Domanda

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  Allfiles the number of files in Allfiles
         Application.workbooks(Allfiles(Test)).activate 'type mismatch 
È stato utile?

Soluzione

You need to post more information, such as more of your code and what you're trying to do, but some thoughts:

  1. 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.

  2. How are you declaring and filling the array?

  3. 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
    
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top