Tegenfeldt
New Member
- Joined
- Aug 6, 2013
- Messages
- 13
I have an Excel VBA that opens a webpage and clicks a link. The link runs a JavaScript that generates a PDF page in a new IE window. So far all is fine, but I have not found out how to save (download) the PDF. Below is my VBA, test it and you can see what I mean:
Rich (BB code):
Sub GeneratedPDF() Dim IExplorer As InternetExplorer
Dim TheURL As String
Dim HTMLdoc As HTMLDocument
Dim TheLink As HTMLLinkElement
TheURL = "core.purus.se/PurusWeb/Navigate/Document.aspx?DBDocId=13284"
Set IExplorer = New InternetExplorer
With IExplorer
.navigate TheURL
.Visible = True
While .Busy Or .readyState <> READYSTATE_COMPLETE: DoEvents: Wend
Set HTMLdoc = .Document
Set links = HTMLdoc.getElementsByTagName("a")
i = 0
Set TheLink = Nothing
'And HTMLdoc.links(i).className = "ddmenu"
Do While i < HTMLdoc.links.Length
If HTMLdoc.links(i).className = "PDFLink" Then
Set TheLink = HTMLdoc.links(i)
Debug.Print TheLink
Exit Do
End If
i = i + 1
Loop
End With
TheLink.Focus
TheLink.Click
IExplorer.Quit
End Sub