It would appear you have to use different code for the file types?
ChatGPT shows for video files
Code:
Private Sub Form_Load()
Dim filePath As String
Dim htmlPath As String
Dim fileNum As Integer
Dim htmlContent As String
' Path to media file (MP4/MP3)
filePath = "C:\Media\sample.mp4"
' Path to temporary HTML file
htmlPath = Environ("TEMP") & "\playmedia.html"
' HTML content with embedded video tag
htmlContent = "<html><body>" & _
"<video width='600' controls autoplay>" & _
"<source src='file:///" & Replace(filePath, "\", "/") & "' type='video/mp4'>" & _
"Your browser does not support the video tag." & _
"</video></body></html>"
' Write HTML to temp file
fileNum = FreeFile
Open htmlPath For Output As #fileNum
Print #fileNum, htmlContent
Close #fileNum
' Load HTML file into WebBrowser
Me.WebBrowser0.Navigate htmlPath
End Sub
and comments For audio files, just use <audio> instead of <video>.
To show files
Code:
Private Sub Form_Load()
Dim filePath As String
' Set path to the file you want to show
filePath = "C:\Users\YourName\Documents\sample.pdf" ' Can also be .html, .jpg, .txt, etc.
' Check if file exists
If Dir(filePath) <> "" Then
Me.WebBrowser0.Navigate filePath
Else
MsgBox "File not found: " & filePath, vbExclamation
End If
End Sub
In both it appears you need to use the .Navigate method.