7,763
社区成员
发帖
与我相关
我的任务
分享
Option Explicit
Sub Main()
Dim xlApp As Object
Dim xlBook As Object
Dim xlBookNew As Object
Dim xlSheet1 As Object
Dim xlSheet2 As Object
Dim xlSheetNew As Object
Set xlApp = CreateObject("Excel.Application")
xlApp.Visible = False
Set xlBook = xlApp.Workbooks.Open("D:\a.xls")
Set xlSheet1 = xlBook.Sheets(1)
Set xlSheet2 = xlBook.Sheets(2)
xlSheet1.Copy
Set xlBookNew = xlApp.Workbooks(xlApp.Workbooks.Count)
Set xlSheetNew = xlBookNew.Sheets(1)
xlSheet2.Activate
xlSheet2.UsedRange.Copy
xlSheetNew.Activate
xlSheetNew.Cells(xlSheetNew.UsedRange.Rows.Count + 1, 1).Select
xlSheetNew.Paste
xlBookNew.SaveAs "D:\a-new.xls"
Set xlSheetNew = Nothing
xlBookNew.Close False
Set xlBookNew = Nothing
Set xlSheet1 = Nothing
Set xlSheet2 = Nothing
xlBook.Close False
Set xlBook = Nothing
xlApp.Quit
Set xlApp = Nothing
End Sub