im writing a macro to try and automate a very tedious monthly task, it involves logging into a website, downloading a CSV file and then doing some cleaning and rearranging before uploading it to a database.
Im stuck on one very specific part of the process and have tried multiple solutions but cant get it to work, specifically identifying and clicking the button which creates the download file,
This is the HTML for the button I need to access -
<button class="btn btn-primary btn-xs" type="button" data-toggle="modal" data-target="#download_modal" data-licenceno="33872" data-dfname="Care & Nursing Homes Master" data-dfid="1001">Create a new file containing all records</button>
This is what I have so far, it works up until the for each loop in the download file sub, i'm currently just trying to identify the button so I can click it, but it doesn't identify anything with that class, despite copying the class name exactly from the HTML, no errors but also nothing writes to the immediate window, I cant seem to find any way to access the button so any help would be appreciated.
Option Explicit
Sub Opensite()
'open caredata URL and login
Dim IEapp As Object, WebURL As String, HTMLdoc As HTMLDocument
Set IEapp = CreateObject("InternetExplorer.Application")
WebURL = "URL"
With IEapp
.silent = True
.Visible = True
.Navigate WebURL
Do Until IEapp.readyState = 4
DoEvents
Loop
Set HTMLdoc = IEapp.document
End With
With HTMLdoc.forms(0)
.UserName.Value = "myusername"
.Password.Value = "mypassword"
.btn_signin.Click
End With
downloadfile IEapp, HTMLdoc
End Sub
Private Sub downloadfile(IE As Object, HTML_doc As HTMLDocument)
'download CSV file
Dim o As Object, i As Object
Do Until IE.readyState = 4
DoEvents
Loop
Set o = IE.document.getElementsByClassName("btn btn-primary btn-xs")
For Each i In o
Debug.Print i.innerHTML
Next i
End Sub