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

How to change case of text in Excel?
Use =UPPER() for upper case, =LOWER() for lower case, and =PROPER() for proper case. PROPER won't capitalize second c in Mccartney

Forum statistics

Threads
1,224,823
Messages
6,181,177
Members
453,021
Latest member
Justyna P

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