Macro running automatically on opening file

virtuosok

Board Regular
Joined
Sep 2, 2020
Messages
103
Office Version
  1. 2016
Platform
  1. Windows
Hi,
How should I modify this code in order for it to run automatically upon opening .xlsm file?
VBA Code:
Sub scrape_link()
    'If any element is not available, the program will move to next line.
    On Error Resume Next
   
    Dim HTMLDoc As New HTMLDocument
    Dim ieBrowser As New InternetExplorer
    Dim reqdValue As String
 
    'To open and show Internet Explorer
    ieBrowser.Visible = True
   
    'To Open website in Internet Explorer
    ieBrowser.navigate "https://clinicaltrials.gov/ct2/show/study/NCT04201093"
   
    Do
    ' Wait till the Browser is loaded
    Loop Until ieBrowser.readyState = READYSTATE_COMPLETE
   
    Set HTMLDoc = ieBrowser.document
   
    reqdValue = HTMLDoc.getElementById("EXPAND_CONTROL-Locations").innerText
   
    ActiveSheet.Range("B7") = Mid(reqdValue, 8, WorksheetFunction.Find(" ", reqdValue, 8) - 8)
    
    'To Open website in Internet Explorer
    ieBrowser.navigate "https://clinicaltrials.gov/ct2/show/NCT04223193?term=NCT04223193&draw=2&rank=1"
    
    Do
    ' Wait till the Browser is loaded
    Loop Until ieBrowser.readyState = READYSTATE_COMPLETE
   
    Set HTMLDoc = ieBrowser.document
   
    reqdValue = HTMLDoc.getElementById("EXPAND_CONTROL-Locations").innerText
    ActiveSheet.Range("C7") = Mid(reqdValue, 8, WorksheetFunction.Find(" ", reqdValue, 8) - 8)
    
    'To Open website in Internet Explorer
    ieBrowser.navigate "https://clinicaltrials.gov/ct2/show/NCT04542499"
    
    Do
    ' Wait till the Browser is loaded
    Loop Until ieBrowser.readyState = READYSTATE_COMPLETE
   
    Set HTMLDoc = ieBrowser.document
   
    reqdValue = HTMLDoc.getElementById("EXPAND_CONTROL-Locations").innerText
    ActiveSheet.Range("D7") = Mid(reqdValue, 8, WorksheetFunction.Find(" ", reqdValue, 8) - 8)
    
     'To Open website in Internet Explorer
    ieBrowser.navigate "https://clinicaltrials.gov/ct2/show/NCT04244175"
    
    Do
    ' Wait till the Browser is loaded
    Loop Until ieBrowser.readyState = READYSTATE_COMPLETE
   
    Set HTMLDoc = ieBrowser.document
   
    reqdValue = HTMLDoc.getElementById("EXPAND_CONTROL-Locations").innerText
    ActiveSheet.Range("E7") = Mid(reqdValue, 8, WorksheetFunction.Find(" ", reqdValue, 8) - 8)
       
    Set ieBrowser = Nothing
    Set HTMLDoc = Nothing
End Sub
 

Some videos you may like

Excel Facts

Excel motto
Not everything I do at work revolves around Excel. Only the fun parts.

Jeffrey Mahoney

Well-known Member
Joined
May 31, 2015
Messages
1,830
Office Version
  1. 365
Platform
  1. Windows
1610552400115.png
 
Solution

Watch MrExcel Video

Forum statistics

Threads
1,128,061
Messages
5,628,369
Members
416,314
Latest member
Dan99321

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
Top