我希望excel能够记住活动工作表名称,然后删除活动工作表并复制我用作模板的其他工作表,并使用已删除工作表中存储的名称重命名新工作表。
这是我使用的代码我只需要用存储的工作表名称重命名工作表
Sub Reset_Work_Order()
Application.DisplayAlerts = False
ActiveWindow.SelectedSheets.Delete
Dim NewSht As Worksheet
Master_Work_Order.Copy After:=ActiveSheet
Set NewSht = ActiveSheet
End Sub
答案 0 :(得分:2)
尝试以下代码:
Option Explicit
Sub Reset_Work_Order()
Dim ShtName As String
Dim Master_Work_Order As Worksheet
Application.DisplayAlerts = False
Set Master_Work_Order = Worksheets("YourMasterSheetsName")
' keep name of ActiveSheet
ShtName = ActiveSheet.Name
ActiveSheet.Delete
Dim NewSht As Worksheet
Master_Work_Order.Copy After:=ActiveSheet
Set NewSht = ActiveSheet
' set new copied sheet name to Previous ActiveSheet's name
NewSht.Name = ShtName
End Sub