VBA Web Scrapping Compatibility Issue ? Run time Error 5 on one computer but not the anyother

jcrone

New Member
Joined
Mar 15, 2016
Messages
15
I have a Thinkpad and so does two of my other co-workers, the other has an HP and we all have the same version of Microsoft office. This VBA Code works perfectly on all the computers expect one, the HP. I turned the text below red that is coming up and causing an error.


Code:
Private Sub ImportData_Click()Dim HTMLDoc As HTMLDocument
Dim MyBrowser As InternetExplorer
Dim MyHTML_Element As IHTMLElement
Dim MyURL As String


'On Error Resume Next






MyURL = "Mysite" & txtrequest
Set MyBrowser = CreateObject("InternetExplorer.Application")
MyBrowser.Silent = True
MyBrowser.navigate MyURL
MyBrowser.Visible = False
Do
Loop Until MyBrowser.readyState = READYSTATE_COMPLETE
Set HTMLDoc = MyBrowser.Document


If InStr(HTMLDoc.DocumentElement.innerHTML, "username") <> 0 Then
If Sheet7.Range("Q10") <> True Then
Login.Show
End If
HTMLDoc.all.UserName.Value = Sheet7.Range("Q7")
HTMLDoc.all.Password.Value = Sheet7.Range("Q8")
For Each MyHTML_Element In HTMLDoc.getElementsByTagName("button")
If MyHTML_Element.Type = "submit" Then MyHTML_Element.Click: Exit For
Next


Do While MyBrowser.Busy: DoEvents: Loop




Do
Loop Until MyBrowser.readyState = 4
Set HTMLDoc = MyBrowser.Document


If Sheet7.Range("Q9") <> True Then
Sheet7.Range("Q7") = ""
Sheet7.Range("Q8") = ""
Sheet7.Range("Q9") = ""
Sheet7.Range("Q10") = ""
End If


End If


txtrequestinfo.Value = HTMLDoc.DocumentElement.innerText
Dim TempString As String
Dim SourceCode As String
Dim ReqName() As String
Dim AdminName() As String
Dim newstring As String
Dim BreakUp As String
Dim AdminPhone As String
Dim AdminEmail As String




' setting the string of HTML Code
SourceCode = HTMLDoc.DocumentElement.innerHTML
SourceText = HTMLDoc.DocumentElement.innerText


' finding the values in the code
TempString = Mid(SourceCode, InStr(SourceCode, "Ref WO: ") + 17, 40)
[COLOR=#ff0000]txtcrequest.Value = Mid(TempString, 1, InStr(TempString, "") - 1)[/COLOR]


TempString = Mid(SourceText, InStr(SourceText, "Requested By:") + 13, 40)
newstring = Mid(TempString, 1, InStr(TempString, "Date") - 1)
AdminName() = Split(newstring, " ")


TempString = Mid(SourceText, InStr(SourceText, "Phone:") + 6, 40)
[COLOR=#ff0000]newstring = Mid(TempString, 1, InStr(TempString, "Company:") - 1)[/COLOR]
AdminPhone = newstring




TempString = Mid(SourceText, InStr(SourceText, "E-mail:") + 7, 40)
newstring = Mid(TempString, 1, InStr(TempString, Chr(10)) - 1)
AdminEmail = newstring




TempString = Mid(SourceCode, InStr(SourceCode, "pre-wrap;") + 11, 1000)
newstring = Mid(TempString, InStr(TempString, ">") + 1, InStr(TempString, "") - 1)
txtrequestinfo.Value = Mid(newstring, 1, InStr(newstring, "") - 1)
BreakUp = txtrequestinfo.Value
 

Some videos you may like

Excel Facts

When they said...
When they said you are going to "Excel at life", they meant you "will be doing Excel your whole life".

Kyle123

Well-known Member
Joined
Jan 24, 2012
Messages
2,711
Are there any missing references on that computer?
 

jcrone

New Member
Joined
Mar 15, 2016
Messages
15
I did check that first, but I will go back and check again just in case I missed something. I don't think that is it but I will make sure.
 

jcrone

New Member
Joined
Mar 15, 2016
Messages
15
In case anyone else has this issue I have solved it. The issue was the one computer was coping the SourceCode with tags in all caps. So it worked fine on 5 computers and one it did not. the reason was it was coping the source code differently. I have no idea why this would happen, the versions of Microsoft office were the same. It looks like my tags didn't properly show up in the code above either
 

Watch MrExcel Video

Forum statistics

Threads
1,127,552
Messages
5,625,464
Members
416,108
Latest member
Ravenhold

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Top