VBA detect already opened internet explorer webpage; bring this page to front and focus

RAYLWARD102

Well-known Member
Joined
May 27, 2010
Messages
529
I have a need, for grabbing clipboard data from web pages already opened on my computer. I'm able to loop through these pages and determine which ones are my intended sources, but haven't been able to find a way to bring these webpages forward, to focus. Once I get passed the page being up and in focus, I'll be able to sendkeys to initiate the clipboard copy. The source webpages are web pdf's (none of the links allow me to download the pdf files; otherwise I would and already have a macro for opening, extracting via clipboard, and closing the pdf file)
So far I've been playing with the following code samples and don't know how to bring the internet explorer window into focus. Actually it does bring the internet window into focus; but I also need the tab brought into focus (I don't need help with the extraction stuff afterwards)

Code:
    Dim objShellWindows As New SHDocVw.ShellWindows
    Dim win As Object, rv As SHDocVw.InternetExplorer
    Dim go As Boolean
    
    For Each win In objShellWindows
        If TypeName(win.Document) = "Object" Then 'opened pdf via browser
            If InStr(1, win.LocationName, "ViewPdfSet", vbTextCompare) Then 'is in the url and helps me detect these exact pages
                Set rv = win
                Debug.Print win.LocationName
                rv.Visible = False
                rv.Top = 0
                rv.Left = 0
                rv.Visible = True
            End If
        End If
    Next win
    
    Set objShellWindows = Nothing
    Set win = Nothing
    Set rv = Nothing

or

Code:
    Dim w As SHDocVw.InternetExplorer
    
    Dim window As Object
    For Each window In CreateObject("Shell.Application").Windows
        With window
            Debug.Print window.Title
            
            If InStr(1, .Name, "Internet Explorer", vbTextCompare) Then
                If InStr(1, .LocationName, "ViewPdfSet", vbTextCompare) Then
'bring focus from here????
                End If
            End If
        End With
    Next window
    Set window = Nothing
[CODE]
 
Last edited:

Excel Facts

Workdays for a market open Mon, Wed, Friday?
Yes! Use "0101011" for the weekend argument in NETWORKDAYS.INTL or WORKDAY.INTL. The 7 digits start on Monday. 1 means it is a weekend.

Forum statistics

Threads
1,215,131
Messages
6,123,222
Members
449,091
Latest member
jeremy_bp001

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