Full purpose: Programatically download an XLS file from the DoD website without having to trust the certificate.
Details: I'm looking to interact with the second tab that's pulled up via my code. Currently the code keeps working with the first tab. In what I found online the last hour, this is usually done by checking the URL of the second page. The problem is that the second page has the same URL as the first. The second comes up because of a certificate issue I'm trying to circumvent. (IT can't fix the cert issue.) I would just like to be able to work with the second tab so if we have to kill the first tab, that would be fine, too. Once my links are all clicked, an IE box comes up asking what I'd like to do with the file, Open, Save, or Save As. Will I be able to control this box, too, to tell it to open (because I'm wasting my time if not)? Here's what I've got...
'http://www.exceltrainingvideos.com/how-to-follow-multiple-hyperlinks-and-extract-webpage-data/
Sub testweb()
mystart:
Set objIE = CreateObject("InternetExplorer.Application")
objIE.Top = 0
objIE.Left = 0
objIE.Width = 1600
objIE.Height = 900
objIE.Visible = True
On Error Resume Next
objIE.Navigate ("https://www.defensetravel.dod.mil/site/pdcFiles.cfm?dir=/Allowances/Per_Diem_Rates/Text_Only/OCONUS-Overseas/ovs19-01.xls")
Application.Wait (Now + TimeValue("0:00:04"))
Do
DoEvents
If Err.Number <> 0 Then
objIE.Quit
Set objIE = Nothing
GoTo mystart:
End If
Loop Until objIE.ReadyState = 4
Set alllinks = objIE.document.getElementsByTagName("A") 'click year
For Each Hyperlink In alllinks
If InStr(Hyperlink.innertext, " 2019") > 0 Then
Hyperlink.Click
Exit For
End If
Next
Application.Wait (Now + TimeValue("0:00:02"))
Set alllinks = objIE.document.getElementsByTagName("A") 'click file name
For Each Hyperlink In alllinks
If InStr(Hyperlink.innertext, " ovs19-01.xls") > 0 Then 'item 45
Hyperlink.Click
Exit For
End If
Next
Stop
Application.Wait (Now + TimeValue("0:00:04"))
Below is where I need my code to start working with the second page**
Set alllinks = objIE.document.getElementsByTagName("A") 'click More Info link
For Each Hyperlink In alllinks
If InStr(Hyperlink.innertext, "More information") > 0 Then
Hyperlink.Click
Exit For
End If
Next
Stop
Application.Wait (Now + TimeValue("0:00:02"))
Set alllinks = objIE.document.getElementsByTagName("A") 'click Go on to the webpage...
For Each Hyperlink In aAlllinks
If InStr(Hyperlink.innertext, "Go on to the webpage (not recommended)") > 0 Then
Hyperlink.Click
Exit For
End If
Next
Stop
objIE.Quit
End Sub
You can use the download url direct and specify an ignore certificate warning flag