I am getting an error saying
"Runtime error 70: Permission Denied"
Below is code in which I am getting this error.
Sub reconwebscrap() ' ' reconwebscrap Macro ' ' Keyboard Shortcut: Ctrl+Shift+R
Dim requestsearchrange As Range
Dim cell1 As Range
Dim cell2 As Range
Dim entire As Range
Dim IE As Object
Dim revocdate As String
Dim i As Integer
Dim tags As Object
Dim tagx As Object
Dim tags2 As Object
Dim tagsx As Object
Application.DisplayStatusBar = True
i = 0
With ActiveWorkbook.Sheets(2)
Set requestsearchrange = .Range(.Range("B2"), .Range("B2").End(xlDown))
End With
ActiveWorkbook.Worksheets.Add
With ActiveWorkbook.Sheets(3)
Set entire = .Range(.Range("A1"), .Range("A65536").End(xlUp))
End With
the_start:
Set IE = New InternetExplorerMedium
'Set IE = CreateObject("InternetExplorer.Application")
'-----------------------------------------------------------------------------------------------------------------
'These attributes decide the position of internet explorer window.
'-----------------------------------------------------------------------------------------------------------------
IE.Top = 0
IE.Left = 0
IE.Width = 800
IE.Height = 600
'-----------------------------------------------------------------------------------------------------------------
'Disable the viewing of Internet Explorer window.
'-----------------------------------------------------------------------------------------------------------------
IE.Visible = True
'-----------------------------------------------------------------------------------------------------------------
'Navigate to the website.
'-----------------------------------------------------------------------------------------------------------------
IE.Navigate ("https://ibid.abc.com/RMT/MyDashboard")
'-----------------------------------------------------------------------------------------------------------------
'Let the website load completely.
'Error handling in case the website is not available.
'-----------------------------------------------------------------------------------------------------------------
Do Until Not IE.Busy
DoEvents
Application.StatusBar = " Running"
Loop
'Do
'DoEvents
'If Err.Number <> 0 Then
'IE.Quit
'Set IE = Nothing
'GoTo the_start:
'End If
'Loop Until IE.readystate = 4
MsgBox "webpage has loaded"
revocdate = InputBox("enter the last revocation date")
Set tags = IE.document.getElementsByTagName("img")
'Set tags2 = IE.document.getElementById("dashboardSelect")
For Each cell1 In requestsearchrange
IE.document.getElementById("dashboardSelect").Value = "recipientSid"
IE.document.getElementById("quickSearchCriteriaVar").Value = cell1.Value
For Each tagx In tags
If tagx.alt = "Search Request" Then
tagx.Click
End If
Next tagx
Do Until Not IE.Busy
DoEvents
Loop
i = i + 1
Application.StatusBar = i & " Running"
Next cell1
Application.StatusBar = ""
End Sub
I am getting this error in
For Each tagx In tags
If tagx.alt = "Search Request" Then
tagx.Click
End If
Next tagx
In this code I am trying to enter a number in the search box and then click on the button. Then wait for it to load and then enter the next number. But it is doing it for only first cell in excel sheet. After that I am getting this error.
I think the probably reason is the following:
At some point of your code you obtain the collection containing all elements with img
tag name.
Later on the code goes into a loop. In every iteration of this loop one of this tag is clicked:
tagx.Click
I suppose this fires some JS script and some changes are made in the HTML structure. This causes the collection obtained before is not longer usable and it should be obtained from scratch.
So if you move this part of code:
Set tags = IE.document.getElementsByTagName("img")
into this loop, it should work.
Here is your code with this modification:
Sub reconwebscrap() ' ' reconwebscrap Macro ' ' Keyboard Shortcut: Ctrl+Shift+R
Dim requestsearchrange As Range
Dim cell1 As Range
Dim cell2 As Range
Dim entire As Range
Dim IE As Object
Dim revocdate As String
Dim i As Integer
Dim tags As Object
Dim tagx As Object
Dim tags2 As Object
Dim tagsx As Object
Application.DisplayStatusBar = True
i = 0
With ActiveWorkbook.Sheets(2)
Set requestsearchrange = .Range(.Range("B2"), .Range("B2").End(xlDown))
End With
ActiveWorkbook.Worksheets.Add
With ActiveWorkbook.Sheets(3)
Set entire = .Range(.Range("A1"), .Range("A65536").End(xlUp))
End With
the_start:
Set IE = New InternetExplorerMedium
'Set IE = CreateObject("InternetExplorer.Application")
'-----------------------------------------------------------------------------------------------------------------
'These attributes decide the position of internet explorer window.
'-----------------------------------------------------------------------------------------------------------------
IE.Top = 0
IE.Left = 0
IE.Width = 800
IE.Height = 600
'-----------------------------------------------------------------------------------------------------------------
'Disable the viewing of Internet Explorer window.
'-----------------------------------------------------------------------------------------------------------------
IE.Visible = True
'-----------------------------------------------------------------------------------------------------------------
'Navigate to the website.
'-----------------------------------------------------------------------------------------------------------------
IE.Navigate ("https://ibid.abc.com/RMT/MyDashboard")
'-----------------------------------------------------------------------------------------------------------------
'Let the website load completely.
'Error handling in case the website is not available.
'-----------------------------------------------------------------------------------------------------------------
Do Until Not IE.Busy
DoEvents
Application.StatusBar = " Running"
Loop
'Do
'DoEvents
'If Err.Number <> 0 Then
'IE.Quit
'Set IE = Nothing
'GoTo the_start:
'End If
'Loop Until IE.readystate = 4
MsgBox "webpage has loaded"
revocdate = InputBox("enter the last revocation date")
'Set tags2 = IE.document.getElementById("dashboardSelect")
For Each cell1 In requestsearchrange
IE.document.getElementById("dashboardSelect").Value = "recipientSid"
IE.document.getElementById("quickSearchCriteriaVar").Value = cell1.Value
Set tags = IE.document.getElementsByTagName("img")
For Each tagx In tags
If tagx.alt = "Search Request" Then
tagx.Click
End If
Next tagx
Do Until Not IE.Busy
DoEvents
Loop
i = i + 1
Application.StatusBar = i & " Running"
Next cell1
Application.StatusBar = ""
End Sub
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.