没有声明结束

我得到错误结束没有与我的代码上的声明。 基本上我想检查一下是否存在一个文件,如果不存在,那么msgbox会打开它,复制一个范围,然后将范围粘贴到目标范围。 我也希望能够为多个文件做到这一点。

Sub test() Dim WbookCheck As Workbook Dim filepaths As String On Error Resume Next Set WbookCheck = Workbooks("LL-AD-ARROW.xls") On Error GoTo 0 If WbookCheck Is Nothing Then 'not open.... filepaths = "c:\Disti-Master\Data\LL-AD-ARROW.xls" If Dir(filepaths) = "" Then MsgBox "File is missing" Exit Sub Else 'file exists - open it Set WbookCheck = Workbooks.Open(filepaths) Cells.Select Sheets("Sheet1").Range("B5").Activate Selection.Copy Windows("WW Disti Weekly Q116_Master.xlsm").Worksheets("Update").Range("D3").Activate Selection.PasteSpecial xlPasteValues End If End With End Sub 

 Sub test() Dim WbookCheck As Workbook Dim filepaths As String On Error Resume Next Set WbookCheck = Workbooks("LL-AD-ARROW.xls") On Error GoTo 0 If WbookCheck Is Nothing Then 'not open.... filepaths = "c:\Disti-Master\Data\LL-AD-ARROW.xls" If Dir(filepaths) = "" Then MsgBox "File is missing" Exit Sub Else 'file exists - open it Set WbookCheck = Workbooks.Open(filepaths) Cells.Select Sheets("Sheet1").Range("B5").Activate Selection.Copy Windows("WW Disti Weekly Q116_Master.xlsm").Worksheets("Update").Range("D3").Activate Selection.PasteSpecial xlPasteValues End If End If End Sub