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.
 

Some videos you may like

Excel Facts

Copy formula down without changing references
If you have =SUM(F2:F49) in F50; type Alt+' in F51 to copy =SUM(F2:F49) to F51, leaving the formula in edit mode. Change SUM to COUNT.

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,060
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.
 

Watch MrExcel Video

Forum statistics

Threads
1,118,057
Messages
5,569,954
Members
412,299
Latest member
agentless
Top