I need help to get to a web page, download and save all the avaiable files (CSV and PDF). For now I can only make login in the website and click on the right link. Now i need help to download and save the files.
My code for now:
Sub login()
Const Url$ = "https://www.hapvida.com.br/pls/webhap/webNewTrocaArquivo.login"
Dim UserName As String, Password As String, LoginData As Worksheet
Set LoginData = ThisWorkbook.Worksheets("1")
UserName = LoginData.Cells(2, "B").Value
Password = LoginData.Cells(3, "B").Value
Dim ie As InternetExplorer
Set ie = CreateObject("InternetExplorer.Application")
With ie
.Navigate Url
ieBusy ie
.Visible = True
Dim oLogin As Object, oPassword As Object, oCodigo As Object
Set oLogin = .Document.getElementsByName("pCpf")(0)
Set oPassword = .Document.getElementsByName("pSenha")(0)
oLogin.Value = UserName
oPassword.Value = Password
.Document.forms(0).submit
ieBusy ie
Set alllinks = ie.Document.getElementsByTagName("a")
For Each Link In alllinks
If Link.innerText = "BAIXAR ARQUIVOS - DOWNLOAD" Then
Link.Click
Exit For
End If
Next
ieBusy ie
'Problematic part
Set fulllinks = ie.Document.getElementsByTagName("a")
For Each Links In fulllinks
If Right(Links.innerText, 3) = "PDF" Then
Links.Click
Exit For
End If
Next
ieBusy ie
End With
End Sub
Sub ieBusy(ie As Object)
Do While ie.Busy Or ie.ReadyState < 4
DoEvents
Loop
End Sub
The page i need to get the files from: