如何要求excel 2010工作簿位于特定文件路径中,以便使用VBA打开?
我希望工作簿位于特定的文件路径中才能打开。我正在excel 2010中使用VBA (项目/工作手册代码: 标题:工作簿/打开) (项目/模块/模块1 标题:(常规)文件路径)如何要求excel 2010工作簿位于特定文件路径中,以便使用VBA打开?,vba,excel,filepath,Vba,Excel,Filepath,我希望工作簿位于特定的文件路径中才能打开。我正在excel 2010中使用VBA (项目/工作手册代码: 标题:工作簿/打开) (项目/模块/模块1 标题:(常规)文件路径) 问题是工作簿当前打开并每次运行pathk例程,而不管文件路径如何。为确保检查的工作簿正确,您可能应该这样做: 在“Thisworkbook”代码模块中: Private Sub Workbook_Open() FilePath Me End Sub Sub FilePath(WB As Workbook)
问题是工作簿当前打开并每次运行
pathk例程
,而不管文件路径如何。为确保检查的工作簿正确,您可能应该这样做:
在“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
在标准代码模块中:
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
你的代码在我这边有效。你会遇到你上面描述的那种情况?