我想将工作表从工作簿A导出到另一个工作簿B,我需要Excel来提示我选择。我收到错误“类型不匹配”。或者,我也可以导出到一个全新的工作簿。
Sub savefile()
Worksheets("Test").Activate
Dim wb As Workbook
Dim filter As String
Dim linkf As Variant
Dim targetWorkbook As Workbook
Set targetWorkbook = Application.ActiveWorkbook
caption = "Please Select an output file "
linkf = Application.GetOpenFilename(filter, , caption)
If linkf = False Then Exit Sub
Set wb = Workbooks.Open(linkf)
targetWorkbook.Sheets("Test").Copy After:=Workbooks(wb).Sheets("Sample")
End Sub
答案 0 :(得分:0)
替换以下行
targetWorkbook.Sheets("Test").Copy After:=Workbooks(wb).Sheets("Sample")
到
targetWorkbook.Sheets("Test").Copy After:=wb.Sheets("Sample")
答案 1 :(得分:0)
用这个替换你的最后一行: targetWorkbook.Sheets(“Test”)。复制后:= wb.Sheets(“Sample”)
确保在第二个工作簿中有一个名为“Sample”的工作表