' VBA object
' The objects in VBA are actually the objects that we manipulate that are supported in Excel with methods and properties
' Several common object representation methods in Excel
' 1, workbooks
' Workbooks represents the workbook collection, all workbooks, Workbooks (n), which represents the nth workbook that has been opened
' Workbooks ("Workbook name")
' ActiveWorkbook the workbook that is being manipulated
The workbook where the ' ThisWorkBook ' code resides
' 2, worksheets
' Sheets ("sheet name")
' Sheet1 represents the first inserted sheet, Sheet2 represents the second inserted sheet ....
' Sheets (n) indicates the order, nth sheet
' ActiveSheet represents the active sheet, the worksheet on which the cursor is located
' Worksheet also represents worksheets, but does not include chart sheets, macro worksheets, and so on.
' 3, cell
' Cells all cells
' Range ("cell address")
' Cells (number of rows, number of columns)
' Activecell the cell being selected or edited
' Selection the cell or range of cells that is being selected or selected
' One, VBA properties
' VBA properties are features of VBA objects
' means that a property of an object is represented by the
' Object. Property = property Value
Sub TTT ()
Range ("A1"). Value = 100
End Sub
Sub TTT1 ()
Sheets (1). Name = "Worksheet renamed"
End Sub
Sub Ttt2 ()
Sheets ("Sheet2"). Range ("A1"). Value = "ABCD"
End Sub
Sub Ttt3 ()
Range ("A2"). Interior.ColorIndex = 3
End Sub
' Second, VBA method
' VBA method is an action that acts on a VBA object
' means that you can use a method for VBA objects in the following format:
Sub Ttt4 ()
Steak. Degree of cooked: = Seven mature
Range ("A1"). Copy Range ("A2")
End Sub
Sub Ttt5 ()
Sheet1.move before:=sheets ("Sheet3")
End Sub
' Basic structure and components of code in VBA
' VBA statements
' One, macro program statements
' Can complete a function after running
Sub test () ' Start statement
Range ("a1") = 100
End Sub ' concluding sentence
' Second, function program statement
' Can return a value after running
Function Shcount ()
Shcount = Sheets.count
End Function
' Iii. statements applied in the program
Sub test2 ()
Call Test
End Sub
Sub Test3 ()
For x = 1 "for Next loop statement
Cells (x, 1) = X
Next x
End Sub
VBA objects, methods, properties