[英]Excel macro VBA new workbook with one named sheet
I need a macro to able to create a new workbook with only one sheet named "Options" and the following worksheets must start with "Sheet1" not with "Sheet2". 我需要一个宏才能仅使用一个名为“ Options”的工作表来创建新工作簿,并且以下工作表必须以“ Sheet1”开头,而不是以“ Sheet2”开头。 Is it possible?
可能吗?
The code below will add a new Workbook
with just 1 sheet named "Options". 下面的代码将添加一个只有1个名为“选项”的
Workbook
表的新Workbook
。
However, regarding the second part, in order to start from "Sheet1" instead of "Sheet2" it involves adding code to the new created Workbook, since by default the new workbook already has 1 worksheet named "Options", so in fact you are adding a 2nd worksheet, so Excel automatically names it "Sheet2" 但是,关于第二部分,为了从“ Sheet1”而不是“ Sheet2”开始,它涉及将代码添加到新创建的工作簿中,因为默认情况下,新工作簿已经具有1个名为“选项”的工作表,因此实际上添加第二个工作表,因此Excel自动将其命名为“ Sheet2”
Option Explicit
Sub CreateNewWB()
With Application
.SheetsInNewWorkbook = 1
.Workbooks.Add
.Sheets(1).Name = "Options"
End With
End Sub
Think this is what you're looking for 认为这就是您要寻找的
This first creates a new workbook, then adds a new sheet at the beginning before renaming it to "Options". 这首先创建一个新的工作簿,然后在将其重命名为“选项”之前在开头添加新的工作表。 The rest of the sheets should then follow the default naming pattern
然后,其余的工作表应遵循默认的命名模式
Option Explicit
Public Sub NewWorkbook()
With Workbooks.Add
With .Sheets.Add(Before:=.Sheets(1))
.Name = "Options"
End With
End With
End Sub
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.