开发者

Open array files subscript out of range

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