I'm trying to write a bit of VBScript to open a browser on a specific webpage. Ultimately this webpage would be unique per script. At the moment I have the following code which works:
Dim objShell
objShell = CreateObject("Shell.Application")
objShell.ShellExecute("C:\Program Files (x86)\Google\Chrome\Application\chrome.exe", "www.google.ie", "", "", 1)
But I would like to get the following working:
Dim iURL As String
Dim objShell
iURL = "www.google.ie"
objShell = CreateObject("Shell.Application")
objShell.ShellExecute("C:\Program Files (x86)\Google\Chrome\Application\chrome.exe", iURL, "", "", 1)
Any ideas what it is I'm doing wrong? Any help would be greatly appreciated.
To insert a VBScript into an HTML page, we use the <script> tag. Inside the <script> tag we use the type attribute to define the scripting language. The document. write command is a standard VBScript command for writing output to a page.
VBScript is supported by Internet Explorer of Microsoft only, while other browsers (Firefox and Chrome) offer JavaScript support. Therefore, JavaScript usually is prefered by developers over VBScript. As Internet Explorer (IE) supports VBScript, this feature may be explicitly enabled or disabled.
VBScript is supported just by Microsoft's Internet Explorer while other browsers (Firefox and Chrome) support just JavaScript. Hence, developers normally prefer JavaScript over VBScript.
No As String
as VBScript is not strongly type, you need a set
when you create an instance of the COM object & no parens around the method call;
Dim iURL
Dim objShell
iURL = "www.google.ie"
set objShell = CreateObject("Shell.Application")
objShell.ShellExecute "chrome.exe", iURL, "", "", 1
Or if chrome is the default
set objShell = CreateObject("WScript.Shell")
objShell.run(iURL)
I found the easiest way is to do this:
set WshShell=WScript.CreateObject("WScript.Shell")
WshShell.run "chrome.exe"
WScript.sleep 400
WshShell.sendkeys "URL HERE"
WshShell.sendkeys "{ENTER}"
also just a fyi you can do this to close chrome:
WshShell.sendkeys "%{F4}"
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