Excel VBA - Mastering the Display Size of WindowsMediaPlayer in UserForms
TonyLucky
-
TonyLucky -
TonyLucky -
Hello everyone,
I am on Windows 10 and I want to embed a video in a UserForm in Excel. I have loaded a Windows Media Player control. It works well. My problem is that the video window automatically resizes and takes up too much space in my UserForm. I have removed the WMP command part, but this space gain is not enough.
I have searched for various solutions on the web, without success. I tried autosize = false, but this property does not apply to this control.
Is there a way to control the display size?
Here is my code:
Private Sub A_Play_Click()
Photo_Name = "Casting Léon"
Photo_Path = ActiveWorkbook.Path & "\Common Tools\Videos\" & Photo_Name & ".mp4"
Me.WindowsMediaPlayer1.stretchToFit = False
'VBA help text: This property applies to the Windows Media Player control only when embedded in a webpage. (apparently, this function only works on a webpage)
Me.WindowsMediaPlayer1.Width = 200: Me.WindowsMediaPlayer1.Height = 125
'VBA properly sizes the window to this dimension, then goes into autosize, so to speak.
WindowsMediaPlayer1.Url = Photo_Path
End Sub
Thank you in advance for your suggestions or ideas,
Tony
Configuration: Windows / Firefox 52.0
I am on Windows 10 and I want to embed a video in a UserForm in Excel. I have loaded a Windows Media Player control. It works well. My problem is that the video window automatically resizes and takes up too much space in my UserForm. I have removed the WMP command part, but this space gain is not enough.
I have searched for various solutions on the web, without success. I tried autosize = false, but this property does not apply to this control.
Is there a way to control the display size?
Here is my code:
Private Sub A_Play_Click()
Photo_Name = "Casting Léon"
Photo_Path = ActiveWorkbook.Path & "\Common Tools\Videos\" & Photo_Name & ".mp4"
Me.WindowsMediaPlayer1.stretchToFit = False
'VBA help text: This property applies to the Windows Media Player control only when embedded in a webpage. (apparently, this function only works on a webpage)
Me.WindowsMediaPlayer1.Width = 200: Me.WindowsMediaPlayer1.Height = 125
'VBA properly sizes the window to this dimension, then goes into autosize, so to speak.
WindowsMediaPlayer1.Url = Photo_Path
End Sub
Thank you in advance for your suggestions or ideas,
Tony
Configuration: Windows / Firefox 52.0
3 answers
-
Finally, I found it by testing the commands related to WMP.
Just add the macro:
Private Sub WindowsMediaPlayer1_StatusChange()
Me.WindowsMediaPlayer1.Width = 200: Me.WindowsMediaPlayer1.Height = 175
End Sub
And there, it perfectly sizes my video.
For your information, to hide the WMP controls:
Me.WindowsMediaPlayer1.uiMode = "none"
If this can interest someone, great! -
Hello,
I think it's your UserForm that needs to be resized like this:WindowsMediaPlayer1.URL = Photo_Path UserForm1.Width = WindowsMediaPlayer1.Width + 100 ' to adjust UserForm1.Height = WindowsMediaPlayer1.Height + 100 ' to adjust
for more info see this:
https://silkyroad.developpez.com/VBA/WindowsMediaPlayer/
@+ The Woodpecker -
Hello,
Thank you for your response, but your solution does not fit my case because in my UF, WMP does not take up all the space. There is other information.
However, if my solution works, it is not fully satisfactory because at the beginning and at the end of the video, the image flickers two or three times.
I will keep looking...