我已经向许多Excel文件(下面的VBA代码)添加了使用情况日志跟踪功能。这些当前显示哪些用户打开了特定文件以及何时打开它们。但是,我正在尝试收集其他信息。具体来说,我正在寻找一种记录用户导航到的选项卡的方式(除了他们打开文件的事实之外)。这样做的主要目的是消除因在不定期引用的标签上创建展览而产生的工作。
这是我当前用于创建通用用法日志以查看谁打开文件(以及何时打开)的代码;
Private Sub Workbook_Open()
Open ThisWorkbook.Path & "\Usage.log" For Append As #2
Print #2, Application.UserName, Now
Close #2
End Sub
答案 0 :(得分:1)
ThisWorkbook代码表中的这组子过程应涵盖大多数情况。
Option Explicit
Private Sub Workbook_Open()
Open ThisWorkbook.Path & "\Usage.log" For Append As #2
Print #2, Application.UserName, Now & " open"
Print #2, Application.UserName, Now, ActiveSheet.Name & " activate"
Close #2
End Sub
Private Sub Workbook_BeforeClose(Cancel As Boolean)
Open ThisWorkbook.Path & "\Usage.log" For Append As #2
Print #2, Application.UserName, Now & " close"
Close #2
End Sub
Private Sub Workbook_SheetActivate(ByVal Sh As Object)
Open ThisWorkbook.Path & "\Usage.log" For Append As #2
Print #2, Application.UserName, Now, Sh.Name & " activate"
Close #2
End Sub
Private Sub Workbook_SheetDeactivate(ByVal Sh As Object)
Open ThisWorkbook.Path & "\Usage.log" For Append As #2
Print #2, Application.UserName, Now, Sh.Name & " deactivate"
Close #2
End Sub