开发者

Open array files subscript out of range

开发者 https://www.devze.com 2023-03-28 21:39 出处:网络
I\'m trying to open up a series of xlm 开发者_运维技巧files stored in an array, but the error keeps popping up that says that the subscript is out of range. Any advice? Thanks

I'm trying to open up a series of xlm 开发者_运维技巧files stored in an array, but the error keeps popping up that says that the subscript is out of range. Any advice? Thanks

 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


This doesn't address the root cause (what ever that may be) but is a more natural way to loop an array

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

By the way, your dim statement Dim count, test, StartRow, LastRow, LastColumn As Long declares all items except LastColumn as Variant

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号