Gino_Vernisci
New Member
- Joined
- Jul 13, 2011
- Messages
- 20
Hi all
I wrote some VBA code that navigates to a website, fills in search fields with data from a spreadsheet then takes relevent data from the website search results and places them back in the spreadsheet. The code includes the Internet Explorer "find" tool 'ExecWB 32, 0. Sometimes the code works flawlessly but sometimes I encounter the following error:
runtime error '-2147221248(80040100)'
method 'ExecWB' of object 'Iwebbrowser2' failed
The code stops and Debug flags the ExecWB 32, 0 line. No changes to the code are made, it just stops working.
I'm not so much interested in a fix to the problem as I am an explanation of why its functionality varies.
Thanks Guys
Full code below:
I wrote some VBA code that navigates to a website, fills in search fields with data from a spreadsheet then takes relevent data from the website search results and places them back in the spreadsheet. The code includes the Internet Explorer "find" tool 'ExecWB 32, 0. Sometimes the code works flawlessly but sometimes I encounter the following error:
runtime error '-2147221248(80040100)'
method 'ExecWB' of object 'Iwebbrowser2' failed
The code stops and Debug flags the ExecWB 32, 0 line. No changes to the code are made, it just stops working.
I'm not so much interested in a fix to the problem as I am an explanation of why its functionality varies.
Thanks Guys
Full code below:
Code:
Sub AppActivate_Test()
Dim j As Integer
Dim fname As String
Dim lname As String
Dim i As Integer
i = Range("E2").Value
For j = 1 To i
If j / 25 = Int(j / 25) Then 'Saves every 25 items
ActiveWorkbook.Save
Application.Wait Now + TimeValue("00:00:03")
Else
End If
fname = Cells(j, 1)
lname = Cells(j, 2)
'Search Relationship Dbase
Set IE = CreateObject("InternetExplorer.Application")
Application.Wait Now + TimeValue("00:00:01")
IE.Visible = True
IE.Navigate "dbase URL"
Application.Wait Now + TimeValue("00:00:04")
SendKeys "{TAB}"
Application.Wait Now + TimeValue("00:00:01")
SendKeys "{TAB}"
Application.Wait Now + TimeValue("00:00:01")
SendKeys lname
Application.Wait Now + TimeValue("00:00:01")
SendKeys "{TAB}"
Application.Wait Now + TimeValue("00:00:01")
SendKeys fname
Application.Wait Now + TimeValue("00:00:01")
SendKeys "~"
Application.Wait Now + TimeValue("00:00:02")
[COLOR=red]IE.ExecWB 32, 0 'Find[/COLOR]
Application.Wait Now + TimeValue("00:00:01")
SendKeys lname + ", " + fname
Application.Wait Now + TimeValue("00:00:01")
SendKeys "~"
Application.Wait Now + TimeValue("00:00:01")
IE.ExecWB 12, 2 'Copy Selection
IE.Quit
'Paste Findings
On Error Resume Next 'Ignores "failed find" in IE
AppActivate "AllClientsProspects(1)"
Cells(j, 3).PasteSpecial
Next
End Sub