例如有 file1.xls和file2.xls两个excel文件,file1.xls里面有个sheet1,file2.xls里面有个sheet2,要想把sheet1作为一个增加的sheet复制到file2.xls里面去,要怎么做呢?

解决方案 »

  1.   

    Set chApp = CreateObject("Excel.Application")
    chApp.Visible = visible
    Set source = chApp.Workbooks.Open(cPath & "file1.xls", 0)
    Set template = chApp.Workbooks.Open(cPath & "file2.xls", 0)source.Activate
    source.Sheets("sheet1").Select
    chApp.Cells.Select
    chApp.Selection.Copytemplate.Activate
    template.Sheets("sheet2").Select
    chApp.Cells.Select
    chApp.ActiveSheet.Paste
    chApp.Range("A1").Select
      

  2.   

    Dim newApp As New Excel.Application
        Dim newBook1 As New Excel.Workbook
        Dim newBook2 As New Excel.Workbook
        
        
        Set newBook1 = newApp.Workbooks.Open("D:\file1.xls") '---输入你的正确路径
        Set newBook2 = newApp.Workbooks.Open("D:\file2.xls") '---输入你的正确路径
        
        '下面表示把file1.els里的sheet1复制到file2.xls里的sheet2后面
        newBook1.Worksheets("sheet1").Copy after:=newBook2.Worksheets("sheet2")
        
        newApp.Visible = True
        
        Set newBook1 = Nothing
        Set newBook2 = Nothing
        Set newApp = Nothing