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


How do I call a VBA subroutine from Javascript

Posted on 2008-11-15
Medium Priority
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?
Question by:StarDusterII
  • 2
  • 2
LVL 21

Accepted Solution

GlennaShaw earned 500 total points
ID: 22971845

Assisted Solution

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 = _

Open in new window


Author Comment

ID: 23020465
But the question would be, how do you access that object from the Javascript function?

Expert Comment

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.

Author Comment

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");

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.

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