我需要从一个工作簿中获取(复制)工作表并将其附加到现有excel文档的末尾。我写了这段代码,但它不起作用,并给出了错误。请帮忙=)
Public wb As Workbook 'workbook with the source sheet
Sub test()
dim wbNew as workbook 'destination workbook
Set wbNew = Workbooks.Open(Me.fileDestPathTextBox.Value)
wbNew.Sheets.Add After:=wbNew.Sheets(wbNew.Sheets.Count).Name = Me.sheetNameTextBox.Value
wb.Sheets("Souce Sheet").Copy wbNew.Sheets(Me.sheetNameTextBox.Value)
End Sub
答案 0 :(得分:0)
您不添加工作表,然后尝试将工作表复制到该工作表 - 只需将原始工作表复制到目标工作簿:
Sub test()
dim wbNew as workbook 'destination workbook
Set wbNew = Workbooks.Open(Me.fileDestPathTextBox.Value)
wb.Sheets("Souce Sheet").Copy After:=wbNew.Sheets(wbNew.Sheets.Count)
End Sub