Logo 
Search:

MS Office Forum

Ask Question   UnAnswered
Home » Forum » MS Office       RSS Feeds

playing avi file in excel using macro

  Asked By: Tracey    Date: Feb 08    Category: MS Office    Views: 3231
  

I want to play an AVI file I created possibly by simply pressing a
command button in Excel. I have an example code I found online, but
was not able to get it to work. Here it is:

Declare Function mciSendString Lib "winmm" Alias "mciSendStringA"
(ByVallpstrCommand As String, ByVal lpstrReturnStr As Any, ByVal
wReturnLen As Long, ByVal hCallBack As Long) As Long

Declare Function GetActiveWindow Lib "USER32" () As Integer
Const WS_CHILD = &H40000000

Sub PlayAVIFile()

'Dimension variables.
Dim CmdStr As String, FileSpec As String
Dim Ret As Integer, XLSHwnd As Integer

'The name and location of the AVI file to play.
FileSpec = "C:\Documents and Settings\Administrator\My
Documents\My Recordings\excel video 2.avi"

'Get the active sheet's window handle.
XLSHwnd = GetActiveWindow()

'Opens the AVIVideo and creates a child window on the sheet
'where the video will display. "Animation" is the device_id.
CmdStr = ("open " & FileSpec & _
" type AVIVideo alias animation parent " & _
LTrim$(Str$(XLSHwnd)) & " style " & LTrim$(Str$(WS_CHILD)))

Ret = mciSendString(CmdStr, 0&, 0, 0)

'Put the AVI window at location 25, 120 relative to the
'parent window (Microsoft Excel) with a size of 160 x 160.
Ret = mciSendString("put animation window at 25 120 160 160", _
0&, 0, 0)

'The wait tells the MCI command to complete before returning
'control to the application.
Ret = mciSendString("play animation wait", 0&, 0, 0)

'Close windows so they don't crash when you quit the application.
Ret = mciSendString("close animation", 0&, 0, 0)

End Sub

This function currently does not work. When I pasted into VBA it
automatically splits the code with a line after the function
declarations. Any suggestions/help would be greatly appreciated.

Share: 

 

3 Answers Found

 
Answer #1    Answered By: Este Ferrrari     Answered On: Feb 08

It is much easier to click the cell where you want it to be, then
Insert/Object/Create from file  then browse for the AVI file and click
insert. When the file is double clicked it will open  in the appropriate
player.

 
Answer #2    Answered By: Channarong Boonliang     Answered On: Feb 08

If I have the object in a cell, is there a macro  that will allow me
to play  it, then automatically close it and bring the user back to
the current excel  spreadsheet? The purpose of this avi  file is to
act as a help reference that the user would click a button  to view
the AVI file  then when the file has run its course, bring the user
right back to the excel sheet so they can continue working on it. I
don't want the user to have to go through having to close the AVI
file and get back to excel themselves. Any suggestions anyone?

 
Answer #3    Answered By: Abagail Cohen     Answered On: Feb 08

You would need to know how to control the player application (which might be
different on different computers). This is difficult. It might be possible
to have something in the Avi file  which closed the application (I don't know
anything about AVI players) or a switch in the caller to do so.

An alternative would be to have a timer set up which would initiate a sendkeys
sequence to close the player after a certain time had elapsed. I think this
method would be incredibly unreliable.

You need to find a forum for the player if you know which one is likely to be
used and find out how to control it.

 
Didn't find what you were looking for? Find more on playing avi file in excel using macro Or get search suggestion and latest updates.




Tagged: