我希望让这个宏不断记录当前活动程序的名称。我有一个用户窗体,它运行一个计时器用户宏,该宏每秒都会调用自己。我希望它在同一宏中记录活动窗口的名称,并将其附加到描述性字符串(如果与姓氏不同)。
我最初使用“Active window.caption”只是为了了解它不适用于其他程序(例如 chrome、word 或 Outlook),但下面是我的代码块。
If ActiveApp <> ActiveWindow.Caption Then 'look at active program for name
ActiveApp = ActiveWindow.Caption 'if the last name is not the same as the current
aapp2 = ThisWorkbook.Sheets("bts").Range("b13").Value & "|" & ActiveApp & ": " & Format(dteElapsed, "hh:mm:ss")
'updates the descriptive string
ThisWorkbook.Sheets("bts").Range("b13").Value = aapp2
End If
Run Code Online (Sandbox Code Playgroud)
整个宏:
Sub timeloop()
If ThisWorkbook.Sheets("BTS").Range("b7").Value = "" Then 'the location on theworksheet that time is stored
ThisWorkbook.Sheets("BTS").Range("b7").Value = Time '
ThisWorkbook.Sheets("BTS").Range("b12").Value = Date
End If
dteStart = …Run Code Online (Sandbox Code Playgroud)