By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,275 Members | 1,927 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,275 IT Pros & Developers. It's quick & easy.

How Can I Open a Web Browser and Link to Site

P: 2
Can I use VBA or a macro to open a web browser and link to a web site. The hyperlink is in a table.
1 Week Ago #1
Share this Question
Share on Google+
15 Replies

P: 94
How to open IE
Add the following to the "reference"
Microsoft HTML Object Library
Microsoft Internet Controls
Expand|Select|Wrap|Line Numbers
  1. Dim objIE As InternetExplorer
  2. Dim URL As String
  3. Set objIE = CreateObject ("Internetexplorer.Application")
  4. objIE.Visible = True
  5. URL = "https://your_url"
  6. objIE.navigate URL
1 Week Ago #2

Expert Mod 15k+
P: 31,660
Hi SioSio.

We're fast getting to the stage where IE will no longer be available as ubiquitously as it was previously. There are various other browsers available now, and one (Edge) is even from Microsoft. Do you have the CreateObject() code for any of these others?

That would certainly enhance your answer.
1 Week Ago #3

Expert 100+
P: 197

Here is one solution to the unknown browser problem.

Windows knows what your default browser is, so you simply use a batch file to open the url.

The command in the batch file is:

Expand|Select|Wrap|Line Numbers
  1. start %1
You then call that batch file with the Shell command.

Expand|Select|Wrap|Line Numbers
  1. Private Sub Example(ByVal strUrl as String)
  2.   Shell "c:\url.bat " & strUrl
  3. End Sub
Where c:\url.bat is the path to your actual batch file.

This is equivalent to typing a URL into Start -> Run. This approach can be used to start anything, really.

It could be possible to accomplish the whole thing from the Shell call but I have not researched that in all honesty.

You do, however, introduce the need to distribute that batch file with your solution or you can make your solution create it. You could check that batch file exists and create it if it doesn't in your URL calling function or on intital startup if it is likely to be a high frequency use case.

A potential downside to this approach is that beyond the initial load your solution no longer has any control over the browser so you can not automate it if that is your goal. The chromium engine is the way to go in that case, you wouldn't believe how much modern software is just chromium with a wrapper.

1 Week Ago #4

P: 69
It looks like you are using VBA, which reminds me that in the past I programmed in VB6(sp5). I looked and I have a couple of links that you might find useful.
Huge amount of VB6(sp5) on that site that you might find useful for VBA.

And another page that I had saved years ago, and now find that it is a broken link. Does not open for me on the internet. It is on the site .

If you want me to show the code here I can. It is a long list with a lot of code examples.

I think that this site could use it for VBA references. I did not write it, and please note that I gave a partial reference that I did not manage at this time to get to open.


Navigating to a site
Popup browser using your own form
Check if word/string is found on the page
Making page on startup
Regular Browser Functions
Advanced browser functions
Changing web browser’s Font Size
Disabling functions appropriately (Back/Forward)
Disabling functions appropriately (page setup/print preview/print setup)
Removing Right Click Menu From the browser control
Grab all links on the page
Save Page
Open Page
Auto Submit
Using A ProgressBar With The Webbrowser
Setting a Control in a Webbrowser to focus
Checkbox in a page, how to control it
Custom Right Click Menu
There is a lot there.

Maybe some of that may help if the site editors would like me to post that code here.

It does not show on that list but VB6(sp5) can hook and subclass FireFox tabs even though there is only one (1) windows handle to the entire FireFox program. I have seen it done, but you might have to program that one in yourself: catch the new tab as it is an instance before it is added to the single overall one handle then subclass that instance and Firefox in general does not know that anything is happening. Then the web pages can be opened with custom adjustments internal to them, and inside of VB6(sp5). All with VB6(sp5). The thing is, if this can be done with VB6(sp5) then it probably can be done with VBA with some adjustments.
1 Week Ago #5

P: 94
Hi NeoPa.
In CreateObject(), Edge doesn't seem to be selectable.

There is also a way to use Selenium VBA.

After downloading Selenium,
add "Selenium Type Library" in the reference settings.

It supports the following WebDriver.

The new ChromeDriver must be obtained from the following site.

Code tested in Chrome
Expand|Select|Wrap|Line Numbers
  1. Dim driver As New ChromeDriver
  2. driver.Get "http: // your_url"
  3. driver.Quit
1 Week Ago #6

P: 2
Thank you SioSio

