ShankarSangoli
ShankarSangoli

Reputation: 69905

How to open default browser in both PC and Mac using Excel VBA?

I need to open a url in the default web browser using Excel VBA. It should work both in PC as well as Mac.

I also need to get hold of the browser instance so I can access its document object and read some of the html elements or anything from the page rendered in the browser.

I know how to open InternetExplorer using CreateObject which gives you back the browser instance. Maybe in Mac I can open the Safari browser the same way. But I want to open the default web browser and also get the browser instance.

Upvotes: 4

Views: 5121

Answers (1)

Comintern
Comintern

Reputation: 22185

I'd personally let Excel figure it out:

ActiveWorkbook.FollowHyperlink "https://www.google.com"

I can't test whether this works on a Mac (but I don't see any reason why it wouldn't).

Note that if you want to use the default browser, you won't be able to ensure that you can even get an object instance (i.e. Chrome, Firefox, Opera, etc., etc.). I'd display for the user in the browser, then grab the html from the same link concurrently with some other method.

Upvotes: 1

Related Questions