简体   繁体   English

具有一个命名工作表的Excel宏VBA新工作簿

[英]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.

相关问题 vba宏从一张纸复制数据并将其保存到新工作簿 - vba macro to copy data from one sheet and save it a new workbook Excel VBA:我切换到新工作簿并想删除工作表,但代码试图删除宏工作簿中的工作表 - Excel VBA: I switched to a new workbook and want to delete a sheet, but code is trying to delete sheet in macro workbook Excel VBA 关闭工作簿并触发新宏 - Excel VBA Close Workbook and Trigger New Macro Excel VBA宏可将工作簿工作表中的特定行复制到新的摘要工作表中…几乎可以工作 - Excel VBA macro to copy specific rows from workbook sheets into new summary sheet…almost works 将命名工作表从一个工作簿保存到同一文件夹中的新工作簿 - Save a named sheet from one workbook to a new workbook in the same folder 将文件夹中的多个工作簿合并到一个文件中,每个工作簿作为单独的工作表,文件名 = 工作表名 - Excel VBA 宏 - Combine multiple workbooks in a folder into one file, every workbook as a separate sheet, file name = sheet name - Excel VBA macro Excel VBA - 检查工作簿中存在的特定工作表和命名单元格的功能 - Excel VBA - Function to check a specific sheet and named cell exists in workbook Excel VBA将内容从一个工作表复制到另一个工作簿工作表 - Excel VBA copy content from one Sheet into other Workbook sheet Excel 2016 VBA宏-使用存储在另一个工作簿中的值更新excel工作簿中的各种命名范围 - Excel 2016 VBA Macro - update various named ranges in an excel workbook using values stored in another workbook 通过复选框将工作表保存到新工作簿中[Excel Macro / VBA] - Save Worksheets to new Workbook By Checkbox [Excel Macro/VBA]
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM