vba - 在 Excel 中跟踪 Share-drive 用户名和打开时间?

标签 vba excel macros

我发现了一篇关于我的问题的类似文章,如下所述;

How do I track who uses my Excel spreadsheet?

但是,我确实喜欢评论的最后一栏>>
“您还可以在下一列中添加时间戳,以显示使用电子表格的时间”

我的问题是>任何人都可以指导我可能的步骤或让我复制代码来执行此操作吗?以及如何在没有人注意的情况下隐藏工作表?
我的关键是,非常重要的是,所有事情都必须默默地完成,其他人(sharedrive 中的其他用户)无法发现我正在跟踪它。原因是,我做了很多研究工作表,我没有时间/不可能使每一个 Excel 工作表都完美,我需要优先考虑它们,以便通过知道哪个对人们更重要来有效利用我的时间.

非常感谢~!!

最佳答案

在 Excel 中,在“审阅”选项卡下,您有“跟踪更改”。这应该做你想做的一切。

如果您希望 VBA 脚本执行此操作,请尝试以下代码示例之一。

Private Sub Worksheet_Change(ByVal Target As Range)
Set t = Target
Set a = Range("A:A")
If Intersect(t, a) Is Nothing Then Exit Sub
Application.EnableEvents = False
t.Offset(0, 7).Value = Environ("username")
Application.EnableEvents = True
End Sub


Private Sub Worksheet_Change(ByVal Target As Excel.Range)
Dim V As Long
Application.EnableEvents = False

Set rng1 = Application.Union(Range("a1:g1"), Range("H:iv"))
Set rng = Application.Intersect(Target, rng1)
If Not rng Is Nothing Then Exit Sub

V = Target.Offset(0, 12).Value
If Target.Offset(0, 12) = "" Then
    With Range("H" & Target.Row)
       .Value = Target.Address & ": first entry by " & Application.UserName & " at " & Now()
       .ColumnWidth = 60
       .Interior.ColorIndex = 33
    End With
    Target.Offset(0, 12).Value = Target.Value
    Application.EnableEvents = True
    Exit Sub
End If
Target.Offset(0, 12).Value = Target.Value
With Range("H" & Target.Row)
  .Value = Target.Address & " changed from " & V & " to " & Target.Value & " by " & Application.UserName & " at " & Now()
   .ColumnWidth = 60
  .Interior.Color = vbYellow
End With
Application.EnableEvents = True
End Sub


Private Sub Worksheet_Change(ByVal Target As Excel.Range)
        With Target
            If .Count > 1 Then Exit Sub
            If Not Intersect(Range("A2:A10"), .Cells) Is Nothing Then
                Application.EnableEvents = False
                Sheets("Sheet2").Select
                If IsEmpty(.Value) Then
                    .Offset(0, 1).ClearContents
                Else
                    With .Offset(0, 1)
                        .NumberFormat = "dd mmm yyyy hh:mm:ss"
                        .Value = Now
                    End With
                End If
                Sheets("Sheet1").Select
                Application.EnableEvents = True
            End If
        End With
End Sub

所有这些“Worksheet_Change”脚本都是工作表事件。您需要右键单击工作表并单击“查看代码”,然后将脚本粘贴到打开的窗口中。一次尝试一个,而不是三个一起尝试。

关于vba - 在 Excel 中跟踪 Share-drive 用户名和打开时间?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37559370/

相关文章:

vba - excel不刷新所有数据透视表

vba - Excel VBA - 我的 VBA 代码搞砸了 : why the spanish characters (á, é,í,ó,ú,ñ,¡,¿) 突变?

sql-server - Excel ODBC 连接速度极慢

vba - 对任务栏中打开的所有文件一一运行宏

c++ - 如何#define C++ STL宏

sql - 获取列名

excel - 如何向现有工作表添加新列并为其命名?

java - 在 Excel 工作表中使用 JAVA 永久删除空行 Apache POI

c - 如何在不修改头文件的情况下取消应用程序代码中的宏定义?

c++ - #define myptr int * 有什么问题?