Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming,microsoft.public.excel.misc,microsoft.public.vb.controls,microsoft.public.vb.controls.internet
|
|||
|
|||
Can I call an Excel VBA function from within a WebBrowser control?
I have an Excel workbook which can pop up a form that contains a
WebBrowser control. When the user clicks on a button in the web page that's being displayed in the control, I want a JavaScript function in the page to call one of the VBA functions in the workbook and pass it some arguments. Can anyone tell me whether this is possible, and if so how to do it? One reason I think it may be possible is that I already know how to call back to a VB.NET program from a .NET WebBrowser control, by using the control's ObjectForScripting property and calling window.external.whatever() in the JavaScript code. It's possible this is a new feature with .NET, but I am hoping there is some way to do the same thing from a VBA WebBrowser control, without .NET being involved. -- John Brock |
#2
Posted to microsoft.public.excel.programming
|
|||
|
|||
Can I call an Excel VBA function from within a WebBrowser control?
Wouldn't the parent of the web browser control be the workbook? -- joel ------------------------------------------------------------------------ joel's Profile: http://www.thecodecage.com/forumz/member.php?userid=229 View this thread: http://www.thecodecage.com/forumz/sh...d.php?t=145854 |
#3
Posted to microsoft.public.excel.programming
|
|||
|
|||
Can I call an Excel VBA function from within a WebBrowser control?
In article ,
joel wrote: Wouldn't the parent of the web browser control be the workbook? I guess so. But how do I get access to that parent in the JavaScript code? I found one link where someone claimed to be doing something like this (with PowerPoint): http://www.pcreview.co.uk/forums/thread-3675697.php But when I adapt for Excel the JavaScript function used in that link: function CallVBA(VBAMacroName) { var App; App = new ActiveXObject("Excel.Application"); App.Run(VBAMacroName); } what it does is open up a new instance of Excel, which doesn't help. I need the App variable to point to the already open instance of Excel that opened up the WebBrowser, but that's what I can't figure out. It may be that there is a very simple way to do this, and if so (or even if it's complicated!) I hope someone will enlighten me. -- John Brock |
#4
Posted to microsoft.public.excel.programming
|
|||
|
|||
Can I call an Excel VBA function from within a WebBrowser control?
I looked at the source code for you posting and found this onclick='javascript:this.parentNode.parentNode.sty le.display="none"; I believe if you displayed in Java "this.parentNode.Name" it would be the workbook name. If not then try the 2nd parent "this.parentNode.parentNode.Name" Once you find the workbook name then the application is what you need to run from App.Run(VBAMacroName); to this.parentNode.Application.Run(VBAMacroName); what also may work is this.Application.Run(VBAMacroName); I not an expert on Java and not sure how to test my theory. -- joel ------------------------------------------------------------------------ joel's Profile: http://www.thecodecage.com/forumz/member.php?userid=229 View this thread: http://www.thecodecage.com/forumz/sh...d.php?t=145854 |
#5
Posted to microsoft.public.excel.programming
|
|||
|
|||
Can I call an Excel VBA function from within a WebBrowser control?
Thanks for the suggestions, but unfortunately they just seem to
throw errors. Where did you get the "onclick=..." line??? It doesn't seem to be in the link I posted. In article , joel wrote: I looked at the source code for you posting and found this onclick='javascript:this.parentNode.parentNode.st yle.display="none"; I believe if you displayed in Java "this.parentNode.Name" it would be the workbook name. If not then try the 2nd parent "this.parentNode.parentNode.Name" Once you find the workbook name then the application is what you need to run from App.Run(VBAMacroName); to this.parentNode.Application.Run(VBAMacroName); what also may work is this.Application.Run(VBAMacroName); I not an expert on Java and not sure how to test my theory. -- joel ------------------------------------------------------------------------ joel's Profile: http://www.thecodecage.com/forumz/member.php?userid=229 View this thread: http://www.thecodecage.com/forumz/sh...d.php?t=145854 -- John Brock |
#6
Posted to microsoft.public.excel.programming
|
|||
|
|||
Can I call an Excel VBA function from within a WebBrowser control?
Debug the code by add messge boxes. You need to verify the I just went to the IE menu View - Source while responding to this email and searched for the word "THIS" Inot a java programmer and not familarr with th eobects in Java. Itried a few things using the IE Developer tools but didn't get very far -- joel ------------------------------------------------------------------------ joel's Profile: http://www.thecodecage.com/forumz/member.php?userid=229 View this thread: http://www.thecodecage.com/forumz/sh...d.php?t=145854 |
#7
Posted to microsoft.public.excel.programming
|
|||
|
|||
Can I call an Excel VBA function from within a WebBrowser control?
I've tried this without success in the past, but your question got me
searching again.... Here's a page explaining how to fire a method in VB from javascript in a hosted browser control: http://msdn.microsoft.com/en-us/libr...45(VS.85).aspx It's a bit complex, but easy enough to follow: you can just copy and paste the code from the link. One difference in VBA: you can't set the default member of a class via the Object browser in VBA, so use the method described he http://www.cpearson.com/excel/DefaultMember.aspx It involves exporting the class to a file, then editing and re-importing it. Worked for me when I tried in XL. I can send you my file if you're having problems. Tim timjwilliams at gmail dot com "John Brock" wrote in message ... Thanks for the suggestions, but unfortunately they just seem to throw errors. Where did you get the "onclick=..." line??? It doesn't seem to be in the link I posted. In article , joel wrote: I looked at the source code for you posting and found this onclick='javascript:this.parentNode.parentNode.s tyle.display="none"; I believe if you displayed in Java "this.parentNode.Name" it would be the workbook name. If not then try the 2nd parent "this.parentNode.parentNode.Name" Once you find the workbook name then the application is what you need to run from App.Run(VBAMacroName); to this.parentNode.Application.Run(VBAMacroName); what also may work is this.Application.Run(VBAMacroName); I not an expert on Java and not sure how to test my theory. -- joel ------------------------------------------------------------------------ joel's Profile: http://www.thecodecage.com/forumz/member.php?userid=229 View this thread: http://www.thecodecage.com/forumz/sh...d.php?t=145854 -- John Brock |
#8
Posted to microsoft.public.excel.programming
|
|||
|
|||
Can I call an Excel VBA function from within a WebBrowser control?
Tim : Just for curiosity sake. Can a Java Script inside the webpage get workbook application object that started the web application? -- joel ------------------------------------------------------------------------ joel's Profile: http://www.thecodecage.com/forumz/member.php?userid=229 View this thread: http://www.thecodecage.com/forumz/sh...d.php?t=145854 |
#9
Posted to microsoft.public.excel.programming
|
|||
|
|||
Can I call an Excel VBA function from within a WebBrowsercontrol?
Hi Joel,
I haven't tried it, but if it were possible it would be a pretty big security problem: once you have a reference to the Excel application object, you could use it to do all sorts of things... The links I posted show how to call a method in excel from the web page, but I'm not sure if there's any support for passing parameters or returning values or objects to the page. I'll check it out when I have some time. Tim On Oct 21, 3:17*am, joel wrote: Tim : Just for curiosity sake. *Can a Java Script inside the webpage get workbook application object that started the web application? -- joel ------------------------------------------------------------------------ joel's Profile:http://www.thecodecage.com/forumz/member.php?userid=229 View this thread:http://www.thecodecage.com/forumz/sh...d.php?t=145854 |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
Can I call an Excel VBA function from within a WebBrowser control? | Excel Discussion (Misc queries) | |||
Re Post - Please Help (Excel WebBrowser Control) | Excel Programming | |||
call a function on control click event | Excel Discussion (Misc queries) | |||
to call WebBrowser in a macro? | Excel Programming | |||
How to open an Excel worksheet in the webBrowser control | Excel Programming |