VBA对象体系

116 篇文章 0 订阅
111 篇文章 0 订阅

VBA中访问一个对象,必须清楚该对象在对象体系中处于何种位置,然后通过对象访问符合“.”进行访问,从包含该对象的最外层对象开始,由外及里逐次取其子对象,一直到达要访问的对象为止。例如要访问当前工作表的第4列第3行单元格的存储内容,Application.activesheets.range(“d3”).value。

VBA中主要包含6层基本对象】

 

Application对象

代表整个 Microsoft Excel 应用程序

Workbooks 集合对象

代表应用程序中当前打开的所有 Workbook 对象的集合

Workbook对象

代表 Microsoft Excel 工作簿

Worksheets集合对象

代表指定的或活动工作簿中所有 Worksheet 对象的集合

Worksheet对象

代表一张工作表

Range对象

代表某一单元格、某一行、某一列、某一选定区域

 

Application 对象_代表整个 Microsoft Excel 应用程序

常用属性

 

常用方法

常用事件

ActiveCell

OnWindow

Calculate

SheetActivate

ActiveSheet

Path

ConvertFormula

SheetDeactivate

ActiveWindow

PathSeparator

OnKey

SheetFollowHyperlink

ActiveWorkbook

Range

InputBox

WindowActivate

AskToUpdateLinks

Rows

Run

WindowDeactivate

Assistant

ScreenUpdating

 

WorkbookActivate

AutoRecover

Selection

 

WorkbookBeforeClose

Caption

Sheets

 

WorkbookOpen

Cells

ShowWindowsInTaskbar

 

 

Charts

StandardFont

 

 

Columns

StandardFontSize

 

 

CommandBars

StartupPath

 

 

CommandUnderlines

StatusBar

 

 

Creator

ThisCell

 

 

Cursor

ThisWorkbook

 

 

DefaultFilePath

UserControl

 

 

DefaultSaveFormat

Workbooks

 

 

DisplayFormulaBar

Worksheets

 

 

DisplayFullScreen

DisplayScrollBars

 

 

Name

DisplayStatusBar

 

 

 

 

 

 

Workbooks 集合对象_应用程序中当前打开的所有 Workbook 对象的集合

属性

方法

 

 

Application

Add

 

 

Count

Close

 

 

Creator

Open

 

 

Item

OpenDatabase

 

 

Parent

OpenText

 

 

 

 

 

 

Workbook 对象_代表 Microsoft Excel 工作簿

属性

方法

事件

 

Charts

Activate

Activate

 

CodeName

Close

BeforeClose

 

FullName

Protect

Open

 

FullNameURLEncoded

ProtectSharing

SheetActivate

 

HasPassword

RunAutoMacros

SheetDeactivate

 

InactiveListBorderVisible

Save

SheetFollowHyperlink

 

Password

SaveAs

WindowActivate

 

Path

SaveCopyAs

WindowDeactivate

 

ProtectStructure

Unprotect

 

 

ProtectWindows

Add

 

 

ReadOnly

 

 

 

Saved

 

 

 

Sheets

 

 

 

Windows

 

 

 

Worksheets

 

 

 

WritePassword

 

 

 

 

 

 

 

Worksheets 集合对象_指定的或活动工作簿中所有 Worksheet 对象的集合

属性

方法

 

 

Application

Add

 

 

Count

Copy

 

 

HPageBreaks

Delete

 

 

Item

FillAcrossSheets

 

 

Parent

Move

 

 

Visible

PrintOut

 

 

VPageBreaks

Select

 

 

 

 

 

 

Worksheet 对象_代表一张工作表

属性

方法

事件

 

Application

Activate

Activate

 

AutoFilter

Calculate

BeforeDoubleClick

 

AutoFilterMode

ChartObjects

BeforeRightClick

 

Cells

CheckSpelling

Calculate

 

CircularReference

CircleInvalid

Change

 

CodeName

ClearArrows

Deactivate

 

Columns

Copy

FollowHyperlink

 

EnableSelection

Delete

PivotTableUpdate

 

Hyperlinks

Evaluate

SelectionChange

 

Name

Move

 

 

ProtectContents

OLEObjects

 

 

Protection

Paste

 

 

ProtectScenarios

PasteSpecial

 

 

Range

PivotTables

 

 

Rows

PivotTableWizard

 

 

ScrollArea

SaveAs

 

 

Type

Select

 

 

Visible

Unprotect

 

 

 

 

 

 

Range集合对象_代表某一单元格、某一行、某一列、某一选定区域

属性

方法

方法

 

AddIndent

Activate

FillUp

 

Address

AddComment

Find

 

AddressLocal

AdvancedFilter

FindNext

 

AllowEdit

ApplyNames

FindPrevious

 

Application

ApplyOutlineStyles

FunctionWizard

 

Areas

AutoComplete

GoalSeek

 

Borders

AutoFill

Group

 

Cells

AutoFilter

Insert

 

Characters

AutoFit

Insert

 

Column

AutoFormat

Justify

 

Columns

AutoOutline

Merge

 

ColumnWidth

BorderAround

NavigateArrow

 

Comment

Calculate

NoteText

 

Count

CheckSpelling

Parse

 

Creator

Clear

PasteSpecial

 

CurrentArray

ClearComments

PrintOut

 

CurrentRegion

ClearContents

PrintPreview

 

Dependents

ClearFormats

RemoveSubtotal

 

DirectDependents

ClearNotes

Replace

 

Font

ClearOutline

RowDifferences

 

FormatConditions

ColumnDifferences

Run

 

Formula

Consolidate

Select

 

FormulaArray

Copy

SetPhonetic

 

FormulaHidden

CopyFromRecordset

Show

 

FormulaLabel

CopyPicture

ShowDependents

 

FormulaLocal

CreateNames

ShowErrors

 

FormulaR1C1

CreatePublisher

ShowPrecedents

 

FormulaR1C1Local

Cut

Sort

 

Height

DataSeries

SortSpecial

 

Name

Delete

Speak

 

Value

DialogBox

SpecialCells

 

Text

Dirty

SubscribeTo

 

Row

EditionOptions

Subtotal

 

Rows

FillDown

Table

 

Range

FillLeft

TextToColumns

 

RowHeight

FillRight

UnMerge

 

每一个对象基本包括:属性、方法、事件三类特征。

事件应用举例:

Application 中的worksheet事件

Private Sub Workbook_SheetActivate(ByVal Sh As Object)

    With ActiveWorkbook.Worksheets("sheet1").Sort

        .SetRange Range("B8:E13")

        .Apply

    End With

End Sub

  上述代码输入的路径是:vba编程环境中,双击sheet1,右侧上方选中worksheet,最右侧就会出现关于worksheet的几种常用事件。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值