Please Help - Trying to Launch IE from Excel

  • Thread starter Thread starter eBob.com
  • Start date Start date
E

eBob.com

I am trying to launch IE from a VBA macro in Excel. After a great deal of
web searching I came up with the following ...

Public Declare Function ShellExecute Lib "shell32.dll" _
Alias "ShellExecuteA" (ByVal hwnd As Long, ByVal lpOperation As String,
_
ByVal lpFile As String, ByVal lpParameters As String, _
ByVal lpDirectory As String, ByVal nShowCmd As Long) As Long

<some other stuff>

Sub test23()
Dim WEB_SITE_URL As String
WEB_WITE_URL = "http://www.mysite.com"
Dim SW_SHOWNORMAL As Integer
SW_SHOWNORMAL = 1

'Launch Web Site
ShellExecute 0, vbNullString, WEB_SITE_URL, vbNullString, _
vbNullString, SW_SHOWNORMAL
End Sub

When I execute test23 I get a windows explorer window opening up to the My
Documents directory. No error messages.

I think that I am close. Could someone please help me get this to launch IE.

Thanks, Bob
 
Hi "Bob",

in the word groups I answered that question, like that:

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

Yet Karl E. Peterson, who is quite an authority, told me:

"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"

Make the best of all of it.
 
Hi eBob,

Heres some pretty simple code l have been using for along time, and
gives you control over the size of the IE window etc.(they are of
course optional)

Hope it helps

Sub MyIE()

Set IE = CreateObject("InternetExplorer.Application")
IE.AddressBar = False
IE.MenuBar = False
IE.Toolbar = False
IE.Width = 600
IE.Height = 750
IE.Left = 0
IE.Top = 0
IE.navigate "www.yahoo.com"
IE.resizable = True
IE.Visible = True

End Sub

Regards

Michael
 
Yes, and that has an advantage if I ever want to export the spreadsheet to
an html file. But it also makes the spreadsheet unnecessarily large. So I
prefer the macro solution.

Bob
 
How about this?

Option Explicit
Sub GoToWebSite()

Dim appIE As InternetExplorer
Dim sURL As String
Application.ScreenUpdating = False

Set appIE = New InternetExplorer

sURL = "http://www.mywebsite.com"

With appIE
.Navigate sURL
.Visible = True
End With

Application.ScreenUpdating = True

Set appIE = Nothing
End Sub


Of course you would need to set a reference to Microsoft Internet
Controls (shdocvw.dll). For more samples check out
http://www.codeforexcelandoutlook.com/automateinetexplorer.html

HTH,
JP
 
Thanks for the many responses. They were all helpful. This response from
Tim seems like the perfect solution to my problem.

Thanks again to Tim and everyone else who responded.

Bob
 
Back
Top