If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > PC based Database Applications > Microsoft Excel > Fire Excel Macro Only IF Specific URL Change, Exit Sub IF Not This URL

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 10-29-10, 21:41
indi visual indi visual is offline
Registered User
 
Join Date: Oct 2010
Posts: 3
Fire Excel Macro Only IF Specific URL Change, Exit Sub IF Not This URL

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/...75#post1012675
http://forums.anandtech.com/showthre...3#post30682733
Fire Excel Macro Only IF Specific URL Change, Exit Sub IF Not This URL
http://www.excelforum.com/excel-gene...ml#post2409449
http://social.answers.microsoft.com/...7-06fe60958da7
http://social.technet.microsoft.com/...5-871e9a936f3c
http://www.mrexcel.com/forum/showthr...67#post2494267
http://www.xtremevbtalk.com/showthread.php?p=1372719






SOLVED.
DONE.
FINISHED.
VICTORY! : )

Resolution originally posted beneath:
http://www.mrexcel.com/forum/showthr...16#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.

Last edited by indi visual; 10-30-10 at 20:06. Reason: Thank You's
Reply With Quote
Reply

Tags
title_change

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On