Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/vba/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何要求excel 2010工作簿位于特定文件路径中,以便使用VBA打开?_Vba_Excel_Filepath - Fatal编程技术网

如何要求excel 2010工作簿位于特定文件路径中,以便使用VBA打开?

如何要求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)

我希望工作簿位于特定的文件路径中才能打开。我正在excel 2010中使用VBA

(项目/工作手册代码: 标题:工作簿/打开)

(项目/模块/模块1 标题:(常规)文件路径)


问题是工作簿当前打开并每次运行
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

你的代码在我这边有效。你会遇到你上面描述的那种情况?