Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/excel/26.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 错误处理-在何处输入';退出Sub';?_Excel_Vba_Error Handling - Fatal编程技术网

Excel 错误处理-在何处输入';退出Sub';?

Excel 错误处理-在何处输入';退出Sub';?,excel,vba,error-handling,Excel,Vba,Error Handling,我有下面的代码,它只是打开一个文件。如果指定的LCO中不存在该文件,则需要显示错误消息。下面代码的问题是,当文件确实存在时,它会打开,在单元格A1中输入“Hello”,但MsgBox仍会出现。我想我把出口接头放错地方了 Sub Test() Dim Location As String Dim File1 As String Dim Err1 As String On Error GoTo Err1 Location = "S:\HRIS\Restricted\Information S

我有下面的代码,它只是打开一个文件。如果指定的LCO中不存在该文件,则需要显示错误消息。下面代码的问题是,当文件确实存在时,它会打开,在单元格A1中输入“Hello”,但MsgBox仍会出现。我想我把出口接头放错地方了

Sub Test()

Dim Location As String
Dim File1 As String
Dim Err1 As String

On Error GoTo Err1
  Location = "S:\HRIS\Restricted\Information Services\Regular Reports\DRS _   
    Automation\" & Format(Date, "DD.MM.YYYY")
      File1 = "\Test.xlsx"
        Workbooks.Open FileName:=Location & File1

Range("A1").Value = "Hello"

Err1:
  MsgBox "Could not Locate " & Location & File1
Exit Sub

End Sub

Err1
标签之前移动
Exit Sub

Sub Test()

    Dim Location As String
    Dim File1 As String
    Dim Err1 As String

    On Error GoTo Err1
        Location = "S:\HRIS\Restricted\Information Services\Regular Reports\DRS Automation\" & Format(Date, "DD.MM.YYYY")
        File1 = "\Test.xlsx"
        Workbooks.Open Filename:=Location & File1

    Range("A1").Value = "Hello"

    Exit Sub

Err1:
      MsgBox "Could not Locate " & Location & File1

End Sub

Err1
标签之前移动
Exit Sub

Sub Test()

    Dim Location As String
    Dim File1 As String
    Dim Err1 As String

    On Error GoTo Err1
        Location = "S:\HRIS\Restricted\Information Services\Regular Reports\DRS Automation\" & Format(Date, "DD.MM.YYYY")
        File1 = "\Test.xlsx"
        Workbooks.Open Filename:=Location & File1

    Range("A1").Value = "Hello"

    Exit Sub

Err1:
      MsgBox "Could not Locate " & Location & File1

End Sub

我一发帖就意识到了这一点。谢谢你的帮助。我一发帖就意识到了。谢谢你的帮助。在出现错误1之前,你需要一个出口接头。。。。请参见错误1…之前需要退出子系统。。。。另见