Excel VBA中的“下标超出范围”错误

时间:2019-06-17 12:10:00

标签: excel vba

以下代码给出错误“下标超出范围”:

Sub Workbooks2(str)
     Workbooks.Open (ThisWorkbook.path & "\" & str)
     Workbooks(ThisWorkbook.path & "\" & str).Close ' <<<<< subscript out of range error
End Sub

1 个答案:

答案 0 :(得分:0)

以下工作原理(在“关闭”命令中删除了文件的路径):

Sub Workbooks2(str)
     Workbooks.Open (ThisWorkbook.path & "\" & str)
     Workbooks(str).Close 
End Sub