0

我正在尝试打开存储在数组中的一系列 xlm 文件,但不断弹出错误提示下标超出范围。有什么建议吗?谢谢

 Dim AllFiles() As String
 Dim count, test, StartRow, LastRow, LastColumn As Long    
 test = count
 Do While (test >= 0)
 Workbooks.Open Filename:=AllFiles(test) 'subscript out of range
 test = test - 1
 Loop
4

1 回答 1

2

这并没有解决根本原因(可能是什么),而是一种更自然的循环数组的方法

For test = UBound(AllFiles) to LBound(AllFiles) Step -1    
    Workbooks.Open Filename:=AllFiles(test)
Loop

顺便说一句,您的暗淡声明Dim count, test, StartRow, LastRow, LastColumn As Long声明了所有项目LastColumn,除了Variant

于 2011-08-18T21:29:51.960 回答