VBA objects, methods, properties

Source: Internet
Author: User

' 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

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.