How do I call a VBA subroutine from Javascript

Posted on 2008-11-15
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
    LVL 21

    Accepted Solution

    LVL 7

    Assisted Solution

    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

    But the question would be, how do you access that object from the Javascript function?
    LVL 7

    Expert Comment

    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

    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.

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Top 6 Sources for Identifying Threat Actor TTPs

    Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

    Citrix XenApp, Internet Explorer 11 set to Enterprise Mode and using central hosted sites.xml file.
    Today, still in the boom of Apple, PC's and products, nearly 50% of the computer users use Windows as graphical operating systems. If you are among those users who love windows, but are grappling to keep the system's hard drive optimized, then you s…
    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.
    How to create a custom search shortcut to site-search Experts Exchange using Google in the Firefox browser. This eliminates the need to type out whenever you want to search the site. Launch your Bookmark Menu: Press 'Ctrl +…

    761 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

    Need Help in Real-Time?

    Connect with top rated Experts

    9 Experts available now in Live!

    Get 1:1 Help Now