20160122: Start learning VBA: (i), Macro and vba/(ii), VBA statement object method Properties

Source: Internet
Author: User

Start today with "Blue Fantasy" video learning VBA

The macro is actually the operation step

Recorded macros are automatically generated by VBA

In VB, you can write your own

You can specify a macro by using the form button

1. VBA Objects
' 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

2. VBA Properties

' VBA properties are features of VBA objects
' means that a property of an object is represented by the

Object.Properties= 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


3. 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:

' object. Method parameter Name: = parameter value
Sub Ttt4 ()

Steak. Degree of cooked: = Seven mature

Range ("A1"). Copy Range ("A2")
End Sub

Sub Ttt5 ()

Sheet1.move before:=sheets ("Sheet3")

End Sub

Macro Program statement: Complete a function after running

/////////////////////////////////////////////////////////

Sub function name ()

EXECUTE statement

End Sub

Sub Test ()

Range ("a1") = 100

End Sub

////////////////////////////////////////////////////////

Second, function program statement: Can return a value after running

/////////////////////////////////////////////////////////

Function Shcount ()

Shcount = Sheets.count

End Function

////////////////////////////////////////////////////////

Iii. statements that run in a program

/////////////////////////////////////////////////////////

Sub test2 ()

Call Test

End Sub

////////////////////////////////////////////////////////

20160122: Start learning VBA: (i), Macro and vba/(ii), VBA statement object method 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.