Ok I really could do with a hand on this one!
I am trying to download PDF invoices. The problem I have is I cant see the url where the files are kept and I want to use the UrlDownloadToFile. The site is locked for editing but looks like this
[ATTACH=CONFIG]69644[/ATTACH]
The code behind it looks like this (iveobsecured account details for obvious reasons)
[ATTACH=CONFIG]69645[/ATTACH]
Therefore what I am trying to do is download all the PDFs that come up providing the document name hasn't been previously downloaded. So I currently have two problems -
1. The PDF filename only seems to come up when I click the document
2. I can see a direct weblink from the code which means URLDownloadToFile wont work
This is what I played around with so far
Dim strURL As String, strPath As String, Mo As String, LMo As String
Public ImpFXLstCl As Long, ImpFXCountry As Long, ImpFXCurrency As Long, ImpFXCurrencycode As Long, ImpFXCurrencyunitsper1 As Long, ImpFXStartDate As Long, ImpFXEndDate As Long
Dim Fnd As String
Dim Dte As Date
Dim dte2 As Long
Dim Nwb As String
Sub FindInvoice()
'find the HMRC web link. Note this can change format so this code may need updating!
Set ie = CreateObject("InternetExplorer.Application")
'Wait until IE is done loading page
On Error Resume Next
With ie
.Visible = True
.navigate "[URL]https://mybill.virginmediabusiness.co.uk/group/analysis/downloads[/URL]"
Do While ie.Busy Or ie.readyState <> 4
DoEvents
Loop
End With
For Each element In ie.Document.all
If element.ID = "p_MyView_WAR_PantherUser" Then
Fnd = "Yes"
Exit For
End If
Next element
If Fnd <> "Yes" Then
SwitchOn
MsgBox ("You do not appear to be logged in to Virgin Media. Please sign in before running")
ie.Visible = True
End
End If
rw = 1
With ie.Document
'#_DownloadAnalysis_WAR_PantherAnalysis_invoice_
'For Each element In ie.Document.all
For Each element In ie.Document.getElementsByTagName("a")
If element.getattribute("href") = "#_DownloadAnalysis_WAR_PantherAnalysis_invoice_" Then
element.Click
Do While ie.Busy Or ie.readyState <> 4
DoEvents
Loop
End If
rw = rw + 1
Next element
rw = 1
With ie.Document
'#_DownloadAnalysis_WAR_PantherAnalysis_invoice_
'For Each element In ie.Document.all
For Each element In ie.Document.getElementsByTagName("a")
ThisWorkbook.Sheets("Workbench").Cells(rw, 1) = element.ID
ThisWorkbook.Sheets("Workbench").Cells(rw, 2) = element.Value
ThisWorkbook.Sheets("Workbench").Cells(rw, 3) = element.Text
ThisWorkbook.Sheets("Workbench").Cells(rw, 4) = element.innertext
ThisWorkbook.Sheets("Workbench").Cells(rw, 5) = element.getattribute("href")
If element.innertext = "Download PDF" Then
element.Click
WebAddress = "[URL]https://mybill.virginmediabusiness.co.uk/group/analysis/downloads?p_p_id=DownloadAnalysis_WAR_PantherAnalysis&p_p_lifecycle=1&p_p_state=normal&p_p_mode=view&p_p_col_id=column-1&p_p_col_pos=1&p_p_col_count=2[/URL]"
'~~> Destination for the file
strPath = "U:\Virgin.pdf"
Ret = URLDownloadToFile(0, WebAddress, strPath, 0, 0)
End If
Display More
Ideally I want the "Virgin.pdf" name to be the actual invoice ID, but like I said that only appear to come up when you click it.
Is this impossible?
Many many thanks.