Problem wir global declared Variable using SeleniumBasic

donald_dark

New Member
Joined
Oct 25, 2021
Messages
2
Office Version
  1. 365
Platform
  1. Windows
Dear Community,

I have the following problem:
I have written a code to automate from web browser. Where data from excel spreadsheet is used to fill webforms. The code itself works fine.
I would like to write the macro in such a way that the user can choose which browser is used for automation.
Since I used Selenium to automate Chrome, Edge and so on, some users will fall back to Internet Explorer, since there is no need to install anything else here.
I wrote my main macro which runs the macro for IE or the macro for the other browsers (using Selenium) depending on the user's choice.
Unfortunately, in the macro for the Selenium browsers, I have to declare the Webdriver variable outside the sub so that the browser remains open after the macro ends.
VBA Code:
Private browser as WebDriver
However, for all those who do not have SeleniumBasic installed, this of course creates a compilation error.
Maybe someone has an idea how to work around this problem.

I would like users of IE not to have to install SeleniumBasic. So that all variables of type Selenium only come into play when the user selects Chrome, Edge or so. If I declare the WebDriver in the sub, everything works. However, the browser window then closes at the end.

With kind regards.
 

Excel Facts

Can you AutoAverage in Excel?
There is a drop-down next to the AutoSum symbol. Open the drop-down to choose AVERAGE, COUNT, MAX, or MIN
Since no one could help me, I came up with the solution myself after some research.
I think with Late Binding it should work.
 
Upvote 0

Forum statistics

Threads
1,223,885
Messages
6,175,178
Members
452,615
Latest member
bogeys2birdies

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