Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Retrieving URL's from IE 3

Status
Not open for further replies.

JBU

Instructor
Nov 3, 2003
25
IN
Hi

I'm trying to figure out whether it is possible from Word to retrieve the active URL's in all open Internet Explorer window. My problem is that these explorer windows will most likely not be opened from inside Word. Any ideas?

Jens Busse
Workflow Consultant
CCI Europe A/S
 
What do you mean by "active URL"?

Gerry
 
Well, just the URL in the address field of the open IE's on the workstation.

Jens Busse
Workflow Consultant
CCI Europe A/S
 

It's possible. This works on my machine (XP SP2, IE 7, Word 2003).

Code:
Sub GetURLFromIE()
  Dim objShell As Object
  Dim objWindows As Object, objWindow As Object
    
  Set objShell = CreateObject("Shell.Application")
  Set objWindows = objShell.Windows
  
  For Each objWindow In objWindows
    If Right(objWindow.FullName, 12) = "iexplore.exe" Then
      Debug.Print objWindow.LocationURL
    End If
  Next
  Set objWindow = Nothing
  Set objWindows = Nothing
  Set objShell = Nothing
End Sub

Hope this helps,
CMP

[small]For the best results do what I'm thinking, not what I'm saying.[/small]
(GMT-07:00) Mountain Time (US & Canada)
 



CMP, thanx! Put that one in my bag of trix. ==> *

Skip,
[sup][glasses]Don't let the Diatribe...
talk you to death![tongue][/sup][sub]
[glasses]Just traded in my old subtlety...
for a NUANCE![tongue][/sub]
 
That is perfect!! Thank you very much. [thumbsup2]

Jens Busse
Workflow Consultant
CCI Europe A/S
 
Just to comment, CMP's code does NOT work for me unless I make it Uppercase. It does not work otherwise.
Code:
    If Right(objWindow.FullName, 12) = UCase("iexplore.exe") Then
      Debug.Print objWindow.LocationURL
    End If
Further, with Tabs in IE 7, the following returns the URL for each Tab, without the use of Right(objWindow.FullName, 12).
Code:
Sub GetURLFromIE()
  Dim objShell As Object
  Dim objWindows As Object, objWindow As Object
    
  Set objShell = CreateObject("Shell.Application")
  Set objWindows = objShell.Windows
  
  For Each objWindow In objWindows
      Debug.Print objWindow.LocationURL
  Next
  Set objWindow = Nothing
  Set objWindows = Nothing
  Set objShell = Nothing
End Sub
In fact, at least on my system,

Right(objWindow.FullName, 12)

seems to ignore all Office and other Windows application (EXCEPT explorer.exe). I have the following applications open:

Outlook
Powerpoint - two presentation files
PolyView - a graphics app
MS Word - three documents open
IE 7 - three Tabs with URL
Windows Explorer

The result of...
Code:
Sub GetURLFromIE_2()
  Dim objShell As Object
  Dim objWindows As Object, objWindow As Object
    
  Set objShell = CreateObject("Shell.Application")
  Set objWindows = objShell.Windows
  
  For Each objWindow In objWindows
          [b]Debug.Print objWindow.FullName
  Next
  Set objWindow = Nothing
  Set objWindows = Nothing
  Set objShell = Nothing
End Sub

C:\Program Files\Internet Explorer\IEXPLORE.EXE
C:\Program Files\Internet Explorer\IEXPLORE.EXE
C:\Program Files\Internet Explorer\IEXPLORE.EXE
C:\WINNT\Explorer.EXE

All the other application windows are ignored.

Gerry
 
That's even better. Thanks.

I've been trying to find a way of determining which of the IE windows that has been used last by the user, but without any luck. I tried with objWindow.Document.LastModified, but that is also updated by IE itself (automatic refreshes and such). Any ideas?

Jens Busse
Workflow Consultant
CCI Europe A/S
 
I've been trying to find a way of determining which of the IE windows that has been used last by the user, but without any luck. I tried with objWindow.Document.LastModified, but that is also updated by IE itself (automatic refreshes and such). Any ideas? "

I do not understand what you mean by "which of the IE windows that has been used last by the user".

Are you trying to find out if IE window X has had a click (on a link) after IE window Y has had a click?

1. Why????

2. I do not think this is possible from Word VBA. But I could be wrong.

Gerry
 

This is not necessarily true in all cases but the window/app with the largest hwnd # could be the most recent spawned/activated app.

Just a thought

Good Luck

 
Yes, but doesn't the hwnd only show which instance of IE that has been created last. Does activation really change the hwnd?

Here is my scenario:

The user has used one of many already open IE's to look up a website. I want to be able to retrieve the url from this one.

Jens Busse
Workflow Consultant
CCI Europe A/S
 
I have to ask again....WHY? Mostly I am simply curious.

Gerry
 
Well, I have to re-create the standard hyperlink functionality and make it as easy as possible (as few operations as possible) for the users.

We are using a very customized version of Word as an editor for editorial systems for newspapers. Due to the customizations we cannot use the standard hyperlink stuff. So I'm re-creating it and improving it :)

Jens Busse
Workflow Consultant
CCI Europe A/S
 

Yes you are right... I misunderstood what you were wanting which then means you would have to enum the windows and I believe, could be wrong, that via the enumeration you can get the order or the window that has the focus or is at the top of the "stack" of windows.

I know there is code around here somewhere that may point this out... hmmm where is it? Try a search for enum windows but make sure you have the VB 5/6 forum listed within your forum search.

 
Ok, the solution I have so far is fairly decent. If the user has found the website in the last added IE window, then I make it easily available, and I've put all the URL's in a dropdown in a userform. That should do the trick.

But I will have a look at that enum stuff. Thank you all. This has been extremely helpful.

Jens Busse
Workflow Consultant
CCI Europe A/S
 
JBU,
The only solution I ever came up with for this problem was to present the user with a list of open IE windows and let them select the correct window.

Check out [tt]GetIEApp[/tt] in faq707-6399, it has a cludgy [tt]InputBox[/tt] method for doing this (the code will look familar). You could use the concept in a [tt]UserForm[/tt] to get a more "glossy" look.

Hope this helps,
CMP

P.S. On [tt]UCase[/tt], I usually use [tt]Option Compare Text[/tt] in all modules since I do so many text comparisons.

[small]For the best results do what I'm thinking, not what I'm saying.[/small]
(GMT-07:00) Mountain Time (US & Canada)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top