Reputation: 850
I Can able to access the website and click on Download button, once I clicked it download dialog box opens at the bottom with buttons Open,Save,Cancel. I would like to click on Open button and print the opened file in Cute pdf format.
How do i click the Open button Please help me out.
Code used to click download button
ie2.Document.forms("ViewReferral").getElementsByClassName("notsuccess")(0).getElementsByTagName("tr").Item(1).getElementsByTagName("td").Item(3).getElementsByTagName("A").Item(0).Click
Once I clicked it above mentioned Dialog box opens.
Thank You.
Upvotes: 1
Views: 307
Reputation: 21619
Instead of trying to click the button on the browsers' "Open/Save/Cancel" bar, you can download the file directly as long as you're able to retrieve the complete URL (ie., http://......attached_doc135155.pdf
) through whatever method of scraping.
Option Explicit
Sub downloadFile(url As String, filePath As String)
Dim WinHttpReq As Object, attempts As Integer, oStream
attempts = 3
On Error GoTo TryAgain
TryAgain:
attempts = attempts - 1
Err.Clear
If attempts > 0 Then
Set WinHttpReq = CreateObject("Microsoft.XMLHTTP")
WinHttpReq.Open "GET", url, False
WinHttpReq.send
If WinHttpReq.Status = 200 Then
Set oStream = CreateObject("ADODB.Stream")
oStream.Open
oStream.Type = 1
oStream.Write WinHttpReq.responseBody
oStream.SaveToFile filePath, 2 ' 1 = no overwrite, 2 = overwrite
oStream.Close
MsgBox "File downloaded to:" & vbLf & filePath
End If
Else
MsgBox "Failed."
End If
End Sub
Sub testDownload()
Const testFileURL = "http://ipv4.download.thinkbroadband.com/5MB.zip"
Const localSavePathFile = "c:\5MB_testfile.zip"
downloadFile testFileURL, localSavePathFile
End Sub
(Source)
Upvotes: 1