iT邦幫忙

0

excel 執行時間

wsj 2020-06-15 14:59:24907 瀏覽

各位大大,
我有一個VBA程式,內部有幾個sub,當所有sub執行完畢,立即跳出小視窗並顯示所花費時間?時間格式為"時";"分";"秒",謝謝!
Sub A()
....
....
End Sub
Sub B()
....
....
End Sub
Sub C()
....
....
End Sub

2 個回答

2
paicheng0111
iT邦高手 1 級 ‧ 2020-06-15 15:29:57
最佳解答
Sub Main()
    Dim start As Date

    start = now()
    Call A
    Call B
    Call C
    Msgbox Format(now - start, "HH:mm:ss")
End Sub
看更多先前的回應...收起先前的回應...

自慚形穢/images/emoticon/emoticon17.gif

只是踩過的坑比較多而已

wsj iT邦新手 5 級 ‧ 2020-06-15 16:39:21 檢舉

請問大大,可置入我的VBA程式中甚麼地方?

可以寫在

Sub C()
    ...
End Sub

之下

0
listennn08
iT邦高手 7 級 ‧ 2020-06-15 15:27:00
Sub main()
    Dim ds As Date, de As Date

    ds = TimeValue(Now)
    Call sub1
    Call sub2
    de = TimeValue(Now)
    
    Dim dif As Double, hh As Integer, mm As Integer, ss As Integer
    dif = DateDiff("s", ds, de)
    ss = dif Mod 60
    dif = dif / 60
    mm = dif Mod 60
    dif = dif / 60
    hh = dif
    
    MsgBox (CStr(hh) + "時" + CStr(mm) + "分" + CStr(ss) + "秒")
    
End Sub

我要發表回答

立即登入回答