-
Run time error when accessing Internet using VBA
Hi,
Please refer to the following code. This code works fine on my office machine, but does not work on my laptop and home machine. All three machines have Excel 2003, SP3, and MS XP.
When I run the code on my laptop, the macro stops at the line : BUSY and the following error message is displayed.
Runtime error -2147023170, Automation error, The remote procedure call failed.
My guess is that the error has something to do with the way I have defined the IE object.
I tried changing the Dim IE As New SHDocVw.InternetExplorer declaration to Dim IE as Object and Dim IE as InternetExplorer, but the error did not go away.
[vba]
Dim IE As New SHDocVw.InternetExplorer '***
Dim URL As String
Dim Ext As String
Dim ocell As Range
Dim file_loc As String
Dim ResultDIV As HTMLDivElement, AllResultsDIV As HTMLDivElement, OneResultDIV As HTMLDivElement
Dim message As String
Dim htmlDoc As MSHTML.HTMLDocument
Dim htmlInput As MSHTML.HTMLInputElement
Dim htmlColl As MSHTML.IHTMLElementCollection
Dim counter As Integer
Dim DLd As Boolean
file_loc = "C:\newfolder\"
Set IE = CreateObject("InternetExplorer.Application")
With IE
.Visible = 1
.Navigate "http://www.fxstreet.com/forum/showthread.php?t=2910"
Do While .Busy: DoEvents: Loop ' runtime error occurs here or on the next line
Do While .readyState <> 4: DoEvents: Loop
...
[/vba]
Thanks,
MG
-
Change your wait event to this, I believe it should work in all common versions:
[VBA]Do Until ie.ReadyState = READYSTATE_COMPLETE: DoEvents: Loop[/VBA]
Cordially,
Aaron
Keep Our Board Clean! - Please Mark your thread "Solved" if you get an acceptable response (under thread tools).
- Enclose your code in VBA tags then it will be formatted as per the VBIDE to improve readability.
-
That code works fine for me.
Aaron
I don't see how using the constant READYSTATE_COMPLETE would change anything, the OP is using 4 which is the value of that constant.
Am I missing something?
-
Sorry should have been more clear. I am suspecting the
".Busy".
Cordially,
Aaron
Keep Our Board Clean! - Please Mark your thread "Solved" if you get an acceptable response (under thread tools).
- Enclose your code in VBA tags then it will be formatted as per the VBIDE to improve readability.
-
Aaron
Like I said the code works fine for me, and the syntax for 'busy' seems to be what is normally used when automating IE.
It's what I use anyway.
I think the error has something to fo with the OPs setup, everything I can find pertaining to remote procedure calls (RPCs) seems to point to that.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules