1. Home
  2. Docs
  3. Azure Application Insights for VBA
  4. Getting Started
  5. How to Setup your Excel workbook (VBA)

How to Setup your Excel workbook (VBA)

You can follow the instructions in video format, or scroll down to follow the instructions in a detailed step-by-step text article.

Video: Prepare Excel Workbook – Azure Application Insights for VBA – Step 03

We need to send the data to Microsoft Azure – Application insights resource that we have created in previous step.

If you want to see how to create a free Microsoft Azure account and create our first Application Insights resource click here. 

In this article we will go step-by-step on how to setup our Excel workbook to send the data to the Azure Application Insights resource with just 3 lines of VBA code:

  1. Open your Excel workbook and make sure that you save it as the “Excel Macro-Enabled Workbook (*.xlsm)”
  2. Click on the “Developer” tab
  3. And then click on “Visual Basic”
  4. If you didn’t download the clsAI class module, go to https://www.vbatelemetry.com/downloads-azure-application-insights/ and download this clsAI.cls class module
  5. In VBA editor click on File > Import File and import this clsAI.cls from the destination where you have downloaded it on your machine.
  6. Click on Save button to save the changes
  7. Let’s test it by adding 3 lines of VBA code in Workbook open Event
  8. In the VBA Editor double-click on “ThisWorkbook”
  9. Paste this code into the VBA code editor window:
Private Sub Workbook_Open() 
   Dim clsAI1 As New clsAI 
   clsAI1.InstrumentationKey = "MyKey" 
   clsAI1.TrackPageView "Workbook Open" 
End Sub

10. Change the “MyKey” with the Instrumentation Key from the Azure Application Insights resource.
11. Now your code should look something like this (put your Instrumentation Key):

Private Sub Workbook_Open() 
   Dim clsAI1 As New clsAI 
   clsAI1.InstrumentationKey = "q49acd70-d043-4925-89dc-8b0ecb4db4bb" 
   clsAI1.TrackPageView "Workbook Open" 
End Sub

12. Click save, to save the changes
13. Close and reopen the Excel Workbook

14. Go to your Application Insights resource in Microsoft Azure and on the left sidebar, scroll down and click on Users, or Sessions, or Events, or User Flows and in a few seconds or maximum in a few minutes you should see your “Workbook Open” event

Was this article helpful to you? Yes No

How can we help?

Leave A Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.