Selenium - Open Browser, Select All, Copy, Paste

FrankieGTH

New Member
Joined
May 29, 2021
Messages
9
Office Version
  1. 365
Platform
  1. Windows
Hello all,

I've been using the same VBA for years that opens IE, selects everything in the browser, copies it and pastes into Excel.

VBA Code:
URL = Sheets("Links").Range("H1")
Dim IE As Object
'Dim document As Object
Set IE = CreateObject("internetexplorer.application")
With IE
.Visible = True
.Navigate URL

        Call Application.Wait(Now + TimeValue("0:00:05"))
        Do Until .ReadyState = 4: DoEvents: Loop

Do While .ReadyState <> 4
DoEvents
Loop
.ExecWB 17, 2
.ExecWB 12, 2


ActiveSheet.PasteSpecial Format:="HTML", Link:=False, DisplayAsIcon:= _
        False, NoHTMLFormatting:=True

Further to this, I create a loop whereby the URL updates in H1 and loops to scrape multiple pages, it's been super useful for handling all types of websites over the years.

With the phasing out of IE and more and more websites not being compatible with IE, this VBA is becoming past its sell by date.

I have very limited IT skills, but through Googling have become aware of Selenium and have just barely managed to use the code in the website linked to open a browser.

VBA Code:
Sub Test()
Dim bot         As New WebDriver
    Dim Body As String
    
    bot.Start "chrome", "https://www.google.co.uk/"
    bot.Get "/"
    
End Sub

This code works, but I am completely out of my depth what to do next.

I'd be ever so grateful if the above code could be adapted to work in a similar vain to the IE VBA up top, one that refers to a URL in a cell. I'd use the code for various websites, so I'm not looking to scrape a specific table(s) with a website.

Kind Regards,

Frankie
 

Excel Facts

Add Bullets to Range
Select range. Press Ctrl+1. On Number tab, choose Custom. Type Alt+7 then space then @ sign (using 7 on numeric keypad)

Forum statistics

Threads
1,223,903
Messages
6,175,289
Members
452,631
Latest member
a_potato

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