Fire Macro Only IF Specific URL Change, Exit Sub IF Not This URL (1 Viewer)

Local time
Today, 02:48
Joined
Oct 16, 2010
Messages
9
Fire Macro Only IF Specific URL Address Change Is Requested From WebBrowser Object?

I am using a WebBrowser Sub that runs a macro when the URL Address changes.

The problem is it fires the macro each time the browser is refreshed because it changes (or refreshes back to itself and runs the macro).

I would like the macro only to run ONLY when a SPECIFIED URL is requested.



The code beneath works great.
All are welcome to try this code for yourself (click on the developer tab>insert tools>more tools>microsoft web browser>draw browser>paste code beneath in vba)
Code:
Private Sub Worksheet_Activate()
WebBrowser1.Navigate  “http://www.google.com”		‘this is home page I want the web browser to start with but NOT run the macro
End Sub
Private Sub WebBrowser1_TitleChange(ByVal sText As String)
MsgBox “Macro Runs Once Web Page Change Occurs”		‘this code works, but the problem is I need the macro to only launch with a specific URL only
End Sub



The only problem is (as stated above), it launches each time the page is opened or refreshed. I am in need of a way to code this the right way so that it only runs the macro if a specified URL address is requested only. This way the macro will not fire up at start up or when the page is refreshed, but yet only when the specified page is loaded with the web browser.

Code:
Private Sub WebBrowser1_TitleChange(ByVal sText As String)
 If address.Equals("http://www.google.com") Then
MsgBox "Macro Runs Because Of Specified URL"		‘I would like the MACRO to RUN because it EQUALS the SPECIFIED URL
        If address.Equals("http://www.YAHOO.com") Then
Do Nothing and Exit Sub						‘I would like it to DO NOTHING and EXIT SUB if the page changes to YAHOO  or anything else for the matter
End Sub




Can anyone help me with the correct working syntax for this code?




all cross post links (8 total): I am checking any every one of them with follow up questions (responses), and I will mark them all as solved once I implement the solution tip top. I thank anyone in advance for any resolution, and for all feed back thus far. I saved these links because my heart was in the right place to mark all of these as solved, but I honestly didn't know that developers check other forums as well. Sincerely: Indi Visual

http://www.access-programmers.co.uk/forums/showthread.php?p=1012675#post1012675
http://forums.anandtech.com/showthread.php?p=30682733#post30682733
http://www.dbforums.com/microsoft-e...l-change-exit-sub-if-not-url.html#post6483450
http://www.excelforum.com/excel-gen...nge-exit-sub-if-not-this-url.html#post2409449
http://social.answers.microsoft.com...g/thread/6486470a-478b-4bf9-9f67-06fe60958da7
http://social.technet.microsoft.com/Forums/en/excel/thread/0e6975d6-68e6-444f-8e35-871e9a936f3c
http://www.mrexcel.com/forum/showthread.php?p=2494267#post2494267
http://www.xtremevbtalk.com/showthread.php?p=1372719
 
Last edited:
Local time
Today, 02:48
Joined
Oct 16, 2010
Messages
9
SOLVED.
DONE.
FINISHED.
VICTORY! : )

Resolution originally posted beneath:
http://www.mrexcel.com/forum/showthread.php?p=2494916#post2494916



Chandoo|KeyMaster at Chandoo.org
Hui at Chandoo.org
DonkeyOte at ExcelForum.com
Rik_UK at SocialAnswers.Microsoft.com
FlyGuy|Lost Soul at XtremeVBTalk.com
Peter_SSs at Mr.Excel.com
John_w at Mr.Excel.com
Norie at Mr.Excel.com


and last but certaintly not least a tremendous thank you to Mr.
Colin Legg at Mr.Excel
for helping me with the finishing touches to actually pull this off.

I appreciated everyone's help on this, and so far this only tested for one button, but the victory was well worth it.
 

Brianwarnock

Retired
Local time
Today, 08:48
Joined
Jun 2, 2003
Messages
12,701
It is great to have feedback like this, many times I have posted code in the Excel forum and never had a response, it is not uncommon for people to post in more than one forum to maximise the chance of a response, nothing wrong with that, but its a pain to do unneeded work because a solution has already been found.
Not that I could help in this case.

Well done

Brian
 

Users who are viewing this thread

Top Bottom