Help Opening Website using VBA

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I am trying to navigate to a website using VBA. The problem is that I get an
IE message box that pops up before I can actually reach the page. In order
to reach the page, I need to "click OK" or press enter, but I do not know how
to do this using VBA. I have tried the sendkeys method, but I was
unsuccessful. The code accesses a password protected site so I cannot show
it, but it is very basic:

Sub Get_Info
Set IE = CreateObject("InternetExplorer.Application")
IE.Navigate "Website address here"
"Click Ok/Press Enter when message box appears <---- Here is the problem"
... gather information from the website
End Sub

Any help would be greatly appreciated. Thanks.
Dan
 
I need to "click OK" or press enter, but I do not know how
to do this using VBA.

You need something like:

Set oForm = oIE.Document.forms(0)
oForm("OK").Click

....where "OK" is the name of the item to click.
 
I gave it a shot, but I am still having trouble. The message box is actually
being displayed when I click (using VBA) on a radio button on the website.
Once the box is up, I cannot get VBA to move to the next line of code until
the box is dismissed. Is there any way to disable alerts in IE (like
application.displayalerts = false in VBA)?

Dan
 
Dan said:
I gave it a shot, but I am still having trouble. The message box is actually
being displayed when I click (using VBA) on a radio button on the website.
Once the box is up, I cannot get VBA to move to the next line of code until
the box is dismissed. Is there any way to disable alerts in IE (like
application.displayalerts = false in VBA)?

Dan
Have you tried ActiveWorkbook.FollowHyperlink ..... I think useing this
method doesnt invoke the alert to open a webpage ....

Cheers ,
 
Put the following in a standard module:

Private 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

Public Enum eWindowState
wsNormal = 1
wsMin = 2
wsMax = 3
End Enum

Public Function OpenLocation(URL As String, WindowState As
eWindowState) As Long

Dim hwnd As Long
Dim retHwnd As Long

retHwnd = ShellExecute(hwnd, "open", URL, vbNullString,
vbNullString, WindowState)
OpenLocation = retHwnd

End Function


HTH,

Nick Hebb
http://www.breezetree.com
 
Thanks for all of the feedback. Unfortunately I am still stuck. I think the
issue has to do with my inability to trap events in IE while I am running VBA
macros from Excel. As soon as the message box appears from IE, I cannot move
to the next line of VBA code. I have heard that it is possible to create an
instance of IE "With Events" but that it can come with the expense of a lot
of "overhead." Does anyone have any experience with this?

Dan
 
Back
Top