but im trying to use a link or web address that is in a table that was entered be a user in a form. is there any other way i can do this with out making the URL Static in the code
1 Week Ago #7

Expert Mod 15k+
P: 31,660
Yes, there certainly is. We're not here simply to do it for you though. You need to jump in with something to show you're not simply using us to get your work done for you. We've seen very little from you so far.

I can tell you that SioSio's code passes a simple string to the driver.Get() call. That string is simple to create and requires only that your web address be appended to the string "https://" in order to work (or http://" if the site doesn't handle secure browsing - some still don't).

That should be simple enough for you. If not then at least have a go at it and show us what you've tried and what the attempt resulted in.
1 Week Ago #8

Expert Mod 15k+
P: 31,660
Here is one solution to the unknown browser problem.
Hi Gaz.

Nice solution, but hard to interface into a table containing the data. Not impossible, but certainly hard.

I love the idea of the BAT (or CMD) file but to get that to be flexible and powerful by linking it to a table and thus creating the file on the fly is a lot more complicated than you may imagine. I know. I've done it. I've even given presentations on how to do it with some example code. Most struggled to get to grips even with most of the code already written and ready to use.

I'm happy to share it but not happy to explain it using the written word when it appears so hard to grasp even when presented with the finished article.

It's an idea I like, but don't believe really has legs in a situation such as this. Great to throw in ideas though, of course.
1 Week Ago #9

P: 94
Access the record set URL value field and set its value to the browser URL.
1 Week Ago #10

Expert 100+
P: 197
Nice solution, but hard to interface into a table containing the data. Not impossible, but certainly hard.
You only need to pass the field data to the function, which takes in a string. The URL is passed to Start via the %1 argument in the batch file. No file creation needed.

linking it to a table and thus creating the file on the fly is a lot more complicated than you may imagine
It is not necessary to do that to get this working.

By creating files on the fly I am referring to initialisation of dependencies the solution needs in first run wizards or startup tests.

Apologies, when I post I assume that these posts will be read by many other people long down the road with similar goals arriving via Google, et al.

Native Access 'Hyperlink' fields open your default browser when you click them in forms and datasheets by default, assuming your source table is Access and you have the ability to refactor it.

1 Week Ago #11

Expert Mod 15k+
P: 31,660
Hi Gaz.

I must have rushed this without considering it fully. You're right of course. An elegant solution as it allows the system to select the browser based on your selected preferences.

I wasn't thinking past the idea of creating a new Batch/CMD file to run every time but your ealier post already illustrated the parameter approach.
1 Week Ago #12

Expert 100+
P: 197
Hi NeoPa,

Thanks, I admit that it is only a half solution in that the browser no longer has any connection to the Access instance that called it so no further automation can be accomplished and as alluded to in my prior post, Hyperlink fields can accomplish this natively.

For me, the usefulness in this approach is that it demonstrates one method of reaching outside of the limitations of the Access runtime without resorting to far more complicated measures, such as writing COM visible wrapper DLLs. One such example is using Shell to call an FTP powershell / python script to send a file you just had Access create.

1 Week Ago #13

Expert Mod 15k+
P: 31,660
To be fair that part was always above and beyond the requirements stated in the OP. Now I better understand the suggestion it would probably be my preference. What is good though is that both approaches have been covered. SioSio went with handling it within the code and you went with the command file one.

All-in-all a good, helpful thread to have available for searchers :-)
1 Week Ago #14

P: 94
Microsoft Edge started successfully using Shell object.
Expand|Select|Wrap|Line Numbers
  1. Dim wUrl As String
  2. Dim url As String
  3. url = "https://your_url"
  4. wUrl = "microsoft-edge:" & url & ""
  5. With CreateObject("Shell.Application")
  6.     .ShellExecute wUrl
  7. End With
1 Week Ago #15

Expert Mod 2.5K+
P: 3,364

I know I am late to this discussion, but is there a particular reason we are avoiding the overly simplistic:

Expand|Select|Wrap|Line Numbers
  1. Call Application.FollowHyperlink(Address:="")

It opens one's default browser and you can feed it whatever string you want. I know Gaz mentioned this in passing in Post #11, but this "appears" to be the simplest and easiest solution and doesn't worry about which browser is installed or using Shell or creating Objects.

Am I missing something obvious?? I'm glad to be corrected on this one....
1 Week Ago #16

Post your reply

Sign in to post your reply or Sign up for a free account.