One: VBA object
' VBA objects ' objects in VBA are actually the ones we operate with methods, properties that support objects in Excel: ' 1, Workbook ' Workbooks represents a workbook collection, all workbooks, Workbooks (n), which indicates that the nth workbook ' Workbooks ("Workbook name") ' ActiveWorkbook is in the workbook ' 2, Workbook ' where the workbook ' ThisWorkBook ' code is in action ' ' Sheets ("sheet name") ' Sheet1 represents the first inserted sheet, Sheet2 represents the second inserted sheet .... ' Sheets (n) indicates that the nth worksheet ' ActiveSheet represents the active sheet in order, and the worksheet ' worksheet on the cursor also represents the worksheet, but excludes chart sheets, macro sheets, 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
Two: VBA Objects and properties
' One, VBA Properties ' VBA property is the feature of the VBA object ' The method that represents the property of an object is ' object. Property = property value Sub ttt () Range ("A1"). Value = The 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 ' II, VBA method ' The VBA method is action on a VBA object ' means that a method is used on an object for VBA, which can be in the following format: Sub TTT4 () steak. Degree of maturity: = Seven mature Range ("A1"). Copy Range ("A2") End Sub Sub Ttt5 () sheet1.move before:=sheets ("Sheet3") End Sub
Three: VBA statements
' The basic structure of code in VBA and Components ' VBA statement ' one, macro program Statement ' can be completed after a function Sub test () ' start statement Range ("a1") = 100End Sub ' concluding sentence ' two, A function program Statement ' can return a value after shcount () shcount = Sheets.count End function ' III, a statement that is applied in a 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 Basic Concepts