2Hi All,
Hoping that someone can point out where I am going wrong.
I'm trying to adapt some code I that I had come across quite some time ago - I can get it working to an extent but not 100%.
I do have a sample sheet but can't for the life of me find where to upload it... So I'll post both code blocks and explain the issue as best as I can...
So this code does work as expected except for the bold line, if the comment is removed it will break on that line.
The next code block is what I would ideally like to work properly the idea:
It loops through column G if the value is null/blank it will just count it.
If there is a value in the cell it will navigate to the website+cell.value and hopefully get 2 values off the page when loaded (resolution date and reason). If I can only get one - I'll live with that.
These 2 values should then be updated in the workbook in the adjacent columns H & I.
as far as I can tell it all works fine until it goes to update the cell value (bold lines) & it throws the error "object variable or with block variable not set" & I'm assuming its going to have the same issue with the lbl id on the commented line as well.
I hope its something small that I've overlooked - been driving me crazy for awhile now
Thanking you all in advance!
Hoping that someone can point out where I am going wrong.
I'm trying to adapt some code I that I had come across quite some time ago - I can get it working to an extent but not 100%.
I do have a sample sheet but can't for the life of me find where to upload it... So I'll post both code blocks and explain the issue as best as I can...
Code:
Public Sub CheckDockets()
'http://www.experts-exchange.com/Software/Office_Productivity/Office_Suites/MS_Office/Excel/Q_26686033.html (I believe this is where the code came from originally, so props!)
Dim objIE As Object
Dim objxmlhttp As Object
Dim strURL
On Error GoTo errhandler
strURL = "http://www.website.com.au/blah.asp?=INC123123123"
Set objIE = CreateObject("InternetExplorer.Application")
objIE.navigate "about:blank"
Set objxmlhttp = CreateObject("Microsoft.xmlhttp")
With objxmlhttp
.Open "GET", strURL, False
objxmlhttp.setRequestHeader "Content-Type", "text/xml"
objxmlhttp.send
If .Status = 200 Then
Debug.Print objxmlhttp.responseText
objIE.document.write objxmlhttp.responseText
[B]'ActiveSheet.Range("H2").value = objIE.document.getElementById("lblLastResolvedDate").value[/B]
ActiveSheet.Range("I2").value = objIE.document.getElementById("txtResolution").value
Else
MsgBox "no reponse from site"
End If
End With
objIE.Quit
Set objIE = Nothing
Exit Sub
errhandler:
MsgBox "Code failed on" & vbNewLine & Err.Description
objIE.Quit
Set objIE = Nothing
End Sub
So this code does work as expected except for the bold line, if the comment is removed it will break on that line.
The next code block is what I would ideally like to work properly the idea:
It loops through column G if the value is null/blank it will just count it.
If there is a value in the cell it will navigate to the website+cell.value and hopefully get 2 values off the page when loaded (resolution date and reason). If I can only get one - I'll live with that.
These 2 values should then be updated in the workbook in the adjacent columns H & I.
Code:
Public Sub CheckDockets()
Dim objIE As Object
Dim objxmlhttp As Object
Dim strURL
Dim r As Range, cell As Range
Dim NoDocketRaised As Integer
Dim totaldockets As Integer
Dim ResolveDate As String
Dim Resolution As String
' On Error GoTo errhandler
totaldockets = WorksheetFunction.CountA(Range("G2", "G" & Range("G2").CurrentRegion.Rows.Count))
NoDocketRaised = 0
Set r = Range("G2", "G" & Range("G2").CurrentRegion.Rows.Count)
For Each cell In r
If IsNull(cell.value) Or cell.value = "" Then
NoDocketRaised = NoDocketRaised + 1
Else
strURL = "http://www.website.com.au/blah.asp?=" & cell.value
Debug.Print strURL
Set objIE = CreateObject("InternetExplorer.Application")
objIE.navigate "about:blank"
Set objxmlhttp = CreateObject("Microsoft.xmlhttp")
With objxmlhttp
.Open "GET", strURL, False
objxmlhttp.setRequestHeader "Content-Type", "text/xml"
objxmlhttp.send
If .Status = 200 Then
Debug.Print objxmlhttp.responseText
objIE.document.write objxmlhttp.responseText
[B] 'ActiveSheet.Range(cell.Offset(0, 1)).Value = objIE.document.getElementById("lblLastResolvedDate").Value
ActiveSheet.Range(cell.Offset(0, 2)).value = objIE.document.getElementById("txtResolution").value[/B]
Else
MsgBox "no reponse from site"
End If
End With
End If
Next
Set objIE = Nothing
Exit Sub
'errhandler:
' MsgBox "Code failed on" & vbNewLine & Err.Description
' objIE.Quit
' Set objIE = Nothing
End Sub
as far as I can tell it all works fine until it goes to update the cell value (bold lines) & it throws the error "object variable or with block variable not set" & I'm assuming its going to have the same issue with the lbl id on the commented line as well.
I hope its something small that I've overlooked - been driving me crazy for awhile now
Thanking you all in advance!