Notice: This website is an unofficial Microsoft Knowledge Base (hereinafter KB) archive and is intended to provide a reliable access to deleted content from Microsoft KB. All KB articles are owned by Microsoft Corporation. Read full disclaimer for more details.

XL2000: How to Use Visual Basic to Play an AVI File


View products that this article applies to.

Summary

This article shows you how to use Visual Basic for Applications to play an Audio Video Interleaved (AVI) file from Microsoft Excel. You can reference an AVI file directly without inserting it as an object.

↑ Back to the top


More information

Microsoft provides programming examples for illustration only, without warranty either expressed or implied, including, but not limited to, the implied warranties of merchantability and/or fitness for a particular purpose. This article assumes that you are familiar with the programming language being demonstrated and the tools used to create and debug procedures. Microsoft support professionals can help explain the functionality of a particular procedure, but they will not modify these examples to provide added functionality or construct procedures to meet your specific needs.
If you have limited programming experience, you may want to contact a Microsoft Certified Partner or Microsoft Advisory Services. For more information, visit these Microsoft Web sites:

Microsoft Certified Partners - https://partner.microsoft.com/global/30000104

Microsoft Advisory Services - http://support.microsoft.com/gp/advisoryservice

For more information about the support options that are available and about how to contact Microsoft, visit the following Microsoft Web site:http://support.microsoft.com/default.aspx?scid=fh;EN-US;CNTACTMS

Sample Visual Basic Procedure

In Microsoft Excel 2000, the following Visual Basic code plays a Microsoft AVI file at a specified location and size on the active window. This example assumes that the Blastoff.avi file is stored in the default folder (C:\Winvideo). This code does not require the full Microsoft Video package in order to function properly.
'API and Constant Declarations.
'The function declarations must each be typed on one line.

Declare Function mciSendString Lib "winmm" Alias "mciSendStringA" (ByVal _
   lpstrCommand 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:\WINVIDEO\BLASTOFF.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
				

↑ Back to the top


References

For more information about the mciSendString function, in the Visual Basic Editor, click Microsoft Visual Basic Help on the Help menu, type Win SDK in the Office Assistant or the Answer Wizard, and then click Search to view the topic.

Also see the Microsoft Video for Windows Development Kit.

↑ Back to the top


Keywords: KB213471, kbprogramming, kbhowto

↑ Back to the top

Article Info
Article ID : 213471
Revision : 8
Created on : 11/23/2006
Published on : 11/23/2006
Exists online : False
Views : 282