Skip to content

VBA Profiler

Sergey Frolov edited this page Jan 6, 2024 · 2 revisions

VBA framework that allows you to monitor the runtime of your project's procedures with logging to txt/csv files, Excel range, VBA Immediate window or JSON file.

Framework consists of:

CProfiler.cls VBA profiler object for monitoring VBA code productivity
MProfiler.bas "Sugar" wrappers for VBA profiler object
COmniLogger.cls OmniLogger object for logging events from VBA code
CJSONWriter.cls Class to create JSON files
MSupport.bas functions from Excel helpers snippets, which necessary for VBA Profiler framework

VBA Profiler object (see CProfiler.cls) contains next key methods:

Public methods of VBA Profiler

How to test examples:

  1. Press ALT+F11 to open VBA IDE
  2. Go to MTests.bas
  3. Run procedure testProfilerAndReportTypes() to see how it works (comment/uncomment necessary log stream init procedure before run)
    IMPORTANT! Do not forget to create 'logs' folder near vba-profiler.xlsm to avoid errors related to files creation into this folder

How to use VBA Profiler framework in project:

Just copy five modules: CProfiler.cls, MProfiler.bas, COmniLogger.cls, CJSONWriter.cls and MSupport.bas to your project and you can start to measure your code productivity.

Typical code optimization workflow using VBA Profiler:

code optimization workflow using VBA Profiler

Report types samples:

toRange:
report to Range

toJSON:
report to JSON

toTXT:
report to TXT

toCSV:
report to CSV

toDebug (parameter inTabularForm = False):
report to Debug

toDebug (parameter inTabularForm = True):
report to Debug in tabular format

Clone this wiki locally