Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do open an HTML file with a default application using VBScript?

Tags:

vbscript

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.)

like image 872
lidia Avatar asked Aug 30 '25 18:08

lidia


2 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.

like image 59
Stephen Quan Avatar answered Sep 03 '25 05:09

Stephen Quan


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"
like image 22
Fionnuala Avatar answered Sep 03 '25 05:09

Fionnuala