Beruflich Dokumente
Kultur Dokumente
Williams)
Description: The Timer function has its limits in providing accurate measurement of VBA code
procedures. The MicroTimer procedure detailed below allows for a better
measure.
Discussion: Analyse the speed of different sections of code to determine where bottlenecks
exist and where improvements are required.
Option Explicit
'
'
Private Declare Function RegCloseKey Lib "advapi32.dll" (ByVal hKey As Long) As Long
Private Declare Function RegOpenKey Lib "advapi32.dll" Alias "RegOpenKeyA" (ByVal hKey As Long,
ByVal lpSubKey As String, phkResult As Long) As Long
Private Declare Function RegQueryValueEx Lib "advapi32.dll" Alias "RegQueryValueExA" (ByVal hKey
As Long, ByVal lpValueName As String, ByVal lpReserved As Long, lpType As Long, lpData As Any,
lpcbData As Long) As Long
'
'
'
MicroTimer = 0
End Function
'Calling macro
Sub Test()
Dim i As Long
Tim = MicroTimer
For i = 1 To 100000
DoEvents
Next
Tim = MicroTimer
For i = 1 To 1000
DoEvents
Next
MsgBox "100000" & vbTab & Int(Result1 * Factor) & vbCr & _
End Sub
Test the code: 1. In the attached example, click the Fill 1 and Fill 2 command buttons,
clearing between runs.