Close the current workbook

Sub CloseWorkbook()
    ActiveWorkbook.Close
    End Sub
Copy the code

Save and close the workbook


    Sub ClostAndSaveWorkbook()
    ActiveWorkbook.Close Savechanges:=True
    End Sub
Copy the code

Create a new worksheet

Workbooks.Add
Copy the code

Gets the name of the worksheet

Workbooks(1).Name
Copy the code

Activate the second worksheet

Workbooks(2).Activate
Copy the code

Delete worksheet

Worksheets("Expenses").Delete
Copy the code

Declare a variable

Dim s As String 
Copy the code

Open the file for output

  Open fullName For Output As #1 
Copy the code

Type Hello in the file above

Print # 1, "hello"Copy the code

Obtain elements

Cells(1, c1)
Copy the code

Pop-up prompts

MsgBox ("ok!" )Copy the code

Then in fact, vBA is mostly VB code, although there is a little bit different, but most are the same, such as for statement and if statement are the same, can be directly used.

We probably use it a lot when we’re dealing with data. Just practice and give it a try.

You are welcome to discuss procedural questions with me and answer any questions you may have. Follow the public number: poetic code, make a friend.