[英]Copy one tab from a sheet to another workbook
我正在编写一个宏,以将活动工作簿的选项卡选项卡复制到不同的工作簿。 所以基本上我想做的是:
我尝试使用以下代码进行操作:
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.快速修复有什么想法吗?
问候,马克
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
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.