I have an HTML file C:\Program Files\my_html_files\file.html
. How do I open this file using VBScript? (By "open" I mean open it with the default application, as if it was double-clicked in Explorer.)
The following VBScript code does the equivalent of double clicking on the file.html and having the default open command occur for that file:
Dim wshShell
Set wshShell = CreateObject("WScript.Shell")
wshShell.Run """C:\Program Files\my_html_files\file.html"""
If you want to get really tricksy you can omit the variable declaration and write it in one line of code:
CreateObject("WScript.Shell").Run """C:\Program Files\my_html_files\file.html"""
N.B. Strings may require to be enquoted to handle paths containing spaces. This can be done using the Chr(34)
suggestion by @aland or as I've done in my code examples.
Do you mean open the file in Internet Explorer?
Dim objIE
'' Create an IE object
Set objIE = CreateObject("InternetExplorer.Application")
'' Open file
objIE.Navigate "C:\Program Files\my_html_files\file.html"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With