Pankil

New Member
Joined
Aug 1, 2019
Messages
16
Hello Guys,

i have below code that copy table on current webpage but when i change that page it not getting new table. note both the tables have same format, with little change in content,

Dim i As SHDocVw.InternetExplorer
Set i = New InternetExplorer
Dim clipboard As MSForms.DataObject
i.Visible = True
Dim HTMLdoc As New HTMLDocument
Dim tables As MSHTML.IHTMLElementCollection
Dim table As MSHTML.HTMLTable
Dim objTable As Object
Dim lRow As Long
Dim lngTable As Long
Dim lngRow As Long
Dim lngCol As Long
Dim ActRw As Long

i.navigate ("URL")

Do While i.readyState <> READYSTATE_COMPLETE
Loop

Application.Run "module1.DeleteSheets"

Dim idoc As MSHTML.HTMLDocument
Set idoc = i.document

idoc.getElementById("Usr").Value = "ID1"
idoc.getElementById("cpny").Value = "ID2"
idoc.getElementById("pwd").Value = "PW"
idoc.getElementsByClassName("btn_primary buttonclass")(0).Click

Do While i.readyState < 4: DoEvents: Loop
Do Until i.readyState = 4: DoEvents: Loop
While i.Busy
DoEvents
Wend
'------------------------------------------------------------------------------
i.navigate ("URL2")

Do While i.readyState < 4: DoEvents: Loop
Do Until i.readyState = 4: DoEvents: Loop
While i.Busy
DoEvents
Wend

newHour = Hour(Now())
newMinute = Minute(Now())
newSecond = Second(Now()) + 3
waitTime = TimeSerial(newHour, newMinute, newSecond)
Application.Wait waitTime

idoc.getElementById("calendarData").selectedIndex = 4
idoc.getElementById("calendarData").FireEvent ("onchange")

idoc.getElementById("locationData").selectedIndex = 1
idoc.getElementById("locationData").FireEvent ("onchange")

idoc.getElementsByClassName("btn_primary buttonclass")(0).Click

While i.Busy
DoEvents
Wend

ActiveWorkbook.Sheets.Add

i.navigate ("URL 3")

newHour = Hour(Now())
newMinute = Minute(Now())
newSecond = Second(Now()) + 3
waitTime = TimeSerial(newHour, newMinute, newSecond)
Application.Wait waitTime

HTMLdoc.body.innerHTML = idoc.body.innerHTML
With HTMLdoc.body
Set objTable = .getElementsByTagName("Table")
For lngTable = 0 To objTable.Length - 1
For lngRow = 0 To objTable(lngTable).Rows.Length - 1
For lngCol = 0 To objTable(lngTable).Rows(lngRow).Cells.Length - 1
ActiveSheet.Cells(ActRw + lngRow + 1, lngCol + 1) = objTable(lngTable).Rows(lngRow).Cells(lngCol).innerText
Next lngCol
Next lngRow
ActRw = ActRw + objTable(lngTable).Rows.Length + 1
Next lngTable
End With

newHour = Hour(Now())
newMinute = Minute(Now())
newSecond = Second(Now()) + 5
waitTime = TimeSerial(newHour, newMinute, newSecond)
Application.Wait waitTime
Range("a1").Select
ActiveCell.PasteSpecial
ActiveSheet.Name = Range("b2").Value
ActiveWorkbook.Sheets.Add

'---------------------------------------------

Set objTable = Nothing

i.navigate ("URL 4")
While i.Busy
DoEvents
Wend

newHour = Hour(Now())
newMinute = Minute(Now())
newSecond = Second(Now()) + 2
waitTime = TimeSerial(newHour, newMinute, newSecond)
Application.Wait waitTime

idoc.getElementById("calendarData").selectedIndex = 4
idoc.getElementById("calendarData").FireEvent ("onchange")

idoc.getElementById("locationData").selectedIndex = 2
idoc.getElementById("locationData").FireEvent ("onchange")

idoc.getElementsByClassName("btn_primary buttonclass")(0).Click

While i.Busy
DoEvents
Wend


i.navigate ("URL 5")
newHour = Hour(Now())
newMinute = Minute(Now())
newSecond = Second(Now()) + 3
waitTime = TimeSerial(newHour, newMinute, newSecond)
Application.Wait waitTime

HTMLdoc.body.innerHTML = idoc.body.innerHTML
With HTMLdoc.body
Set objTable = .getElementsByTagName("Table")
For lngTable = 0 To objTable.Length - 1
For lngRow = 0 To objTable(lngTable).Rows.Length - 1
For lngCol = 0 To objTable(lngTable).Rows(lngRow).Cells.Length - 1
ActiveSheet.Cells(ActRw + lngRow + 1, lngCol + 1) = objTable(lngTable).Rows(lngRow).Cells(lngCol).innerText
Next lngCol
Next lngRow
ActRw = ActRw + objTable(lngTable).Rows.Length + 1
Next lngTable
End With
 

Excel Facts

How to show all formulas in Excel?
Press Ctrl+` to show all formulas. Press it again to toggle back to numbers. The grave accent is often under the tilde on US keyboards.

Forum statistics

Threads
1,214,798
Messages
6,121,635
Members
449,043
Latest member
farhansadik

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
Back
Top