ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Help Opening Website using VBA (https://www.excelbanter.com/excel-programming/371835-help-opening-website-using-vba.html)

Dan Hatola

Help Opening Website using VBA
 
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

Randy Harmelink

Help Opening Website using VBA
 
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.


Dan Hatola

Help Opening Website using VBA
 
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

"Randy Harmelink" wrote:

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.



tausif

Help Opening Website using VBA
 

Dan Hatola wrote:
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

"Randy Harmelink" wrote:

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.

Hi ....

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

Cheers ,


Nick Hebb

Help Opening Website using VBA
 
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


Dan Hatola

Help Opening Website using VBA
 
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

"Nick Hebb" wrote:

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




All times are GMT +1. The time now is 07:10 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com