gpt4 book ai didi

excel - 防止打开保存在特定位置的 Excel 工作簿

转载 作者:行者123 更新时间:2023-12-04 20:30:08 25 4
gpt4 key购买 nike

如果从保存工作簿的位置打开工作簿,我试图阻止授权用户以外的用户打开工作簿。我想要的是用户将工作簿复制到另一个位置然后打开它。我已将下面的代码用于 Access 数据库,但我不确定如何将其用于 Excel。有人可以帮忙吗?

Option Compare Database
Private Function AutoExec()
' Use Macro to run code and use the AutoExec() name
If VBA.InStr(1, CurrentDb.Name, "G:\") _
Or VBA.InStr(1, CurrentDb.Name, "\\NetWorkLocation\") Then

Select Case VBA.StrConv(VBA.Environ("username"), vbLowerCase)
Case "username1", "username2", "username3"

Case Else
VBA.MsgBox "Copy and paste this database to your desktop." _
& vbCrLf & "You may not open it from this location."
DoCmd.CloseDatabase
End Select

End If

End Function

最佳答案

如果你把它放到 ThisWorkbook module of the workbook你想限制 Access ,它应该工作。

Private Sub Workbook_Open()

If InStr(ThisWorkbook.path, "G:\") > 0 _
Or InStr(ThisWorkbook.path, "\\NetWorkLocation\") > 0 Then

Select Case LCase(Environ("username"))
Case "username1", "username2", "username3"

Case Else
MsgBox "Copy and paste this spreadsheet to your desktop." & _
vbCrLf & "You may not open it from this location."

ThisWorkbook.Close savechanges:=False
End Select

End If

End Sub

关于excel - 防止打开保存在特定位置的 Excel 工作簿,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52281753/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com