从第三个工作簿本身打开的工作簿调用打开时,工作簿不会打开

我面临一个关于vba的问题,从一个文件(我们称之为file1)解释我自己,通过点击一个button,打开另一个工作簿(file2),当到达这个工作簿时,它要求打开另一个文件(file3) ,但它不….(当我写“设置WBK =工作簿(文件3),它给了我的错误”下标超出范围“)

事实上,当我直接打开file2时,它将打开文件3,没有任何问题

有人有答案吗?

在文件1

Private Sub CommandButton3_Click() UserForm1.Hide Workbooks.Open ("Boss4 copy.xlsm") End Sub 

在文件2(Boss4副本)

 Private Sub Workbook_Open() Dim MyPath As String Dim MyScript As String Dim MyFiles As String Dim MySplit As Variant Dim N As Long Dim Fname As String Dim mybook As Workbook On Error Resume Next MyPath = MacScript("return (path to documents folder) as String") MyScript = _ "set applescript's text item delimiters to "","" " & vbNewLine & _ "set theFiles to (choose file of type " & _ " {""com.microsoft.Excel.xls"",""org.openxmlformats.spreadsheetml.sheet""} " & _ "with prompt ""Please select a file or files"" default location alias """ & _ MyPath & """ multiple selections allowed true) as string" & vbNewLine & _ "set applescript's text item delimiters to """" " & vbNewLine & _ "return theFiles" MyFiles = MacScript(MyScript) On Error GoTo 0 MySplit = Split(MyFiles, ",") For N = LBound(MySplit) To UBound(MySplit) ' Get the file name only and test to see if it is open. Fname = Right(MySplit(N), Len(MySplit(N)) - InStrRev(MySplit(N), Application.PathSeparator, , 1)) If bIsBookOpen(Fname) = False Then Set mybook = Nothing On Error Resume Next Set mybook = Workbooks.Open(MySplit(N)) On Error GoTo 0 Else MsgBox "the file: " & MySplit(N) & " is already opened." End If Next N With Application .ScreenUpdating = True .EnableEvents = True End With **Here's the error "subscript out of range"** Set WBK = Workbooks(Fname) Else: Exit Sub End If End Sub 

仍然在文件2

 Function bIsBookOpen(ByRef szBookName As String) As Boolean On Error Resume Next bIsBookOpen = Not (Application.Workbooks(szBookName) Is Nothing) End Function