Preview:
#If VBA7 And Win64 Then
    'for 64-bit
    Private Declare PtrSafe Function QueryPerformanceCounter Lib "kernel32" (lpPerformanceCount As Currency) As Long
    Private Declare PtrSafe Function QueryPerformanceFrequency Lib "kernel32" (lpFrequency As Currency) As Long
#Else
    'for 32-bit
    Private Declare Function QueryPerformanceCounter Lib "kernel32" (lpPerformanceCount As Currency) As Long
    Private Declare Function QueryPerformanceFrequency Lib "kernel32" (lpFrequency As Currency) As Long
#End If

Private m_cCounterStart As Currency
Private m_cCounterEnd As Currency

'Initialize the Timer
Sub ProcessTimer_Start()
    Dim lResult         As Long
    
    lResult = QueryPerformanceCounter(m_cCounterStart)
End Sub

'Stop the Timer and calculate the elapsed time
Function ProcessTimer_End(Optional sOutputFormat As String = "ms") As Double
    Dim lResult         As Long
    Dim cFrequency      As Currency
    Dim dOutput         As Double
    
    lResult = QueryPerformanceCounter(m_cCounterEnd)
    lResult = QueryPerformanceFrequency(cFrequency)
    ProcessTimer_End = (m_cCounterEnd - m_cCounterStart) / cFrequency
End Function
downloadDownload PNG downloadDownload JPEG downloadDownload SVG

Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!

Click to optimize width for Twitter