VBA Permission Denied Error, Program Works Only Sometimes

Avradice22

New Member
Joined
Jul 26, 2015
Messages
2
Hey Everyone,

Thank you for taking the time to read this, I am currently a novice VBA programmer beginning to learn the basics of visual basics.

I had been trying to design a program to view/download current tax forms for client viewing. The program as designed is supposed to visit a page and loop through hyperlinks on the page until it finds a hyperlink with matching text on to that of my workbook.

The problem is that sometimes it will go to the hyperlink correctly, and sometimes it will not go to the hyperlink even though nothing has changed. Occasionally I will recieve the error "Permission Denied" and even without the error the program sometimes will not go to the hyperlink.

I would appreciate any effort or insight as I am new, I have put the code below with notes:

Sub ExtractionProject()


Dim anchorTag As Object
Dim result As String


Set ie = CreateObject("InternetExplorer.Application")


ie.Visible = True
ie.navigate "http://apps.irs.gov/app/picklist/list/formsPublications.html"

With ie

While ie.readyState <> 4
DoEvents
Wend

'Enters cell B3 text into search bar and clicks the search button
ie.document.getElementById("searchFor").Value = Range("B3")
ie.document.getElementsByName("submitSearch").Item.Click


result = ie.document.body.innerHTML
Set html = CreateObject("htmlfile")
html.body.innerHTML = result


Set irsPage = ie.document.getElementsByTagName("a")


'Find anchor and "Get associated href link" if innertext is the same as cell "B3"
For Each anchorTag In irsPage


If anchorTag.innertext = ActiveSheet.Range("b3").Text Then 'This is where Permission Denied Occasionally Occurs
ie.navigate anchorTag

End if

Next anchorTag

'Will write the code to save and open later

End With

End Sub
 

Excel Facts

How to change case of text in Excel?
Use =UPPER() for upper case, =LOWER() for lower case, and =PROPER() for proper case. PROPER won't capitalize second c in Mccartney

Forum statistics

Threads
1,215,580
Messages
6,125,654
Members
449,245
Latest member
PatrickL

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