PC Review


Reply
Thread Tools Rate Thread

How do I call a VBA subroutine from Javascript?

 
 
SteveR
Guest
Posts: n/a
 
      18th Nov 2008
I have a VBA form in a PowerPoint add-in that includes a webbrowser control.
In the webbrowser document I've written a Javascript function that, when
called, should pass information to a subroutine in the VBA. How can this be
done?

Thanks,

Steve

 
Reply With Quote
 
 
 
 
Chirag
Guest
Posts: n/a
 
      19th Nov 2008
From your Javascript code, you can call VBA macro using something like the
following snippet:

<SCRIPT Language = "JScript">
function CallVBA(VBAMacroName)
{
var App;

App = new ActiveXObject("PowerPoint.Application");
App.Run(VBAMacroName);
}
CallVBA("YourVBAMacroNameHere");
</SCRIPT>

- Chirag

PowerShow - View multiple PowerPoint slide shows simultaneously
http://officeone.mvps.org/powershow/powershow.html

"SteveR" <(E-Mail Removed)> wrote in message
news:E25E77B2-34CD-4AD7-9527-(E-Mail Removed)...
>I have a VBA form in a PowerPoint add-in that includes a webbrowser
>control.
> In the webbrowser document I've written a Javascript function that, when
> called, should pass information to a subroutine in the VBA. How can this
> be
> done?
>
> Thanks,
>
> Steve


 
Reply With Quote
 
SteveR
Guest
Posts: n/a
 
      20th Nov 2008
Thanks for your reply.

That works for calling a "Macro" but I'd like to call a subroutine within
the macro that's currently running. I create the content of the webbrowser
control (including the javascript) with the macro. Then on a specific
javascript event, I'd like to call a subroutine in the that macro.

Is that possible?

sr

"Chirag" wrote:

> From your Javascript code, you can call VBA macro using something like the
> following snippet:
>
> <SCRIPT Language = "JScript">
> function CallVBA(VBAMacroName)
> {
> var App;
>
> App = new ActiveXObject("PowerPoint.Application");
> App.Run(VBAMacroName);
> }
> CallVBA("YourVBAMacroNameHere");
> </SCRIPT>
>
> - Chirag
>
> PowerShow - View multiple PowerPoint slide shows simultaneously
> http://officeone.mvps.org/powershow/powershow.html
>
> "SteveR" <(E-Mail Removed)> wrote in message
> news:E25E77B2-34CD-4AD7-9527-(E-Mail Removed)...
> >I have a VBA form in a PowerPoint add-in that includes a webbrowser
> >control.
> > In the webbrowser document I've written a Javascript function that, when
> > called, should pass information to a subroutine in the VBA. How can this
> > be
> > done?
> >
> > Thanks,
> >
> > Steve

>
>

 
Reply With Quote
 
SteveR
Guest
Posts: n/a
 
      22nd Nov 2008
Ok, I tried calling a public sub in my VBA application and I'm getting an
error: "Application.Run: Invalid request, Sub of function not defined."

I tried using App.Run("addQuestion") and
App.Run("addQuestion()") but same error...

