 |
| Excel VBA Discuss using VBA for Excel programming. |
Welcome to the p2p.wrox.com Forums.
You are currently viewing the Excel VBA section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
|
|
|
|

January 18th, 2007, 07:29 AM
|
|
Registered User
|
|
Join Date: Jan 2007
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Determine the URL that is displayed in IE
I need a VBA macro that will determine the name of a window open, or will determine the URL of a website that is open in IE.
I've found absolutely no information about if this is even possible, but it must be!
Can anyone help?
|
|

January 18th, 2007, 07:52 AM
|
|
Registered User
|
|
Join Date: Jan 2007
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Hello,
I don't know if that can help, but if you go in view source, you will see the full nam of the url in Ie.
appart from that...
Hope it helps
Luc ARNOLD
|
|

January 18th, 2007, 07:55 AM
|
|
Registered User
|
|
Join Date: Jan 2007
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Yeah, I currently view source, select all, and then paste it into my excel sheet. This allows me to do my check to see what page it is on. It's a .asp file that is used to create a new user account, and I need to check whether it was successful, or if the page contains the words "username already exists". Alternatively, if I can capture the URL of the page that is open I can do it this way.
|
|

January 18th, 2007, 07:58 AM
|
|
Friend of Wrox
|
|
Join Date: Jun 2003
Posts: 173
Thanks: 0
Thanked 3 Times in 3 Posts
|
|
s this the sort of thing you're after? NB will need references to "Microsoft Shell Controls and Automation" and "Microsoft Internet Controls"
[code]
Sub test()
Dim shSh As Shell32.Shell
Dim objWindows As Object
Dim objWindow As SHDocVw.InternetExplorer
Dim i As Integer
Set shSh = New Shell32.Shell
Set objWindows = shSh.Windows
For Each objWindow In objWindows
MsgBox objWindow.LocationURL
Next objWindow
End Sub
[code\]
|
|

January 18th, 2007, 09:16 AM
|
|
Registered User
|
|
Join Date: Jan 2007
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Thanks for the input. I'm confused as to why you included the 'Dim i as integer' line tho...
With "Microsoft Shell Controls and Automation" and "Microsoft Internet Controls", what are they and how do I set up these references?
I tried to insert the code, but it doesn't like the 'Dim shSh As Shell32.Shell' line.
|
|

January 18th, 2007, 09:31 AM
|
|
Friend of Wrox
|
|
Join Date: Jun 2003
Posts: 173
Thanks: 0
Thanked 3 Times in 3 Posts
|
|
Sorry - written at speed. You can drop the dim i as interger.
To add a reference you need to be in the VBE (Visual Basic Editor) then select from the menu Tools -> References... You should now have a dialogue box pop up with a large number of check boxes on it. Scroll down the list and check the named items "Microsoft Shell Controls and Automation" and "Microsoft Internet Controls". Click Ok and you should be good to go.
Maccas
|
|

January 18th, 2007, 09:56 AM
|
|
Registered User
|
|
Join Date: Jan 2007
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Brill! This is displaying the name of the window (like this is "p2p.wrox.com Forums") which is getting me halfway there. I'd like to eliminate having to do my opening of notepad however as this is where the problem usually occurs.
Is there any way to return the actual URL of the document? (e.g. this page has a URL of "http://p2p.wrox.com/post.asp?method=Reply&TOPIC_ID=55024&FORUM_ID=72") .
|
|

January 18th, 2007, 10:02 AM
|
|
Registered User
|
|
Join Date: Jan 2007
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
I tell a lie, it does bring back the URL! I hadn't realised it wasn't reporting the currently active window first.
Is there a way to ensure it begins it's check with the currently active window?
|
|

January 18th, 2007, 10:12 AM
|
|
Friend of Wrox
|
|
Join Date: Jun 2003
Posts: 173
Thanks: 0
Thanked 3 Times in 3 Posts
|
|
You can't do that - to the best of my knowlegde - without going into the WinAPI, a nasty horrible place that's best avoided unless really necessary. Even then I wouldn't be sure of quite how to go about it without spend the best part of a day trawling through MSDN. Can you not use the iteration loop to loop through and check when you have the correct window to hand?
You should be able to do some sort of test. If you're looking for inspiration on the test you could do try looking at the properties of the IE window you want at run-time. You can do this by first getting the code to pause during the run with a break point on the MsgBox line (add a breakpoint by left clicking in the gutter to the right of the code and in line with the desired line - on my computer it shades the line brown with a circular dot). On running the code will debug out to a highlighted yellow line to show where you've got to. You can move the higlighted line on one step at a time by pressing F8 or run though to the next breakpoint / end by pressing F5. At this point you should open up the Locals window and expand up the properties of objWindow. From here you can see stuff to test for...
Maccas
|
|
 |