Results 1 to 11 of 11

Thread: Excel VBA Macro to start a local video in fullscreen mode using a shortcut

  1. #1

    Thread Starter
    New Member
    Join Date
    Oct 2020
    Posts
    5

    Post Excel VBA Macro to start a local video in fullscreen mode using a shortcut

    I am a novice to Excel VBA code but this is what I've learned / done so far. The code below is a module initiated in Excel by a key shortcut. Ctrl Shift T. It runs the video within the worksheet as required, but with a small screen. I'd like to add to the code to launch the video full screen and when finished close the Windows Media Player and return to the same point in the worksheet. I wonder if anyone knows how to do this please?


    Sub Title_Vid1()
    Dim WMP As Object

    Set WMP = CreateObject("new:{6BF52A52-394A-11d3-B153-00C04F79FAA6}")

    WMP.openPlayer "C:\Users\User1\Teenage_Dream.mp4"


    End Sub

  2. #2
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    Re: Excel VBA Macro to start a local video in fullscreen mode using a shortcut

    you can try
    Code:
    WMP.fullscreen = True
    i could not test as i did not have any media files on this computer, fullscreen only works while the player is playing

    i did not find any method to quit the wmp application
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

  3. #3

    Thread Starter
    New Member
    Join Date
    Oct 2020
    Posts
    5

    Re: Excel VBA Macro to start a local video in fullscreen mode using a shortcut

    Thank you Pete for your kind help. I had already tried that and got the following error:

    Method 'fullscreen' of object 'IWMPPlayer4' failed

    Also:
    WMPfullScreen = True

    ie no fullstop, gives the same error. Wonder if you have any further ideas please.

  4. #4
    PowerPoster jdc2000's Avatar
    Join Date
    Oct 2001
    Location
    Idaho Falls, Idaho USA
    Posts
    2,392

    Re: Excel VBA Macro to start a local video in fullscreen mode using a shortcut


  5. #5

    Thread Starter
    New Member
    Join Date
    Oct 2020
    Posts
    5

    Post Re: Excel VBA Macro to start a local video in fullscreen mode using a shortcut

    Quote Originally Posted by jdc2000 View Post
    Thank you so much. Have you got it working?

    Its close now, but have two snags:

    1) On running the Batch .bat file it asks for permission to run in case of viruses everytime
    2) When I run as a Link in Excel, a small WMP window stays on the screen at the end of the video

    Any ideas please?

    Richard

  6. #6
    PowerPoster jdc2000's Avatar
    Join Date
    Oct 2001
    Location
    Idaho Falls, Idaho USA
    Posts
    2,392

    Re: Excel VBA Macro to start a local video in fullscreen mode using a shortcut

    For item 1:
    The setup steps for creating the batch file need Administrator access, however, you should not actually need to run the batch file As Administrator to get it to work. It should not give you the UAC dialog when run as a non-admin user.

    For item 2:
    You may have to close WMP after the video finishes. Possible useful links:

    https://social.technet.microsoft.com...mplayer.exe%22.

    https://docs.microsoft.com/en-us/win...ine-parameters

    https://www.techrepublic.com/forums/...automatically/

  7. #7

    Thread Starter
    New Member
    Join Date
    Oct 2020
    Posts
    5

    Post Re: Excel VBA Macro to start a local video in fullscreen mode using a shortcut

    Thank you.

    I've cracked the permission thing. As for closing WMP in a command prompt using:

    TaskKill.exe /IM WMPlayer.exe

    It kills it as soon as it starts playing the video!!

    A work around I found is to time in seconds the duration of the video, then insert a TIMEOUT command for the same number of seconds!!

    Surely there's a way without having to time each video!?

    Any help please?

  8. #8
    PowerPoster jdc2000's Avatar
    Join Date
    Oct 2001
    Location
    Idaho Falls, Idaho USA
    Posts
    2,392

    Re: Excel VBA Macro to start a local video in fullscreen mode using a shortcut

    The only other way would be if you could somehow determine when the video had stopped playing, then kill WMPlayer.

    https://social.msdn.microsoft.com/Fo...orum=vbgeneral

    https://stackoverflow.com/questions/...layer-finishes

  9. #9
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    Re: Excel VBA Macro to start a local video in fullscreen mode using a shortcut

    there are a heap of WMP events, one of which may fire when the video is finished playing

    Event Description
    AudioLanguageChange Occurs when the current audio language changes.
    Buffering Occurs when the Windows Media Player control begins or ends buffering.
    CdromMediaChange Occurs when a CD or DVD is inserted into or ejected from a CD or DVD drive.
    Click * Occurs when the user clicks a mouse button.
    CurrentItemChange Occurs when Controls.currentItem changes.
    CurrentMediaItemAvailable Occurs when a graphic metadata item in the current media item becomes available.
    CurrentPlaylistChange Occurs when something changes within the current playlist.
    CurrentPlaylistItemAvailable Occurs when the current playlist item becomes available.
    Disconnect Reserved for future use.
    DomainChange Occurs when the DVD domain changes.
    DoubleClick * Occurs when the user double-clicks a mouse button.
    DurationUnitChange Reserved for future use.
    EndOfStream Reserved for future use.
    Error Occurs when the Windows Media Player control has an error condition.
    KeyDown * Occurs when a key is pressed.
    KeyPress * Occurs when a key is pressed and then released.
    KeyUp * Occurs when a key is released.
    MarkerHit Occurs when a marker is reached.
    MediaChange Occurs when a media item changes.
    MediaCollectionAttributeStringAdded Occurs when an attribute value is added to the library.
    MediaCollectionAttributeStringChanged Occurs when an attribute value in the library is changed.
    MediaCollectionAttributeStringRemoved Occurs when an attribute value is removed from the library.
    MediaCollectionChange Occurs when the media collection changes.
    MediaCollectionMediaAdded Occurs when a media item is added to the local library.
    MediaCollectionMediaRemoved Occurs when a media item is removed from the local library.
    MediaError Occurs when the Media object has an error condition.
    ModeChange Occurs when a mode of Windows Media Player is changed.
    MouseDown * Occurs when a mouse button is pressed.
    MouseMove * Occurs when the mouse pointer is moved.
    MouseUp * Occurs when a mouse button is released.
    NewStream Reserved for future use.
    OpenPlaylistSwitch Occurs when a title on a DVD begins playing.
    OpenStateChange Occurs when the Windows Media Player control changes state.
    PlaylistChange Occurs when a playlist changes.
    PlaylistCollectionChange Occurs when something changes in the playlist collection.
    PlaylistCollectionPlaylistAdded Occurs when a playlist is added to the playlist collection.
    PlaylistCollectionPlaylistRemoved Occurs when a playlist is removed from the playlist collection.
    PlaylistCollectionPlaylistSetAsDeleted Reserved for future use.
    PlayStateChange Occurs when the play state of the Windows Media Player control changes.
    PositionChange Occurs when the current position of the media item has been changed.
    ScriptCommand Occurs when a synchronized command or URL is received.
    StatusChange Occurs when the status property changes value.
    StringCollectionChange Occurs when a string collection changes.
    Warning Reserved for future use.
    i would try playstatechange or statuschange first
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

  10. #10

    Thread Starter
    New Member
    Join Date
    Oct 2020
    Posts
    5

    Post Re: Excel VBA Macro to start a local video in fullscreen mode using a shortcut

    Quote Originally Posted by westconn1 View Post
    there are a heap of WMP events, one of which may fire when the video is finished playing

    i would try playstatechange or statuschange first

    Thank you for the comprehensive list. I wonder if you can help me with how they work. Below is my current Command lines (in a batch file). I assume for example
    there needs to be some sort of loop around 'playstatechange = True'?


    start wmplayer "C:\Test01.mp4" /new /fullscreen

    TIMEOUT 17
    TaskKill.exe /IM WMPlayer.exe
    EXIT

  11. #11
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    Re: Excel VBA Macro to start a local video in fullscreen mode using a shortcut

    the events would only work with a wmp object as created in your original code
    Set WMP = CreateObject("new:{6BF52A52-394A-11d3-B153-00C04F79FAA6}")
    it does seem strange, that the wmp object has no quit method
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width