【问题标题】:VBA code in spreadsheet not allowing multiple user access in excel电子表格中的 VBA 代码不允许 Excel 中的多个用户访问
【发布时间】:2010-07-22 08:17:07
【问题描述】:

我有一个电子表格,一个部门会将样本扫描到其中,当它被扫描(发送)时,它会在旁边的列中添加时间和日期戳。然后下一个部门将样本扫描到另一列,并在扫描(接收)时标记时间和日期。我使用的代码如下,但由于保护,我不能让两个人同时编辑电子表格。有什么我可以做的吗?

Private Sub Worksheet_Change(ByVal Target As Range)

ActiveSheet.Protect ("Password"), UserInterfaceOnly:=True

'Only write a timestamp of an odd column changes (because the timestamps go in the even columns)
If Target.Column Mod 2 > 0 Then

    'Get the first part of the address, to get the actual column being changed
    Dim columnAddress As String
    columnAddress = Target.Address

    If InStr(columnAddress, ":") > 0 Then
        columnAddress = Left(columnAddress, InStr(columnAddress, ":") - 1)
    End If

        If Not ActiveSheet.Range(columnAddress).Formula = "" Then

        'Write the timestamp for the previous column
        ActiveSheet.Range(columnAddress).Offset(0, 1).Formula = Now

        Else
            ActiveSheet.Range(columnAddress).Offset(0, 1).Formula = ""
        End If
End If

End Sub

【问题讨论】:

  • 为什么要使用电子表格来完成数据库工作?
  • 正在建立数据库,这是一个创可贴。

标签: excel vba


【解决方案1】:

我强烈建议您在此处使用 ADO。如果您走这条路,您将拥有一个远程 Excel 工作簿(或 .mdb,如果您愿意)作为您的数据库,并且“子”工作簿(或 Excel 加载项)会将相关数据写入此数据库,如果必填,也可以从中读取。

此处提供了 VBA 中 ADO 的良好概述:http://www.xtremevbtalk.com/showthread.php?t=217783

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2011-10-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-07-26
    • 1970-01-01
    • 2021-02-24
    • 1970-01-01
    相关资源
    最近更新 更多