VBA Basic Concepts

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.