function changeIcon() {
App = new ActiveXObject("PowerPoint.Application");
App.Run("addQuestion()");
....

in VBA

public sub addQuestion()
call msgbox("here")
end sub

"Steve Rindsberg" wrote:

>
> > That works for calling a "Macro" but I'd like to call a subroutine within
> > the macro that's currently running.

>
> In VBA, a "macro" *is* a subroutine. The "VBAMacroName" Chirag referred to is
> the name of a subroutine. You may be confusing the name of the macro/subroutine
> with the name of the module that contains it.
>
>
> > I create the content of the webbrowser
> > control (including the javascript) with the macro. Then on a specific
> > javascript event, I'd like to call a subroutine in the that macro.
> >
> > Is that possible?
> >
> > sr
> >
> > "Chirag" wrote:
> >
> > > From your Javascript code, you can call VBA macro using something like the
> > > following snippet:
> > >
> > > <SCRIPT Language = "JScript">
> > > function CallVBA(VBAMacroName)
> > > {
> > > var App;
> > >
> > > App = new ActiveXObject("PowerPoint.Application");
> > > App.Run(VBAMacroName);
> > > }
> > > CallVBA("YourVBAMacroNameHere");
> > > </SCRIPT>
> > >
> > > - Chirag
> > >
> > > PowerShow - View multiple PowerPoint slide shows simultaneously
> > > http://officeone.mvps.org/powershow/powershow.html
> > >
> > > "SteveR" <(E-Mail Removed)> wrote in message
> > > news:E25E77B2-34CD-4AD7-9527-(E-Mail Removed)...
> > > >I have a VBA form in a PowerPoint add-in that includes a webbrowser
> > > >control.
> > > > In the webbrowser document I've written a Javascript function that, when
> > > > called, should pass information to a subroutine in the VBA. How can this
> > > > be
> > > > done?
> > > >
> > > > Thanks,
> > > >
> > > > Steve
> > >
> > >

> >

>
> -----------------------------------------
> Steve Rindsberg, PPT MVP
> PPT FAQ: www.pptfaq.com
> PPTools: www.pptools.com
> ================================================
>
>
>

 
Reply With Quote
 
SteveR
Guest
Posts: n/a
 
      22nd Nov 2008
Steve, thanks again for the reply.

Maybe I wan't clear enough in my opening question. It is an add-in and
it's actually the add-in that creates the content of the webbrowser control
with the Javascript included in it. The add-in displays the userForm and
when the user changes a combobox in the webbrowser control, the combobox's
onChange function should call the subroutine in the add-in. So, the add-in
is definitely running when the Javascript is called.

sr

"Steve Rindsberg" wrote:

> In article <39ABF176-FF40-4BAB-BDEA-(E-Mail Removed)>, SteveR wrote:
> > Ok, I tried calling a public sub in my VBA application and I'm getting an
> > error: "Application.Run: Invalid request, Sub of function not defined."
> >
> > I tried using App.Run("addQuestion") and
> > App.Run("addQuestion()") but same error...
> >
> > function changeIcon() {
> > App = new ActiveXObject("PowerPoint.Application");
> > App.Run("addQuestion()");
> > ....
> >
> > in VBA
> >
> > public sub addQuestion()
> > call msgbox("here")
> > end sub

>
> Is the sub in an add-in or a presentation?
> Is the add-in or presentation already loaded when you run the javascript? It would
> need to be.
>
> >
> > "Steve Rindsberg" wrote:
> >
> > >
> > > > That works for calling a "Macro" but I'd like to call a subroutine within
> > > > the macro that's currently running.
> > >
> > > In VBA, a "macro" *is* a subroutine. The "VBAMacroName" Chirag referred to is
> > > the name of a subroutine. You may be confusing the name of the macro/subroutine
> > > with the name of the module that contains it.
> > >
> > >
> > > > I create the content of the webbrowser
> > > > control (including the javascript) with the macro. Then on a specific
> > > > javascript event, I'd like to call a subroutine in the that macro.
> > > >
> > > > Is that possible?
> > > >
> > > > sr
> > > >
> > > > "Chirag" wrote:
> > > >
> > > > > From your Javascript code, you can call VBA macro using something like the
> > > > > following snippet:
> > > > >
> > > > > <SCRIPT Language = "JScript">
> > > > > function CallVBA(VBAMacroName)
> > > > > {
> > > > > var App;
> > > > >
> > > > > App = new ActiveXObject("PowerPoint.Application");
> > > > > App.Run(VBAMacroName);
> > > > > }
> > > > > CallVBA("YourVBAMacroNameHere");
> > > > > </SCRIPT>
> > > > >
> > > > > - Chirag
> > > > >
> > > > > PowerShow - View multiple PowerPoint slide shows simultaneously
> > > > > http://officeone.mvps.org/powershow/powershow.html
> > > > >
> > > > > "SteveR" <(E-Mail Removed)> wrote in message
> > > > > news:E25E77B2-34CD-4AD7-9527-(E-Mail Removed)...
> > > > > >I have a VBA form in a PowerPoint add-in that includes a webbrowser
> > > > > >control.
> > > > > > In the webbrowser document I've written a Javascript function that, when
> > > > > > called, should pass information to a subroutine in the VBA. How can this
> > > > > > be
> > > > > > done?
> > > > > >
> > > > > > Thanks,
> > > > > >
> > > > > > Steve
> > > > >
> > > > >
> > > >
> > >
> > > -----------------------------------------
> > > Steve Rindsberg, PPT MVP
> > > PPT FAQ: www.pptfaq.com
> > > PPTools: www.pptools.com
> > > ================================================
> > >
> > >
> > >

> >

>
> -----------------------------------------
> Steve Rindsberg, PPT MVP
> PPT FAQ: www.pptfaq.com
> PPTools: www.pptools.com
> ================================================
>
>
>

 
Reply With Quote
 
Chirag
Guest
Posts: n/a
 
      23rd Nov 2008
In that case, you need to qualify the subroutine reference with the add-in
name. If the sub routine name is "addQuestion" and add-in name is "AddIn",
you would need to execute
App.Run("AddIn!addQuestion")
in your code instead of App.Run("addQuestion").

- Chirag

PowerShow - View multiple PowerPoint slide shows simultaneously
http://officeone.mvps.org/powershow/powershow.html

"SteveR" <(E-Mail Removed)> wrote in message
news:54EFEFE7-17E3-48AE-B4EE-(E-Mail Removed)...
> Steve, thanks again for the reply.
>
> Maybe I wan't clear enough in my opening question. It is an add-in and
> it's actually the add-in that creates the content of the webbrowser
> control
> with the Javascript included in it. The add-in displays the userForm and
> when the user changes a combobox in the webbrowser control, the combobox's
> onChange function should call the subroutine in the add-in. So, the
> add-in
> is definitely running when the Javascript is called.
>
> sr


 
Reply With Quote
 
SteveR
Guest
Posts: n/a
 
      23rd Nov 2008
Chirag, That made a lot of sense, but still the exact same error. With
CreateGuide being the name of the add-in, I'm using:

App.Run("CreateGuide!addQuestion") and tried
App.Run("CreateGuide!addQuestion()")

This is PPT 2007, and it feels like it's a completely different product from
everything before it. Could there be some syntax difference in 2007 that
have changed from everything else?

sr

"Chirag" wrote:

> In that case, you need to qualify the subroutine reference with the add-in
> name. If the sub routine name is "addQuestion" and add-in name is "AddIn",
> you would need to execute
> App.Run("AddIn!addQuestion")
> in your code instead of App.Run("addQuestion").
>
> - Chirag
>
> PowerShow - View multiple PowerPoint slide shows simultaneously
> http://officeone.mvps.org/powershow/powershow.html
>
> "SteveR" <(E-Mail Removed)> wrote in message
> news:54EFEFE7-17E3-48AE-B4EE-(E-Mail Removed)...
> > Steve, thanks again for the reply.
> >
> > Maybe I wan't clear enough in my opening question. It is an add-in and
> > it's actually the add-in that creates the content of the webbrowser
> > control
> > with the Javascript included in it. The add-in displays the userForm and
> > when the user changes a combobox in the webbrowser control, the combobox's
> > onChange function should call the subroutine in the add-in. So, the
> > add-in
> > is definitely running when the Javascript is called.
> >
> > sr

>
>

 
Reply With Quote
 
SteveR
Guest
Posts: n/a
 
      24th Nov 2008
Create the following file and put it in c:\temp.htm (or something)

<html>
<head>
<script>

function test() {
var App = new ActiveXObject('PowerPoint.Application')
App.Run("PPTupload!addQuestion()")
}
</script>
</head>
<body>
<input type="button" value="test" onclick="test()"
</body>
</html>

In the add-in called PPTupload create a subroutine called addQuestion:

public sub addQuestion()
call msgbox("here")
end sub

Add a webbrowser control to the user form and add
webrowser1.navigate2("file://c:\temp.htm")

When you click the button, you should see "here".

sr


"Steve Rindsberg" wrote:

> If you can supply some example HTML that includes the javascript chirag sent and
> a button to click to invoke it (I'm hopeless w/ javascript) I'd be happy to see
> if I can get it working with PPT.
>
> One thing to consider first: I'm pretty sure the add-in name it's looking for is
> the one that appears in the Add-ins dialog box in PPT. In 2007 that'd be found
> at the bottom of:
>
> Office Button | PowerPoint Options | Add-ins | Manage: PowerPoint Add-ins |
> Click Go
>
> In article <5CE6CBF2-2FF2-44CC-8CF6-(E-Mail Removed)>, SteveR wrote:
> > Chirag, That made a lot of sense, but still the exact same error. With
> > CreateGuide being the name of the add-in, I'm using:
> >
> > App.Run("CreateGuide!addQuestion") and tried
> > App.Run("CreateGuide!addQuestion()")
> >
> > This is PPT 2007, and it feels like it's a completely different product from
> > everything before it. Could there be some syntax difference in 2007 that
> > have changed from everything else?
> >
> > sr
> >
> > "Chirag" wrote:
> >
> > > In that case, you need to qualify the subroutine reference with the add-in
> > > name. If the sub routine name is "addQuestion" and add-in name is "AddIn",
> > > you would need to execute
> > > App.Run("AddIn!addQuestion")
> > > in your code instead of App.Run("addQuestion").
> > >
> > > - Chirag
> > >
> > > PowerShow - View multiple PowerPoint slide shows simultaneously
> > > http://officeone.mvps.org/powershow/powershow.html
> > >
> > > "SteveR" <(E-Mail Removed)> wrote in message
> > > news:54EFEFE7-17E3-48AE-B4EE-(E-Mail Removed)...
> > > > Steve, thanks again for the reply.
> > > >
> > > > Maybe I wan't clear enough in my opening question. It is an add-in and
> > > > it's actually the add-in that creates the content of the webbrowser
> > > > control
> > > > with the Javascript included in it. The add-in displays the userForm and
> > > > when the user changes a combobox in the webbrowser control, the combobox's
> > > > onChange function should call the subroutine in the add-in. So, the
> > > > add-in
> > > > is definitely running when the Javascript is called.
> > > >
> > > > sr
> > >
> > >

>
>
>
>

 
Reply With Quote
 
Chirag
Guest
Posts: n/a
 
      25th Nov 2008
Hi,

App.Run("PPTupload!addQuestion()")
should be
App.Run("PPTupload!addQuestion")

The subroutine addQuestion() should be in a standard module (and not a class
module or userform). Are you placing addQuestion() in a standard module?

- Chirag

PowerShow - View multiple PowerPoint slide shows simultaneously
http://officeone.mvps.org/powershow/powershow.html

"SteveR" <(E-Mail Removed)> wrote in message
news:BC0F7901-D6CB-47B7-A055-(E-Mail Removed)...
> Create the following file and put it in c:\temp.htm (or something)
>
> <html>
> <head>
> <script>
>
> function test() {
> var App = new ActiveXObject('PowerPoint.Application')
> App.Run("PPTupload!addQuestion()")
> }
> </script>
> </head>
> <body>
> <input type="button" value="test" onclick="test()"
> </body>
> </html>
>
> In the add-in called PPTupload create a subroutine called addQuestion:
>
> public sub addQuestion()
> call msgbox("here")
> end sub
>
> Add a webbrowser control to the user form and add
> webrowser1.navigate2("file://c:\temp.htm")
>
> When you click the button, you should see "here".
>
> sr
>
>
> "Steve Rindsberg" wrote:
>
>> If you can supply some example HTML that includes the javascript chirag
>> sent and
>> a button to click to invoke it (I'm hopeless w/ javascript) I'd be happy
>> to see
>> if I can get it working with PPT.
>>
>> One thing to consider first: I'm pretty sure the add-in name it's looking
>> for is
>> the one that appears in the Add-ins dialog box in PPT. In 2007 that'd be
>> found
>> at the bottom of:
>>
>> Office Button | PowerPoint Options | Add-ins | Manage: PowerPoint Add-ins
>> |
>> Click Go


 
Reply With Quote
 
SteveR
Guest
Posts: n/a
 
      25th Nov 2008
Very interesting. I had tried it with and without the () but I had the
subroutine in a userform. I put it in the module and it works fine.
Question though, if you can't use the (), how do you pass data from the
Javascript function to the subroutine? I can parse the
document.body.innerHTML but there must be a better way.

Thanks for your input, very helpful.

"Chirag" wrote:

> Hi,
>
> App.Run("PPTupload!addQuestion()")
> should be
> App.Run("PPTupload!addQuestion")
>
> The subroutine addQuestion() should be in a standard module (and not a class
> module or userform). Are you placing addQuestion() in a standard module?
>
> - Chirag
>
> PowerShow - View multiple PowerPoint slide shows simultaneously
> http://officeone.mvps.org/powershow/powershow.html
>
> "SteveR" <(E-Mail Removed)> wrote in message
> news:BC0F7901-D6CB-47B7-A055-(E-Mail Removed)...
> > Create the following file and put it in c:\temp.htm (or something)
> >
> > <html>
> > <head>
> > <script>
> >
> > function test() {
> > var App = new ActiveXObject('PowerPoint.Application')
> > App.Run("PPTupload!addQuestion()")
> > }
> > </script>
> > </head>
> > <body>
> > <input type="button" value="test" onclick="test()"
> > </body>
> > </html>
> >
> > In the add-in called PPTupload create a subroutine called addQuestion:
> >
> > public sub addQuestion()
> > call msgbox("here")
> > end sub
> >
> > Add a webbrowser control to the user form and add
> > webrowser1.navigate2("file://c:\temp.htm")
> >
> > When you click the button, you should see "here".
> >
> > sr
> >
> >
> > "Steve Rindsberg" wrote:
> >
> >> If you can supply some example HTML that includes the javascript chirag
> >> sent and
> >> a button to click to invoke it (I'm hopeless w/ javascript) I'd be happy
> >> to see
> >> if I can get it working with PPT.
> >>
> >> One thing to consider first: I'm pretty sure the add-in name it's looking
> >> for is
> >> the one that appears in the Add-ins dialog box in PPT. In 2007 that'd be
> >> found
> >> at the bottom of:
> >>
> >> Office Button | PowerPoint Options | Add-ins | Manage: PowerPoint Add-ins
> >> |
> >> Click Go

>

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

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 Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Call a subroutine using variable subroutine name dhstein Microsoft Excel Misc 3 26th Jul 2009 08:28 PM
How do I call a VBA subroutine from Javascript SteveR Microsoft Outlook VBA Programming 4 18th Nov 2008 08:18 PM
Can't call a subroutine donwb Microsoft Excel Programming 3 6th Aug 2008 05:05 AM
Calling ASP.NET server side subroutine from javascript asadikhan Microsoft ASP .NET 2 25th Apr 2004 08:51 AM
Call asp.net subroutine from javascript Christophe Microsoft ASP .NET 1 25th Mar 2004 09:02 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 05:16 AM.