PDA

View Full Version : Automation error



clif
02-14-2017, 09:29 PM
I run successfully in my computer

IE: ver11
EXCEL: 2010
Microsoft Office 14.0 Object Library

But cannot run in other computer
IE: ver11
EXCEL: 2013
Microsoft Office 15.0 Object Library





Sub abc()

Application.ScreenUpdating = False

Dim objIe As Object, xobj As HTMLDivElement
Set objIe = CreateObject("InternetExplorer.Application")
objIe.Visible = True

Dim id As Long
Dim Lastrow2 As Long

Sheets("main").Select
With ActiveSheet
Lastrow2 = .Cells(.Rows.Count, "A").End(xlUp).Row

For custid = 2 To Lastrow2

objIe.navigate "http://www.abc.com/?=" & Sheets("main").Cells(id, 10).Value


While (objIe.Busy Or objIe.readyState <> 4): DoEvents: Wend

Sheets("1").Select
Cells.Select
Selection.Delete Shift:=xlUp

Dim a As Long

For a = 1 To 8

Set xobj = objIe.Document.getElementById("viewInfo_myApprDataGrid")
Set xobj = xobj.getElementsByClassName("lfHead").Item(0)
Set xobj = xobj.getElementsByTagName("td")(a)

Sheets("1").Cells(1, a) = xobj.innerText

Next a

mancubus
02-15-2017, 02:00 AM
try changing custid to id in the outer loop or id to custid in the cell reference.

since id is declared as long and not assigned a value its value is 0. Cells(0, 10) throws error.