question

Mohtadi-6269 avatar image
1 Vote"
Mohtadi-6269 asked WafaHabchi-9691 answered

EDGE : Opening and filling a webpage through VBA

Hello ,


As IE is decommissionned , we are trying to migrate to EDGE / Chrome or any other viable alternative...


many VBA macros in my organization , depend on IE to open websites and fill some information automatically...


We are trying to switch these macros to open EDGE instead ( basically , replace the CreateObject ( IE ) ) , with another alternative....


Macros ,are as well , filling and parsing websites...


I would like to know , what is the plan for this please?

office-vba-devms-edge
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

YuZhou-MSFT avatar image
0 Votes"
YuZhou-MSFT answered RAJAARAMADANE-5032 commented

Hi @Mohtadi-6269

If you want to automate Edge through VBA, you need to use SeleniumBasic. SeleniumBasic is a Selenium based browser automation framework for VB.Net, VBA and VBScript.

You can follow the steps below to automate Edge browser with SeleniumBasic:

  1. Download the latest version of SeleniumBasic v2.0.9.0 from this link and install it.

  2. Download the corresponding version of Edge WebDriver from this link.

  3. Find the path of SeleniumBasic which is C:\Users\%username%\AppData\Local\SeleniumBasic in my situation (it might also be in this path C:\Program Files\SeleniumBasic), copy the Edge WebDriver msedgedriver.exe to this path.

  4. Rename msedgedriver.exe to edgedriver.exe.

  5. Open Excel and prepare to write the VBA code.

  6. In the VBA code interface, click Tools > References, add Selenium Type Library reference and click OK to save.

  7. Example VBA code (you can change it according to your demands):

     Public Sub Selenium()
         Dim bot As New WebDriver
         bot.Start "edge", "https://www.google.com"
         bot.Get "/"
         bot.Wait 5000
         bot.Quit
     End Sub
    

If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

Regards,
Yu Zhou

· 4
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Thanks @YuZhou-MSFT

Indeed , i started doing this , but we are facing two problems :

  1. Due to IE decom soon , we have a lot of legacy code , depending on VBA / IE communication that needs to be migrated to use Selenium... Microsoft indicated it is trying to minimise the impact of the migration , but this looks such a heavy task ..

  2. Most important : is that , personally , i havent found a way to "translate code" from legacy VBA / IE , to the Selenium library
    For example , i was doing somthing like :


Set HTMLdoc = IEApp.document
Set FrameDoc = HTMLdoc.frames.document
FrameDoc.getElementById("XXX").Focus
FrameDoc.getElementById("XXX").FireEvent ("onchange") ( or ("onkeypress") , or ("onblur") ....)

But there is no way to know how to translate this with the selenium driver easily ...






1 Vote 1 ·

Hi @Mohtadi-6269

There's no easy way to translate the legacy IE code to Edge code. You can only rewrite the code if you're going to use Edge.

Besides, regarding the VBA code automating IE, from the official doc, IE retirement will only affect the following:

200831-image.png

IE platform (MSHTML/Trident) will still work. VBA automate IE using IE COM objects which I think will still work after IE retirement.

1 Vote 1 ·
image.png (11.6 KiB)

great answer

0 Votes 0 ·

Good feedback

0 Votes 0 ·
vingasoline-3643 avatar image
0 Votes"
vingasoline-3643 answered

refer to a comment by KelvinYeung-7479 here https://docs.microsoft.com/en-us/answers/questions/829365/vba-automation-with-edge-ie-mode.html

it is possible to have Edge do some data input for you with the IE mode on, but I don't think you can execute the "on click", etc. events thru that code. At least I wasn't able to.

5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

WafaHabchi-9691 avatar image
0 Votes"
WafaHabchi-9691 answered

Good answer

5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.