Logo

dev-resources.site

for different kinds of informations.

Calculate elapsed time in milliseconds in VBA

Published at
10/12/2024
Categories
vba
Author
0meow0
Categories
1 categories in total
vba
open
Author
6 person written this
0meow0
open
Calculate elapsed time in milliseconds in VBA

Calculate execution time in milliseconds

Public Declare PtrSafe Sub Sleep Lib "kernel32" (ByVal milliseconds As Long)

Sub CalculateElapsedTimeInMilliseconds()

    Dim startTime   As Double
    Dim endTime     As Double
    Dim elapsedTime As Double
    Dim message     As String

    startTime = Timer

    Call Sleep(1200) 'Wait 1.2 seconds

    endTime = Timer
    elapsedTime = endTime - startTime

    message = "Time " & elapsedTime & " seconds"

    Debug.Print message 'Time 1.2 seconds

End Sub
Enter fullscreen mode Exit fullscreen mode
Public Declare PtrSafe Sub Sleep Lib "kernel32" (ByVal milliseconds As Long)

Sub CalculateElapsedTimeInMilliseconds()

    Dim startTime   As Double
    Dim endTime     As Double
    Dim elapsedTime As Double
    Dim message     As String

    startTime = Timer

    Call Sleep(1200) 'Wait 1.2 seconds

    endTime = Timer
    elapsedTime = endTime - startTime

    message = "Time "
    message = message & Format(Int((elapsedTime) / 60 / 60), "00") & ":"            'Hour
    message = message & Format(Int((elapsedTime) / 60) Mod 60, "00") & ":"          'Minute
    message = message & Format(Int(elapsedTime) Mod 60, "00") & "."                 'Second
    message = message & Format(Int((elapsedTime - Int(elapsedTime)) * 1000), "000") 'Millisecond

    Debug.Print message 'Time 00:00:01.200

End Sub
Enter fullscreen mode Exit fullscreen mode

Calculate time difference in seconds

Public Declare PtrSafe Sub Sleep Lib "kernel32" (ByVal milliseconds As Long)

Sub CalculateElapsedTimeInSeconds()

    Dim startTime   As Date
    Dim endTime     As Date
    Dim elapsedTime As Date
    Dim message     As String

    startTime = Now

    Call Sleep(3000) 'Wait 3 seconds

    endTime = Now

    elapsedTime = endTime - startTime

    message = "Time " & Format(elapsedTime, "hh:mm:ss")

    Debug.Print message 'Time 00:00:03

End Sub
Enter fullscreen mode Exit fullscreen mode
vba Article's
30 articles in total
Favicon
mala direta usando o VBA, Excel e Word tudo juntos
Favicon
Custom Inventory Management System Using VBA: A Cost-Effective Solution for Small Businesses
Favicon
Import objects from another database in Access VBA
Favicon
Excel 基礎 Part 03 -- 作成したマクロ関数を開発タブから実行する
Favicon
Validate date format in VBA
Favicon
Connect MS Access to SQL Server using ADO
Favicon
Calculate elapsed time in milliseconds in VBA
Favicon
Word VBA 刪除所有圖形
Favicon
How to implement a Polar Area Chart using VBA
Favicon
Automating Excel with Power: Building Your Own Plugin using VBA
Favicon
Outputting data without using a loop
Favicon
How to do Excel table association – You are out if you know only VLOOKUP
Favicon
SPL XLL Practice: Almighty Text Splitting in Excel
Favicon
SPL XLL Practice: Excel Interval Association
Favicon
Excel Advanced Group and Summary Method
Favicon
How to Automatically Extract Eligible Rows in Excel
Favicon
Set operations of Excel inter row data (intersection, union, difference)
Favicon
Power Apps - VBA Subs and Functions
Favicon
Hello there ..im looking for help from someone who has knowledge about VbA
Favicon
How to Merge Excel Sheets Horizontally
Favicon
What Programming Language Should Business People Learn?
Favicon
Looking for Advanced Excel, VBA & Macros Course in Mumbai
Favicon
How to Save Multiple Excel Files into the Same Folder
Favicon
New 64-bit IDE for VB6 developers,Twinbasic VisualFreebasic
Favicon
Streamlining Your Work with Custom Excel Functions
Favicon
Separação de conteúdo em arquivos no Microsoft Excel
Favicon
在 VBA 中讀取 UTF8 編碼的文字檔
Favicon
VBA and Excel as an office GUI.
Favicon
Send an SMS Message From an Excel Spreadsheet
Favicon
在 Office VBA 使用 Open AI API

Featured ones: