我正在编写宏来将活动工作簿的选项卡选项卡复制到不同的工作簿。基本上我想做的是:
我尝试使用以下代码执行此操作:
Sub Copy()
'Open the sheet in which I want to copy the tab
Workbooks.Open ("C:\Users\aa471714\Desktop\RTS\1.xlsx")
'Copy the sheet from an activeworkbook to the tab after the excelsheet i just opened (1.xlsx)
ActiveWorkbook.Sheets("3.").Copy _
after:=Workbooks("1.xlsx").Sheets("1.")
'Define new sheetname
shtname = InputBox("What's the new sheet name?", "Sheet name?")
ActiveSheet.Name = "3_" & shtname
End Sub
但是我得到了一个错误9.有关快速修复的想法吗?
此致 马克
答案 0 :(得分:0)
ActiveWorkbook
可能存在问题这有帮助吗?
Sub Copy()
Dim source As Workbook, sht As Worksheet
Set source = ActiveWorkbook
Set sht = source.Sheets("3.")
'Open the sheet in which I want to copy the tab
Workbooks.Open ("C:\Users\aa471714\Desktop\RTS\1.xlsx")
'Copy the sheet from original to the tab after the excelsheet i just opened (1.xlsx)
sht.Copy after:=ActiveWorkbook.Sheets("1.")
'Define new sheetname
shtname = InputBox("What's the new sheet name?", "Sheet name?")
ActiveSheet.Name = "3_" & shtname
End Sub