Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

How do I call a VBA subroutine from Javascript

Posted on 2008-11-15
6
Medium Priority
?
444 Views
Last Modified: 2013-12-08
I have  a PowerPoint VBA add-in that includes a webbrowser control.  In the webbrowser document there is a Javascript function that, when called, should pass information to a subroutine in the VBA.  How can this be done?
0
Comment
Question by:StarDusterII
  • 2
  • 2
5 Comments
 
LVL 21

Accepted Solution

by:
GlennaShaw earned 500 total points
ID: 22971845
0
 
LVL 7

Assisted Solution

by:hippohood
hippohood earned 500 total points
ID: 23011420
You should use the COMAddIns collection (check 'COMAddIn Object' in VBA Help). Create an object and tag it to the COM object as in the code below. Now use appropriate Properties and Methods to return information from it.
Example (from the VBA Help)
The following example returns the object associated with the COM add-in 'msodraa9.ShapeSelect.'

Dim objBaseObject As Object
Set objBaseObject = _
    Application.COMAddIns.Item("msodraa9.ShapeSelect").Object

Open in new window

0
 

Author Comment

by:StarDusterII
ID: 23020465
But the question would be, how do you access that object from the Javascript function?
0
 
LVL 7

Expert Comment

by:hippohood
ID: 23040372
Not sure if I understood the problem. It would look something like below
When you start Powerpoint application from your script you, probably, do something like below
var thePPApp = new ActiveXObject("Powerpoint.Application");
Then you should be able to use the reference to this object to access any functionality of Powerpoint (switch on the Powerpoint library while coding), which would include objects and their properties and methods.
e.g. thePPapp.Presentations(1).Run
To access VBA project items (like forms) use VBProject object
If it does not work for your browser then you may use a VBScript, which can be called from Javascript and certainly can manipulate VBA routines.
0
 

Author Comment

by:StarDusterII
ID: 23041431
You're almost there... I created the Javascript in a webbrowser control on a user form.  In the Javascript I have:

var thePPApp = new ActiveXObject("Powerpoint.Application");
thePPApp.Run("addQuestion",questionID)

My problem was that I had the addQuestion subroutine in the user for and not the module.  Apparently it must be in a module and not a class or user form.  You pass data (ie questionID) with as many parameters as you need in the thePPApp.Run statement.

Thanks for the update.
0

Featured Post

[Webinar] Database Backup and Recovery

Does your company store data on premises, off site, in the cloud, or a combination of these? If you answered “yes”, you need a data backup recovery plan that fits each and every platform. Watch now as as Percona teaches us how to build agile data backup recovery plan.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Several part series to implement Internet Explorer 11 Enterprise Mode
Following on from our article on "The Murky World of Consent and opt in", we thought we would issue some helpful guidance, not only on consent itself but knowing what information you are capturing, what you are doing with this data and how you can p…
This video teaches viewers how to create handouts from their slides and helps them decide how many slides to include per handout.
This Micro Tutorial will demonstrate how to add subdomains to your content reports. This can be very importing in having a site with multiple subdomains.

581 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question