Excel VBA 更改复制活动的名称 sheet
Excel VBA Change name of copied active sheet
下面是我的代码。我想将此应用于任何 excel 文件并创建任何 sheet selected 的副本并将其重命名为 Updated.
ActiveWorkbook.ActiveSheet.Select
ActiveWorkbook.Activesheet.copy After:=Sheets(1)
*Sheets("page (2)").Select
Sheets("page (2)").Name = "Updated"*
如何select新复制的作品sheet。 *包围的部分是问题,我只是不知道要更改什么。
您应该检查 Updated 名称是否已经存在。
Sub UpdatenMove()
Dim ws As Worksheet
On Error Resume Next
Set ws = Sheets("Updated")
On Error GoTo 0
If Not ws Is Nothing Then
MsgBox "This sheet already exists", vbCritical
Else
ActiveSheet.Copy After:=Sheets(1)
ActiveSheet.Name = "Updated"
End If
End Sub
下面是我的代码。我想将此应用于任何 excel 文件并创建任何 sheet selected 的副本并将其重命名为 Updated.
ActiveWorkbook.ActiveSheet.Select
ActiveWorkbook.Activesheet.copy After:=Sheets(1)
*Sheets("page (2)").Select
Sheets("page (2)").Name = "Updated"*
如何select新复制的作品sheet。 *包围的部分是问题,我只是不知道要更改什么。
您应该检查 Updated 名称是否已经存在。
Sub UpdatenMove()
Dim ws As Worksheet
On Error Resume Next
Set ws = Sheets("Updated")
On Error GoTo 0
If Not ws Is Nothing Then
MsgBox "This sheet already exists", vbCritical
Else
ActiveSheet.Copy After:=Sheets(1)
ActiveSheet.Name = "Updated"
End If
End Sub