• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

Call a macro sub from a web browser link

indi visual

New Member
I have a web browser object embedded in the header of my sheet.


Is it possible to call a sub macro from a link in the web brower object?
 

keymaster

New Member
I guess you can add an event on webbrowser active x to monitor which URLs are getting requested and fire the macro when URLs match. I have never worked with browser object thru excel, so no idea what events it supports.
 

indi visual

New Member
@ Chandoo Key Master (my question a little more clear),


I am still new to all of this (and not quite sure how to add an active X event monitor to my links).


I basically have a web browser embed in my excel sheet (the html page is simply a page with shortcuts).


It all started off as simple jpg buttons and shapes linked to different things (basic add link function in excel), and then I wanted to get glamorous with the links and came up with this idea...


It is basically a web page full of flash based fancy shortcuts (that's pretty much it). It works the same way (only through a web browser object). It looks pretty neat and adds style to my excel page (I use these links a lot).


However, now I wonder if I could I use those links to trigger macros from within the excel sheet?


It would give a more seamless and well designed feel to the entire excel sheet if that were possible.
 

keymaster

New Member
@Indi...


As you can imagine.. firing excel macros from browser would be pretty deep security hole. So there is no natural way to do this (as far as I know). But you can use browser object's events to do something like this.


Btw, if all you want are flash buttons, why not embed them directly in Excel using flash objects? That way you could run macros from _onlick() event...?
 

Hui

Excel Ninja
Staff member
Indi

When you say a web browser embeded.., are you referring to an actual web browser where you can surf the net, or is it a screen that looks like it has a number of links and other objects so it appears like a web browser ?
 

indi visual

New Member
@ Chandoo Key Master


How exactly do I add an _onlick() event?


I know how to add a link to a button in Adobe Flash, but how do I tweak this to actually execute a sub macro?

[pre]<br />
myBtn.onRelease = function() {<br />
getURL("http://www.chandoo.org;);<br />
};<br />



@ Hui


Under Developer Tab>Insert>More Controls> and select Microsoft Web Browswer

<br />
Private Sub Worksheet_Activate()<br />
WebBrowser1.Navigate "http://www.chandoo.org"<br />
End Sub<br />
[/pre]

With this I can upload an html page I created with flash button links, and what I would like to do is execute sub


macro codes from those links.
 

indi visual

New Member
I've been at this for days. My imagination gets the best of me. If anyone could simply just let me know if this is even possible it would put me out of my misery.
 

Hui

Excel Ninja
Staff member
I would suggest just putting the links and buttons etc directly onto the worksheet.

That way they are all usable and can all call macros or direcyly link to other areas sheets, ranges, macros etc
 

keymaster

New Member
I just inserted a web browser object in to a work sheet to see what events it supports.


After you add the object, right click on it and select view code.


Here you can add events for the browser. For example an event macro like "titlechange" will fire whenever underlying page's title changes (ie, when you click on a url, if the target page has diff. title than existing pages title, excel will run the code inside this macro.)


You can use this to do what you are looking for.


But the best and easiest way is to use buttons and links directly on excel. It is much more simple and easier that way.
 

indi visual

New Member
Thanks I really appreciate this.


Is their a reference resource article or something to that effect for the event macros (like "titlechange")? I mean, as far as the event codes, I just would like to name my flash buttons what they do (like highlight entire row, or sort column from Z to A) for instance -simple buttons like that.


I'm sure I can just pop a sort column code in the web browser section of view code.. but what and where does the extra code go that tells the browser to run this code I guess is what I'm trying to say.


Of course regular buttons are easier, but I got into this excel VB game to do the extraordinary.
 

indi visual

New Member
It just dawned on me that if you could provide me the "titlechange" code in it's true working form, then I could use that to do everything that I'm trying to do.


Quite simply, if the title changes then run my macro.


The title would change to another title (I would reroute it back to itself), and the macro would run (which would be the macro I assigned it to be).


When you played with the browser a bit ago did you still use this title change coding successfully, and is there anyway you could provide it for me here?
 

indi visual

New Member
@ Key Master,


Is there anyway you could provide the "titlechange" event code for me?


I've been at this non-stop for days to no avail.


I've tried countless forums and countless syntax combinations to try to make this work.


Quite simply I don't know what I'm doing at all. I'm afraid I just need the code to see the picture.


If you don't want to provide it for me of course you don't have to (no hard feelings), but without your help I am completely in the dark.
 

Hui

Excel Ninja
Staff member
Indi


I still encourage you to do this natively in Excel with Objects and Hyperlinks rather than adding a Web Browser Object, as a lot of what you are trying to achieve can be done without any code.


However the object of this forum is to help and assist so here goes...


Right click on your browser and View Code

In the VBA window, select Web Browser1 in the Object Pulldown (Left Pulldown Main window pane) and then select Title Change in teh Procedure Pulldown (Right Pulldown Main window pane)


You will get the following code

[pre]
Code:
Private Sub WebBrowser1_TitleChange(ByVal Text As String)

End Sub

Code away eg:

Private Sub WebBrowser1_TitleChange(ByVal Text As String)
MsgBox WebBrowser1.LocationURL
End Sub
[/pre]
 

indi visual

New Member
Your code works fine, and thanks a lot Hui.


Now finally, all I need now is something along the lines of this underneath...


Private Sub WebBrowser1_TitleChange(ByVal Text As String)


If WebBrowser1 = "http://www.chandoo.org" Then

MsgBox WebBrowser1.LocationURL

If Not Then Go To Next


If WebBrowser2 = "http://www.google.com" Then

MsgBox WebBrowser2.LocationURL

If Not Then Go To Next


End Sub


Is this possible Hui?
 

indi visual

New Member
Okay never mind the above post.


I didn't realize that multiples private subs_title_changes for multiple web browsers could work independently without all going off at the same time.


However,


They do all go when the page is first opened.


So my finally question to get this entire thing solved...


How do I disable the web browsers from all going off at the same time when the excel file is first opened?
 

Hui

Excel Ninja
Staff member
Indi


I would strongly recomend against using a web browser within excel as an interface, This will be very difficult to maintain, will have inherent security issues and I think will be more trouble than it is worth in developing.


Excel has a good collection of tools for development of interfaces to nearly anything


You can use inbuilt buttons, custom buttons/shapes and have macros or links connected to them. A lot of the management can be done without code, as it is inbuilt within the tools.

You can lock the tools down so that they cannot be moved edited etc.


I would refer you to the spreadsheets at http://chandoo.org/wp/2010/07/16/download-expense-trackers/

These are great example of what can be done with minimal work within Excel

Specifically Option 1 by Bigtaff.
 
Top