TrackError Simple Sample.xlsm

/TrackError Simple Sample.xlsm

TrackError Simple Sample.xlsm

Version 1
Download 1433
Total Views 1784
File Size 1.23 MB
File Type zip
Create Date 07/25/2017
Last Updated 09/08/2017
Please login to download

In this simple Excel Workbook you can see how to use the TrackError function with VBA Telemetry Client to send tracking data about your errors from your Excel Workbook within VBA to Microsoft Azure - Application Insights.

Before you can use this Sample you need to:

1. Install the "VBA Telemetry Client" (VBATelemetrySetup.msi) it is in the zip file you have downloaded
2. Create a FREE Azure account (if you already don't have one)
3. Create new Application Insights resource in your Azure Portal
4. Copy and Paste the "Instrumentation Key" from your Azure Application Insights resource into this VBA project (modVBATelemetryVariables >>> m_InstrumentationKey) (to connect your workbook with your resource in Azure)

Detailed steps how to do this can be found in our Documentation section on our webpage

What does this sample do:

Watch this short (50sec) video on how this sample works:

When we click on the Button the error Division by zero is triggered.
In Error_Handler we have placed a line of code that calls a function TrackError and passes the parameters about the error to this function.
This function then sends the data about the error to our Application Insights resource.
We can see our error in Azure Portal - our Application Insights resource in tab Failures.

In this sample we have:

1. Inserted 1 ActiveX Command Button on Sheet1
2. Inserted few lines of VBA code into Sheet1 (To open the VBA Editor goto Developer > Visual Basic OR press Alt + F11)

Private Sub CommandButton1_Click()
Dim i As Integer

On Local Error GoTo Error_Handler

'trigger error division by zero
i = 1 / 0

Exit Sub

MsgBox Err.Description
'send the data about the error to Microsoft Azure - Application Insights
TrackError Err.Description, Err.Number, "CommandButton1_Click"

End Sub

In this sample we have inserted 1 line of VBA code into ThisWorkbook: (To open the VBA Editor goto Developer > Visual Basic OR press Alt + F11)

Private Sub Workbook_BeforeClose(Cancel As Boolean)

'before we exit, we need to Flush the data so that VBA Telemetry Client & Application Insights Client knows that it needs to send the rest of the data to the Azure

End Sub
2017-09-08T09:08:09+00:00 0 Comments

Leave A Comment

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