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