Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/vba/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
将Excel工作簿合并到工作表中_Excel_Vba_Merge - Fatal编程技术网

将Excel工作簿合并到工作表中

将Excel工作簿合并到工作表中,excel,vba,merge,Excel,Vba,Merge,我目前正在尝试将24本工作簿合并到一个包含24张工作表的工作簿中。工作簿名为run 1到run 24,我正在尝试合并到一个模板中,该模板已经有两张名为summary和pressure的工作表。我对这方面的编码非常陌生,任何从其他问题复制的代码似乎都不适合我。我尝试了移动到模板中的记录宏,但在尝试应用该宏时,出现了运行时错误9。代码如下所示 Sub Macro1() ' ' Macro1 Macro ' ' Sheets("Sheet1").Select Sheets("Shee

我目前正在尝试将24本工作簿合并到一个包含24张工作表的工作簿中。工作簿名为run 1到run 24,我正在尝试合并到一个模板中,该模板已经有两张名为summary和pressure的工作表。我对这方面的编码非常陌生,任何从其他问题复制的代码似乎都不适合我。我尝试了移动到模板中的记录宏,但在尝试应用该宏时,出现了运行时错误9。代码如下所示

Sub Macro1()
'
' Macro1 Macro
'

'
    Sheets("Sheet1").Select
    Sheets("Sheet1").Copy After:=Workbooks("Current Template.xlsx").Sheets(2)
    Sheets("Sheet1").Select
    Sheets("Sheet1").Move After:=Workbooks("Current Template.xlsx").Sheets(3)
End Sub
任何帮助都将不胜感激


干杯

这可能会帮助您:

Sub test()

    Dim wb As Workbook
    Set wb = Application.Workbooks("target.xlsm")  'Considering that macro is placed in your target file
    i = 1
    While i < 25
        Workbooks.Open ("run" & i & ".xlsx")   'give path as applicable
        Set wb1 = Application.Workbooks("run" & i & ".xlsx")
        With wb1
            .Sheets("sheet1").Copy After:=wb.Sheets(wb.Sheets.Count)   'the new sheet will be placed after the last sheet in target file
            .Close
        End With
    i = i + 1
    Wend

End Sub

好的,非常感谢。我将target.xlsm更改为template.xlsm,因为这是目标工作簿。但是它说有一个运行时错误1004,需要检查文件的拼写和位置是否正确。我不知道如何进入这条路。是否有特定的编码行?路径是您的文件夹位置。e、 g.C:\rusk\run。还要提到您在哪一行收到此错误。