VBA:将刚刚创建的图纸移动到工作簿中所有选项卡最右侧的代码

ory*_*000 0 excel vba

有谁知道在VBA中立即移动刚创建的选项卡到整个工作簿最右侧的选项卡的方法。我的代码现在的工作方式是将选项卡放在最左边(这是默认值)。任何帮助将非常感激。

Sub AddSheet()
Dim wb As Workbook: Set wb = ActiveWorkbook
Dim strName As String: strName = CStr(MaxSheetNumber(wb) + 1)
Dim ws As Worksheet
Set ws = wb.Worksheets.Add(Type:=xlWorksheet)
With ws
    .Name = strName
End With

'Line of code here that would immediately move the new tab "ws" to the furthest right position of all tabs in the workbook

End Sub
Run Code Online (Sandbox Code Playgroud)

SJR*_*SJR 5

指定After参数:

Set ws = wb.Worksheets.Add(Type:=xlWorksheet, after:=wb.Worksheets(wb.Worksheets.Count))
Run Code Online (Sandbox Code Playgroud)

  • 哇,就像魔术一样。非常感谢 (2认同)