我无法使用visual basic将工作表从一个工作簿复制到另一个工作簿。
到目前为止,我的代码打开了一个空白的工作簿,它打开了另一个excel文件,其中包含我要复制的工作表。这就是我得到的:
'This creates the new workbook
Set NewBook = Workbooks.Add
NewBook.Title = MyRecordset.Fields(1) & "_Tables"
'This creates a sheet named "2-13"
Sheets.Add().name = "2-13"
'This will open up the existing excel file with the sheet i want to copy over
Set XlApp = New Excel.Application
XlApp.Visible = True
XlApp.Workbooks.Open (CurrentProject.Path & "\Charts\" & MyRecordset.Fields(1) & "_Charts")
Set wBook = XlApp.Workbooks(XlApp.Workbooks.Count)
Set wSheet2 = wBook.Sheets("L1")
因此,NewBook是空白的excel文件,wBook是excel文件,其中包含名为" L1"我想在名为" 2-13"的表格中复制到NewBook。任何帮助将不胜感激!感谢
答案 0 :(得分:1)
将copy一个工作表的内容改为另一个:
' Get contents of worksheet.
wBook.Sheets("L1").UsedRange.Copy
' Paste contents into new sheet.
NewBook.Sheets("2-13").Paste