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