Running a videostream

iggydarsa

Well-known Member
Joined
Jun 28, 2005
Messages
1,647
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

Best way to learn Power Query?
Read M is for (Data) Monkey book by Ken Puls and Miguel Escobar. It is the complete guide to Power Query.

RAM

Well-known Member
Joined
Oct 4, 2004
Messages
1,862
How did you get the file into Excel in the first place and how do you run it without any macro?

RAM
 

iggydarsa

Well-known Member
Joined
Jun 28, 2005
Messages
1,647
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
 

Jaafar Tribak

Well-known Member
Joined
Dec 5, 2002
Messages
8,611
Office Version
  1. 2016
Platform
  1. Windows
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.
 
Master Excel Bundle

Excel contains over 450 functions, with more added every year. That’s a huge number, so where should you start? Right here with this bundle.

Forum statistics

Threads
1,163,995
Messages
5,834,779
Members
430,321
Latest member
yemisimi11

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
Top