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

Highlight Duplicates
Home, Conditional Formatting, Highlight Cells, Duplicate records, OK to add pink formatting to any duplicates in selected range.

lrobbo314

Well-known Member
Joined
Jul 14, 2008
Messages
2,780
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,847
Messages
5,489,229
Members
407,682
Latest member
gmb2521

This Week's Hot Topics

  • Timer in VBA - Stop, Start, Pause and Reset
    [CODE=vba][/CODE] Option Explicit Dim CmdStop As Boolean Dim Paused As Boolean Dim Start Dim TimerValue As Date Dim pausedTime As Date Sub...
  • how to updates multiple rows in muliselect listbox
    Hello everyone. I need help with below code. code is only chaning 1st row in mulitiselect list box. i know issue with code...
  • Delete Row from Table
    I am trying to delete a row from a table using VBA using a named range to find what I need to delete. My Range is finding the right cell. In the...
  • Assigning to a variable
    I have a for each block where I want to assign the value in column 5 of the found row to the variable Serv. [CODE=vba] For Each ws In...
  • Way to verify information
    Hi All, I don't know what to call this formula, and therefore can't search. I have a spreadsheet with information I want to reference...
  • Active Cell Address – Inactive Sheet
    How to use VBA to get the cell address of the active cell in an inactive worksheet and then place that cell address in a location on the current...
Top