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
 

Excel Facts

Best way to learn Power Query?
Read M is for (Data) Monkey book by Ken Puls and Miguel Escobar. It is the complete guide to Power Query.
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
 
Upvote 0

Forum statistics

Threads
1,223,575
Messages
6,173,148
Members
452,502
Latest member
PQCurious

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top