Macro running automatically on opening file

virtuosok

Board Regular
Joined
Sep 2, 2020
Messages
209
Office Version
  1. 365
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
 

Excel Facts

Can a formula spear through sheets?
Use =SUM(January:December!E7) to sum E7 on all of the sheets from January through December
1610552400115.png
 
Upvote 0
Solution

Forum statistics

Threads
1,214,583
Messages
6,120,380
Members
448,955
Latest member
BatCoder

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