Capture Browser address

D Willett
SilverLounger
Posts: 1728
Joined: 25 Jan 2010, 08:34
Location: Stoke on Trent - Staffordshire - England

Capture Browser address

Post by D Willett »

Maybe a long shot.
Is there a way to capture an open browser address?

Lets say I have Chrome or IE open ( not in VB6 ) is there an API to detect which browser is open and to capture the url via VB?
Cheers ...

Dave.

User avatar
HansV
Administrator
Posts: 78523
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: Capture Browser address

Post by HansV »

Set a reference to Microsoft Internet Controls.

The following procedure will list the URLs of all open tabs in Internet Explorer:

Code: Select all

Sub GetURLs()
    Dim sw As SHDocVw.ShellWindows
    Dim objIE As SHDocVw.InternetExplorer

    Set sw = New SHDocVw.ShellWindows

    For Each objIE In sw
        Debug.Print objIE.LocationURL
    Next objIE

    Set sw = Nothing
    Set objIE = Nothing
End Sub
(Adapted from Get Current URL in IE Using Visual Basic)

I don't know how to find the active tab (the code in the above link doesn't do that, although it claims to do so), and I have no idea how to do this for Chrome, if it is possible at all.
Best wishes,
Hans

D Willett
SilverLounger
Posts: 1728
Joined: 25 Jan 2010, 08:34
Location: Stoke on Trent - Staffordshire - England

Re: Capture Browser address

Post by D Willett »

Cheers Hans
A quick test gives me:
User-defined type not defined and errors on the first line of code.

I have the "Microsoft Internet Controls" active in the project references.
Any idea's?

Code: Select all

Private Sub Command1_Click()
GetURLs

End Sub
Sub GetURLs()
    Dim sw As SHDocVw.ShellWindows
    Dim objIE As SHDocVw.InternetExplorer

    Set sw = New SHDocVw.ShellWindows

    For Each objIE In sw
        Debug.Print objIE.LocationURL
    Next objIE

    Set sw = Nothing
    Set objIE = Nothing
End Sub
Cheers ...

Dave.

User avatar
HansV
Administrator
Posts: 78523
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: Capture Browser address

Post by HansV »

Are you absolutely sure? I tested the code, and it worked.
IntelliSense recognizes ShDocVw:
S0314.png
The reference:
S0315.png
ShDocVw really is part of Microsoft Internet Controls:
S0316.png
You do not have the required permissions to view the files attached to this post.
Best wishes,
Hans

D Willett
SilverLounger
Posts: 1728
Joined: 25 Jan 2010, 08:34
Location: Stoke on Trent - Staffordshire - England

Re: Capture Browser address

Post by D Willett »

Perhaps theres different versions of the control:??
You do not have the required permissions to view the files attached to this post.
Cheers ...

Dave.

User avatar
HansV
Administrator
Posts: 78523
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: Capture Browser address

Post by HansV »

What happens if you replace both instances of ShDocVw with ShDocVwCtl?
Best wishes,
Hans

D Willett
SilverLounger
Posts: 1728
Joined: 25 Jan 2010, 08:34
Location: Stoke on Trent - Staffordshire - England

Re: Capture Browser address

Post by D Willett »

I get type mismatch?
You do not have the required permissions to view the files attached to this post.
Cheers ...

Dave.

User avatar
HansV
Administrator
Posts: 78523
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: Capture Browser address

Post by HansV »

Apparently I have an entirely different library on my PC than you have. I have tried to search for a solution using ShDocVwCtl, but can't find it. Sorry.
Best wishes,
Hans

D Willett
SilverLounger
Posts: 1728
Joined: 25 Jan 2010, 08:34
Location: Stoke on Trent - Staffordshire - England

Re: Capture Browser address

Post by D Willett »

No Probs Hans.
It was always a long shot given the different browsers available so it would end up being a pointless addition to the project.
Have a great weekend. And thanks.
Cheers ...

Dave.