How to Click a link on webpage

Rezach20

New Member
Joined
Aug 17, 2019
Messages
1
I am unexperienced when it comes to navigating websites using VBA (or any code). I have been able create code to open the desired websites but now I am trying to automate "clicking a link" to save additional time.

I have an excel file full of various patent numbers. I have been able to create code that will open each of the patents within google.patents.
For example https://patents.google.com/patent/US10000000

Now I would like to automate clicking on the "Download PDF" link.

I am not sure where to start. Any help would appreciated.

Thx,
--Rezach20
 

Some videos you may like

Excel Facts

How can you turn a range sideways?
Copy the range. Select a blank cell. Right-click, Paste Special, then choose Transpose.

lrobbo314

Well-known Member
Joined
Jul 14, 2008
Messages
2,761
Office Version
365, 2019, 2016
Platform
Windows
Try this. Instead of clicking the link, this gets the href from the link and downloads it to the desktop. Make sure to change the commented line to where you want the files saved. Also, the code can be amended to loop through several patent numbers. This one just does the one that you gave in the OP.

Code:
Private Declare PtrSafe Function URLDownloadToFile Lib "urlmon" _
    Alias "URLDownloadToFileA" (ByVal pCaller As Long, ByVal szURL As String, _
    ByVal szFileName As String, ByVal dwReserved As Long, ByVal lpfnCB As Long) As Long

Sub DownloadPDF()
Dim IE As Object: Set IE = CreateObject("InternetExplorer.Application")
Dim URL As String: URL = "https://patents.google.com/patent/US10000000"
Dim SP() As String: SP = Split(URL, "/")
Dim pNum As String: pNum = SP(UBound(SP))
Dim Path As String: Path = "C:\Users\USERNAME\Desktop\" 'Change to where you want the file to be saved
Dim Link As Object
Dim HTML As Object

IE.navigate (URL)

Do While IE.busy = True Or IE.readystate <> 4
    DoEvents
Loop

Set HTML = IE.document
Set Link = HTML.querySelector("#wrapper > div:nth-child(2) > div.flex-2.style-scope.patent-result > section > header > div > a")
downloadFile Link.href, Path, pNum
Set IE = Nothing
End Sub

Sub downloadFile(URL As String, Path As String, FileName)
URLDownloadToFile 0, URL, Path & FileName & ".pdf", 0, 0
End Sub
 

Watch MrExcel Video

Forum statistics

Threads
1,102,362
Messages
5,486,395
Members
407,544
Latest member
mguevara

This Week's Hot Topics

Top