Results 1 to 1 of 1
  1. #1
    Join Date
    Oct 2010

    Unanswered: 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)
    Private Sub Worksheet_Activate()
    WebBrowser1.Navigate  “”		‘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.

    Private Sub WebBrowser1_TitleChange(ByVal sText As String)
     If address.Equals("") Then
    MsgBox "Macro Runs Because Of Specified URL"		‘I would like the MACRO to RUN because it EQUALS the SPECIFIED URL
            If address.Equals("") 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

    VICTORY! : )

    Resolution originally posted beneath:

    Chandoo|KeyMaster at
    Hui at
    DonkeyOte at
    Rik_UK at
    FlyGuy|Lost Soul at
    Peter_SSs at
    John_w at
    Norie at

    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 21:06. Reason: Thank You's

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts