Skip to content
This repository has been archived by the owner on Dec 13, 2020. It is now read-only.

Excel VBA stopwatch class to measure elapsed time in seconds and milliseconds

License

Notifications You must be signed in to change notification settings

hubisan/excel-vba-stopwatch.cls

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Stopwatch to measure elapsed time in milliseconds or seconds

Excel VBA class to Start a timer and get the elapsed time in milliseconds or seconds.

Installation

  • Download the workbook: You can download stopwatch.xlsm. This workbook inlcudes the class and a module with two examples on how to use the class.
  • Or copy the code: Copy the class code starting at line 10 #If VBA7 from raw and paste into a new class in your workbook.
  • Or get the repository: Clone or download the repository and import the file stopwatch.cls into your workbook to use the class.

Usage

Methods and properties:

  • .start: start or restart the timer
  • .Elapsed_ms: get the elapsed time in milliseconds (like 1004) As Double
  • .Elapsed_sec(Optional number_of_digits_after_decimal As Integer = 3): get the elapsed time in seconds as Double.
    You can round to a number of digits after the decimal by providing the optional parameter, the default is 3 = millliseconds.
  • .stop_it: stops the timer, rarely using this myself.

Example usage:

Sub example()
    Dim x As New Stopwatch
    x.start
    'do your stuff here
    'in ms. Output: 1004
    Debug.Print x.Elapsed_ms
    'in seconds rounded to 3 digits after decimal. Output: 1.004
    Debug.Print x.Elapsed_sec
    'in seconds rounded to 0 digits after decimal. Output: 1
    Debug.Print x.Elapsed_sec(0)
End Sub

Remark for the workbook

The class module gets automatically exported when saving the Excel file. To stop this behavior change the constant in the module "autoopen" to "False":

Private Const is_in_development As Boolean = False

Contributing

If you find a bug, please create a new issue. Pull requests are also welcome.

Contributors

License

Copyright (c) 2016 Daniel Hubmann. Licensed under MIT.

About

Excel VBA stopwatch class to measure elapsed time in seconds and milliseconds

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published