Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/arrays/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Arrays 是否激活存储在阵列中的文件的窗口?类型不匹配和下标超出范围_Arrays_Types_Excel_Type Mismatch_Vba - Fatal编程技术网

Arrays 是否激活存储在阵列中的文件的窗口?类型不匹配和下标超出范围

Arrays 是否激活存储在阵列中的文件的窗口?类型不匹配和下标超出范围,arrays,types,excel,type-mismatch,vba,Arrays,Types,Excel,Type Mismatch,Vba,我正试图编写几行代码来激活存储在数组中的文件窗口,这样我就可以将数据从一个文件复制粘贴到另一个文件,但我不断得到下标超出范围或类型不匹配错误。关于语法有什么想法吗 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

我正试图编写几行代码来激活存储在数组中的文件窗口,这样我就可以将数据从一个文件复制粘贴到另一个文件,但我不断得到下标超出范围或类型不匹配错误。关于语法有什么想法吗

      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 

您需要发布更多信息,例如更多的代码和您正在尝试执行的操作,但有些想法:

  • 文件名字符串中是否包含扩展名?工作簿“MyWorkbook”应该是application.Workbook(“MyWorkbook.xls”),用您正在使用的任何版本/文件类型的适当扩展名替换xls

  • 如何声明和填充数组

  • 您是否考虑过对工作簿集合中的每个对象使用一个?例如:

    Dim wkb As Workbook
    
    For Each wkb In Application.Workbooks
        wkb.Activate
        'Do your copy/pasting here
    Next wkb
    

  • 这就更完整地解释了我正在使用do循环填充数组Allfiles。如何为存储在数组中的文件包含扩展名。我只需要语法,存储在allfiles数组中的文件名包含感兴趣文件的完整目录。那么应该如何为这种情况编写语法。Application.workbook(Allfiles(Test)).activate“subscript超出范围语法错误??Allfiles(test),其中test是一个整数,等于存储在Allfiles中的文件总数。所有文件都包含需要放在前面的感兴趣文件的完整目录。