Create new workbook using VBA - learnit

Home Top Ad

Post Top Ad

Wednesday, June 2, 2021

Create new workbook using VBA

Create new workbook using VBA

Create new workbook using VBA

What is VBA?

VBA stands for Visual Basic for Applications, an event-driven programming language from Microsoft. It is now predominantly used with Microsoft Office applications such as MSExcel, MS-Word and MS-Access.


What is Workbook?

In Microsoft Excel, a workbook is a collection of one or more spreadsheets, also called worksheets, in a single file. Below is an example of a spreadsheet called "Sheet1" in an Excel workbook file called "Book1." Our example also has the "Sheet2" and "Sheet3" sheet tabs, which are also part of the same workbook.


Difference between a workbook, worksheet, and spreadsheet

the terms spreadsheet, workbook, and worksheet are so similar, there may be some confusion when trying to understand their differences. When you open Microsoft Excel (a spreadsheet program), you are opening a workbook. A workbook can contain one or more different worksheets that can be accessed through the tabs at the bottom of the worksheet you are currently viewing. What is often most confusing is that a worksheet is synonymous with a spreadsheet. In other words, a spreadsheet and worksheet mean the same thing. However, most people only refer to the program as a spreadsheet program and the files it creates as spreadsheet files.


Creating new workbooks is done using the Workbooks.Add method which optionally is called with a Template argument which can stand for different things as dsiscussed below. The method returns a Workbook object. The new workbook becomes the active workbook.

Create new workbook with no template specified


Creating a new workbook can be as simple as the code below:

Workbooks.Add

Create new workbook from a template file


Example

Sub CreateWorkBook()
Workbooks.Add
Workbooks.Add.SaveAs Filename :=”D:\123\Test2021.xlsx”
End Sub


Note

Though the argument name here is Template, any file that can be opened in Excel is allowed - it need not be an Exel template type (.xltx or similar) -An alternative way to create a new file is using Workbooks.Open and specifying a real Excel template type file in the Filename argument and Editable:=False.

Please Watching My Video is Below

No comments:

Post a Comment

Post Top Ad