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.
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:
- Open your Excel workbook and make sure that you save it as the “Excel Macro-Enabled Workbook (*.xlsm)”
- Click on the “Developer” tab
- And then click on “Visual Basic”
- If you didn’t download the clsAI class module, go to https://vbatelemetry.com/downloads-azure-application-insights/ and download this clsAI.cls class module
- In VBA editor click on File > Import File and import this clsAI.cls from the destination where you have downloaded it on your machine.
- Click on Save button to save the changes
- Let’s test it by adding 3 lines of VBA code in Workbook open Event
- In the VBA Editor double-click on “ThisWorkbook”
- 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