Activate windows Of file stored in an array? Type mismatch and subscript out of range
I'm trying to write a couple of lines of code that activate the windows of files stored in an array so that I can copy and paste data from one file to another but I keep getting either a subscript out of range or type mismatch error. Any ideas on the syntax??
Dim Allfiles as string 'array containing files that are already opened but need to be switched between one another
Dim test as integer 'index to All开发者_JAVA百科files the number of files in Allfiles
Application.workbooks(Allfiles(Test)).activate 'type mismatch
You need to post more information, such as more of your code and what you're trying to do, but some thoughts:
Did you include the extension in the file name string? Workbook "MyWorkbook" should be application.workbooks("MyWorkBook.xls"), replacing xls with the proper extension for whatever version/file type you're using.
How are you declaring and filling the array?
Have you considered using a For Each on the Workbooks collection? For example:
Dim wkb As Workbook For Each wkb In Application.Workbooks wkb.Activate 'Do your copy/pasting here Next wkb
精彩评论