Error '70': Permission Denied

Asked

Viewed 635 times

1

When I run the code below, the title error appears in the 'For Each' line. This is a block of the site itself or there is some error in the code?

Declara função Sleep
If VBA7 Then
    Public Declare PtrSafe Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As LongPtr) 'For 64 Bit Systems
Else
    Public Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long) 'For 32 Bit Systems
End If

Sub IPMO_semanal()

    Dim IE As Object
    Dim doc As MSHTML.HTMLDocument


    Set IE = CreateObject("InternetExplorer.Application")

    IE.navigate "http://ons.org.br/pt/paginas/conhecimento/acervo-digital/documentos-e-publicacoes?categoria=Relat%C3%B3rio+PMO"
    IE.Visible = True

Set el = IE.document.getElementsByTagName("table")

    Sleep 2000

    i = 1
    For Each link In el.getElementsByTagName("a")

    '      If EXTRAIRELEMENTO(link.href, 9, "/") = "InformePMO_MAR2018_RV4.pdf" Then
    '      If Mid(link.href, 105, 8) = "InformePMO" Then

           If link.href = "http://ons.org.br/_layouts/download.aspx?SourceUrl=http://ons.org.br/AcervoDigitalDocumentosEPublicacoes/InformePMO_MAR2018_RV4.pdf" Then
            i = i + 1

            link.Click
             Sleep 2000
            If i = 2 Then Exit For
        End If

    Next link


End Sub
  • 1

    The same mistake didn’t appear to me with this code.

1 answer

1

It rolled here, with a small detail:

The variable el is a collection of tables (even if it contains a single table), so it was necessary to change the For to reference the first element of el (that is to say, el(0)):

For Each link In el(0).getElementsByTagName("a")

Anyway, did not identify any occurrence of the link you specified.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.