我希望需要位于特定文件路径中的工作簿才能打开。我在 Excel 2010 中使用 VBA。
(项目/本工作簿代码: 标题:工作簿/打开)
Private Sub Workbook_Open
FilePath
'Runs file path check when workbook opened
End Sub
(项目/模块/模块1 header :(常规)文件路径)
Sub FilePath()
If ActiveWorkbook.Path = ("path address") Then
PathOk
Else
MsgBox ("This is an Unauthorized copy of this file. Please contact Administrator"), vbOKOnly
ActiveWindow.Close SaveChanges:=False
Exit Sub
End If
End Sub
问题是工作簿当前打开并始终运行 PathOk 例程
,无论文件路径如何。
最佳答案
为了确保您检查的是正确的工作簿,也许您应该这样做:
在“Thisworkbook”代码模块中:
Private Sub Workbook_Open()
FilePath Me
End Sub
在标准代码模块中:
Sub FilePath(WB As Workbook)
If WB.Path = ("path address") Then
PathOk
Else
MsgBox "This is an Unauthorized copy of this file. Please contact Administrator", _
vbOKOnly + vbCritical 'So it looks more critical ;)
ActiveWindow.Close SaveChanges:=False
Exit Sub
End If
End Sub
关于vba - 如何要求 Excel 2010 工作簿位于特定文件路径中才能使用 VBA 打开?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22800182/