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.)
4 Answers
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.
1 Comment
You can use this
CreateObject("WScript.Shell").Run Chr(34) & "C:\Program Files\my_html_files\file.html" & Chr(34)
1 Comment
You can use the File System Object like this:
Set FSO=CreateObject("Scripting.FileSystemObject")
Set iFile = FSO.OpenTextFile ("C:\Program Files\my_html_files\file.html")
Data = iFile.ReadAll
MsgBox(Data)
iFile.Close