Running a videostream

iggydarsa

Well-known Member
Joined
Jun 28, 2005
Messages
1,780
Office Version
  1. 2019
Platform
  1. Windows
Hi everyone,

I have an excel file in a folder, also in the same folder I have a video file (lets say it is called myVideo.avi).

I want to create a macro so that when i call it the video will run.

does anyone know how to execute a video file through a macro in excel?

thank you.
 

Excel Facts

Square and cube roots
The =SQRT(25) is a square root. For a cube root, use =125^(1/3). For a fourth root, use =625^(1/4).
How did you get the file into Excel in the first place and how do you run it without any macro?

RAM
 
Upvote 0
It is not into Excel, the video file is in the same folder as my excel file.

Basically, I want to know how to open another file by using a macro.

Thank you
 
Upvote 0
Hi,

How about using the ShellExecute API function ?

This should start the default Media player program that Windows associates with the AVI file . You can also control the size of the Media Player window via the nShowCmd parameter.


Paste this code in a Standard Module and run the Test Sub :

Code:
Option Explicit

Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" _
(ByVal hwnd As Long, ByVal lpOperation As String, ByVal lpFile As String, _
ByVal lpParameters As String, _
ByVal lpDirectory As String, ByVal nShowCmd As Long) As Long

Const SW_SHOWNORMAL = 1


Function PlayVideo(ByVal strVideoFilePath As String) As Boolean

    Dim lngRetval As Long
    
    lngRetval = ShellExecute _
    (0, "open", strVideoFilePath, vbNullString, vbNullString, SW_SHOWNORMAL)
    
    If lngRetval > 32 Then PlayVideo = True

End Function


Sub Test()

    Dim strFile As String
    
    strFile = ThisWorkbook.Path & "\myVideo.avi" '\\Change this as required
    
    If Not PlayVideo(strFile) Then
        MsgBox "Sorry an error has occurred !" & vbCrLf & _
        "Can't play   " & strFile, vbCritical
    End If

End Sub

Regards.
 
Upvote 0

Forum statistics

Threads
1,214,938
Messages
6,122,346
Members
449,080
Latest member
Armadillos

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top