How to use the method of variable type "Workbook" Excel (Excel) Macro (VBA)

Excel Macro (VBA)
The article contains advertisements.

The use of the variable type "Workbook" is described in this blog.

How to use the variable type "Workbook" Excel(Excel) Macro(VBA)

Here is a more detailed explanation of the "Workbook" method.

Workbook Methods

Workbook methods are like instructions to the book. These methods allow the book to be brought forward, closed, or saved.

Here are some typical frequently used methods.

method nametreatment
ActivateActivate the book
CloseClose the book
SaveOverwrite and save the book
SaveCopyAsSave a copy of the book

We will look at how to use it specifically.

.Activate

Activates the specified book.

Sub Workbook Usage()
    Dim tb As Workbook
    Set tb = ThisWorkbook
    Set tb = ThisWorkbook.Activate
End Sub

.Close

You can close the specified book.

Sub Workbook Usage()
    Dim tb As Workbook
    Set tb = ThisWorkbook
    Set tb = ThisWorkbook.Close
End Sub

If you have not saved the file since you last edited it, do not close it immediately.

and an option to save the book or not.

However, the book is closed as soon as nothing is edited or saved and then run.

.Save

The specified book can be overwritten and saved.

Sub Workbook Usage()
    Dim tb As Workbook
    Set tb = ThisWorkbook
    Set tb = ThisWorkbook.Save
End Sub

When this was done, the file was overwritten and saved.

.SaveCopyAs

Saves a copy of the specified book.

Sub Workbook Usage()
    Dim tb As Workbook
    Set tb = ThisWorkbook
    Set tb = ThisWorkbook.SaveCopyAs ("Book2.xlsm")
End Sub

A new book called "Book2.xlsm" is now saved.

Comment

Copied title and URL