Using VBA to open a new web page

R

robot

Hello,

I use the following code in Word VBA for firing up the default browser and
opening the Google web site:

Dim objshell As Object
Set objshell = CreateObject("Shell.Application")
objshell.Open "http://www.google.com"

However, if the default browser is already running, the above VBA code will
open the Google web page by *replacing* the "last active web page" (i.e. the
web page that I last visited). How should I modify the code so that the
Google web page will open in a new web page instead?

Suggestions are most welcome!
 
H

Helmut Weber

Hi Robot,

maybe:

Sub Test2()
' Dim var
Dim s As String
s = "C:\Program Files\Internet Explorer\iexplore.exe"
s = Chr(34) & s & Chr(34)
s = s & "http://www.google.com"
Shell s
' or
' var = Shell(s)
End Sub

--

Greetings from Bavaria, Germany

Helmut Weber, MVP WordVBA

Vista Small Business, Office XP
 
K

Karl E. Peterson

robot said:
Hi Helmut,

Your code works, thank you so much!

No, don't use that! It's highly fragile, and of course won't be at all to the
user's pleasure if they use Firefox or Opera or something else as the default
browser. Here's the simple way to load a page in whatever browser the user prefers:
http://vb.mvps.org/samples/HyperJmp
 
R

robot

Karl,

Thank you so much for your help. Even though I use the Shell function
without a problem, I can see that your code is more advanced and more
flexible, so I tried it out and find it to work very well . Thanks again.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top