Fire Excel Macro Only IF Specific URL Change, Exit Sub IF Not This URL

indi visual

New Member
Joined
Oct 15, 2010
Messages
22
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?
 
Who has to 'talk' to the Excel file?

Can you give an 'overview' of what you are actually trying to do?

eg what is the purpose of the webbrowser control?

Are you using it to access data?

Just to display data or images?
 
Upvote 0

Excel Facts

Format cells as date
Select range and press Ctrl+Shift+3 to format cells as date. (Shift 3 is the # sign which sort of looks like a small calendar).
As for an overview, my previous post before last in this thread explains it all. I gave you partial credit for helping as well.

I wanted flashy buttons. Drawing shapes and inserting pictures didn't tickle my fancy. I think the native buttons (and or button options) for excel in general are boring. So I spiced things up with these buttons.

Now I have flash based buttons.

As for what's "talking", I meant javascript and html (communicating) with excel to tell excel to fire certain macros.

I can write a web page all day long like nobody's business; however, getting the webpage to make excel do a task is completely different ball game.

I don't think it's even possible actually, but if you think it is and you know how I'm all ears.
 
Upvote 0
Perhaps I wasn't clear - what overall functionality are you looking for?

eg what tasks are the macros in Excel actually doing?

Is the reason for using a web browser mainly because of the buttons?

Have you considered embedding a ShockWave Flash Object in Excel?

Mind you I suppose that would just be like the web browser.:)

You can use Excel in some ways with webpages but that's normally to do with importing/exporting data, creating workbooks/worksheets.

There also seems to be quite a few things available for automating Excel using ASP.NET, but they mostly seem to be commercial.

Anyway you don't need to respond, just some ideas and if you've got things working as you want that's the important thing.

Perhaps more curiousity than anything - I've never heard of a web browser control being used like this.:)
 
Upvote 0

Forum statistics

Threads
1,215,575
Messages
6,125,616
Members
449,238
Latest member
wcbyers

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top