To perform custom operations with any Office365 technology, we make use of jQuery/JavaScript. In one of our client’s functionalities, we came across a need to call the jQuery method using VBA (Visual basic for applications) macro. VBA is a programming language that helps us in custom operations for various Microsoft Office tools. We have implemented it for project professional.

A SharePoint online page was loaded in project professional VBA form using a web browser control. On this SharePoint page, we have used Angular JS + jQuery to perform our custom operation. For displaying some data on the page, we need to fetch some data from project professionals onto our custom page. To do so, we need to call a jQuery method using VBA. As we have used Angular JS, we have to call the method of the controller class after that. I will share with you how we carry out this operation.

In order to call a jQuery method, we have to keep in mind that the web browser controller should be loaded completely else; while calling the method from VBA, it will not find the method and will throw an exception.

Let’s look at the code snippets to carry out the operations:

In VBA, we have to use the below code:

Here, we have to get the parent window object of the web browser control using code line frm1.WebBrowser1.Document.parentWindow. We call “ShowFilterData” a parametric function, a jQuery method on our custom page using code line currentWindow.execScript Code:=”ShowFilterData(‘” + selectedValues + “‘)”

As we have used Angular js so will be calling a method of our controller using the below code snippet from the method, which will be called from VBA
On the html page under the script tag, we have defined the method ShowFilterData that will be called from VBA. An id should be assigned to the div where we have attached our controller using the ng-controller directive. So, here we have given the id: ContId as below
GetData is a function that is defined under the controller.js. So, we have seen how we can easily call an angular js method using VBA. I hope you find it helpful!

Supriya Khamesra

Supriya is currently working as a Senior Consultant with Advaiya, and has more than 10 years of experience in applications development, and responsible for Enterprise Project Server and Project Online and BI solutions. Microsoft Certified Professional in EPM, Supriya has been working on multiple technologies/platforms like Azure, .Net,Office365,Project Server,Project Online,SSRS,CSOM,JSOM,Kendo UI,JavaScript, SQL Server among others.

Posted by Advaiya

    Let's connect to make technology work for you.





    Please tick the options most relevant to your business challenges
    Decision makingBusiness productivityCustomer experienceTechnology-led innovationDigital transformation


    [By using this form you agree with the storage and handling of your data by this website.]