首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >运行时错误70:权限被拒绝

运行时错误70:权限被拒绝
EN

Stack Overflow用户
提问于 2015-08-12 11:52:03
回答 1查看 2.2K关注 0票数 0

我说错了

“运行时错误70:权限被拒绝”

下面是我得到这个错误的代码。

代码语言:javascript
复制
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

我把这个错误记在

代码语言:javascript
复制
For Each tagx In tags
    If tagx.alt = "Search Request" Then
        tagx.Click
    End If
Next tagx

在这段代码中,我试图在搜索框中输入一个数字,然后单击按钮。然后等待它加载,然后输入下一个号码。但它只对excel工作表中的第一个单元格执行此操作。在那之后,我得到了这个错误。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2015-08-12 13:15:38

我认为原因大概有以下几点:

在代码的某个时候,您将获得包含具有img标记名的所有元素的集合。

稍后,代码进入一个循环。在此循环的每一次迭代中,都会单击其中一个标记:

代码语言:javascript
复制
tagx.Click

我认为这会触发一些JS脚本,并对HTML结构进行一些更改。这导致以前获得的集合不再可用,应该从零开始获取。

因此,如果您移动这部分代码:

代码语言:javascript
复制
Set tags = IE.document.getElementsByTagName("img")

在这个循环中,它应该能工作。

下面是进行此修改的代码:

代码语言:javascript
复制
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
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/31964442

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档