You are on page 1of 303

YExcel VBA

Excel VBA Excel VBA

VBA

Excel VBA
Excel Excel

Excel Office

Excel

Excel VBA
VBA Excel
Excel
Excel VBA
Excel
VBA Excel
VBA
Excel
Excel
VBA
Excel

VBA

500

Excel VBA

Excel

VBA ................................................................................1

1.1

..........................................................................................2

1.2

VBA .................................................................2
1.2.1

..............................................................................3

1.2.2

..............................................................................8

1.3

VBA ....................................................................9

1.4

............................................................................12

1.5

1.6

1.4.1

................................................................................12

1.4.2

................................................................................13

VBA ...............................................................14
1.5.1

Boolean ..........................................................14

1.5.2

Byte ...............................................................15

1.5.3

Currency ........................................................15

1.5.4

Data ...............................................................15

1.5.5

Decimal ..........................................................15

1.5.6

Double ...........................................................16

1.5.7

Integer ............................................................16

1.5.8

Long ...............................................................16

1.5.9

Object ............................................................16

1.5.10

Single ...........................................................16

1.5.11

String ...........................................................17

1.5.12

..................................................17

1.5.13

Variant .........................................................17

........................................................................................17
1.6.1

........................................................................18

1.6.2

........................................................................19

1.6.3
1.7

............................................................20

....................................................................................20
1.7.1

....................................................................21

1.7.2

....................................................................22

1.7.3

....................................................................23

1.8

................................................................................23
1.8.1 Select Case ............................................................23
1.8.2

With .......................................................................26

1.9

................................................................................28

1.10

..............................................................................30

1.10.1

DoLoop ............................................................30

1.10.2

ForNext ............................................................31

1.10.3

For EachNext ...................................................33

1.10.4 WhileWend ......................................................34


1.11 ..........................................................................34
1.11.1

Function ...............................................................35

1.11.2

Sub .......................................................................37

1.11.3

......................................................................38

.............................................................................44

A ......................................................................................................45
AddIn .........................................................................................45
Adjustments................................................................................46
Application.................................................................................46
Assistant .....................................................................................47
AutoCorrect................................................................................47
AutoFilter ...................................................................................47
C ......................................................................................................48
Cells ...........................................................................................48
Chart...........................................................................................48

Characters .........................................................................49
Comment ..........................................................................50
D ......................................................................................................50
DataLabel ...................................................................................50
Dialog.........................................................................................50
F.......................................................................................................51
FillFormat...................................................................................51
Filter ...........................................................................................51
Floor ...........................................................................................52
Font ............................................................................................53
FreeformBuilder .........................................................................53
G ......................................................................................................54
Gridlines.....................................................................................54
H ......................................................................................................55
HPageBreak................................................................................55
Hyperlink....................................................................................55
I........................................................................................................56
Interior........................................................................................56
L ......................................................................................................56
Legend........................................................................................56
LegendEntry...............................................................................57
LegendKey .................................................................................58
LineFormat.................................................................................58
N ......................................................................................................59
Name ..........................................................................................59
O ......................................................................................................59
Outline........................................................................................59
P.......................................................................................................60
PageSetup...................................................................................60

Pane............................................................................................60
PictureFormat .............................................................................60
PivotCache .................................................................................61
PivotField ...................................................................................62
PivotItem ....................................................................................62
PivotTable ..................................................................................62
PlotArea .....................................................................................63
Point ...........................................................................................64
PublishObject .............................................................................64
R ......................................................................................................65
Range .........................................................................................65
RecentFile ..................................................................................65
RecentFile ..................................................................................65
RoutingSlip ................................................................................66
Range .........................................................................................66
S.......................................................................................................66
Series..........................................................................................66
SeriesLines .................................................................................67
ShadowFormat ...........................................................................68
Shape..........................................................................................68
Sheets .........................................................................................69
T ......................................................................................................69
Trendline ....................................................................................69
TextEffectFormat .......................................................................70
TextFrame ..................................................................................71
ThreeDFormat ............................................................................71
TickLabels..................................................................................72
U ......................................................................................................73
UpBars .......................................................................................73

V ......................................................................................................74
VPageBreak................................................................................74
W .....................................................................................................74
Window ......................................................................................74
Workbook...................................................................................74
Worksheets.................................................................................75
3

.............................................................................76

A ......................................................................................................77
Activate .............................................................................77
B ......................................................................................................77
BeforeClose .......................................................................77
BeforeDoubleClick ............................................................78
BeforePrint ........................................................................78
BeforeRightClick ...............................................................79
BeforeSave ........................................................................79
C ......................................................................................................80
Calculate ............................................................................80
Change ...............................................................................80
D ......................................................................................................81
Deactivate ..........................................................................81
F.......................................................................................................81
FollowHyperlink ...............................................................81
G ......................................................................................................82
GotFocus ...........................................................................82
L ......................................................................................................83
LostFocus ..........................................................................83
M .....................................................................................................83
MouseDown ......................................................................83
MouseMove .......................................................................84

MouseUp ...........................................................................85
N ......................................................................................................85
NewSheet ..........................................................................85
O ......................................................................................................86
Open ..................................................................................86
R ......................................................................................................86
Resize ................................................................................86
S.......................................................................................................87
SelectionChange ................................................................87
SheetActivate ....................................................................88
SheetBeforeDoubleClick ...................................................88
SheetBeforeRightClick ......................................................89
SheetCalculate ...................................................................89
SheetChange ......................................................................90
SheetDeactivate .................................................................90
SheetFollowHyperlink .......................................................91
SheetSelectionChange .......................................................91
W .....................................................................................................92
WindowActivate ................................................................92
WindowDeactivate ............................................................92
WindowResize ...................................................................93
4

.............................................................................94

A ......................................................................................................95
Activate .............................................................................95
ActivateNext ......................................................................95
ActivatePrevious ...............................................................95
AddCallout ........................................................................96
AddComment ....................................................................96
AddConnector ...................................................................96

AddFormControl ...............................................................97
AddItem .............................................................................97
AddLabel ...........................................................................98
AddLine .............................................................................98
AddNodes .........................................................................99
AddPicture .........................................................................99
AddShape ........................................................................100
AddTextbox ....................................................................100
AddTextEffect ................................................................100
Align ...............................................................................101
AutoFilter .......................................................................101
Apply ...............................................................................102
ApplyCustomType ..........................................................102
Arrange ............................................................................102
AutoFill ..........................................................................103
AutoFit ...........................................................................103
AutoFormat ....................................................................103
B ....................................................................................................104
BarGroups .......................................................................104
BeginConnect .................................................................105
BeginDisconnect ............................................................105
BorderAround .................................................................106
BringToFront ..................................................................107
BuildFreeform ................................................................107
C ....................................................................................................108
Calculate .........................................................................108
ChangeFileAccess ..........................................................108
CentimetersToPoints ......................................................108
Characters .......................................................................109

ChartGroups ...................................................................109
ChartObjects ...................................................................110
ChartWizard ...................................................................110
Clear ...............................................................................111
ClearComments ..............................................................111
ClearContents .................................................................111
ClearFormats ..................................................................111
ClearNotes ......................................................................111
ClearOutline ...................................................................112
Close ...............................................................................112
Copy ...............................................................................112
CopyPicture ....................................................................113
CustomDrop ...................................................................113
Cut ..................................................................................113
D .................................................................................................... 114
DataLabels .......................................................................114
DataSeries ........................................................................114
Delete ..............................................................................114
Deselect ...........................................................................115
DoubleClick ....................................................................115
Duplicate .........................................................................115
E .................................................................................................... 116
EndConnect .....................................................................116
EndDisconnect .................................................................116
ErrorBar ...........................................................................116
ExecuteExcel4Macro .......................................................117
Export ..............................................................................117
Extend .............................................................................117
F..................................................................................................... 118

FillAcrossSheets .............................................................118
FillDown .........................................................................118
FillLeft ............................................................................118
FillRight .........................................................................118
FillUp .............................................................................118
Find ................................................................................119
FindFile ..........................................................................119
FindNext .........................................................................119
FindPrevious ....................................................................120
Flip ..................................................................................121
FunctionWizard ..............................................................121
G ....................................................................................................122
GetOpenFilename ............................................................122
GetSaveAsFilename .......................................................122
Goto ................................................................................123
Group 1....................................................................123
Group 2....................................................................123
H ....................................................................................................124
Help ................................................................................124
I......................................................................................................124
InchesToPoints ...............................................................124
IncrementBrightness .......................................................124
IncrementContrast ..........................................................125
IncrementLeft .................................................................125
IncrementOffsetX ...........................................................125
IncrementOffsetY ............................................................125
IncrementRotationX .......................................................125
IncrementTop .................................................................126
InputBox .........................................................................126

Insert ...............................................................................126
Item ..........................................................................................127
J .....................................................................................................127
Justify .............................................................................127
L ....................................................................................................127
LargeScroll .....................................................................127
List ..................................................................................127
Location ...........................................................................128
M ...................................................................................................128
Merge ..............................................................................128
Move ...............................................................................128
N ....................................................................................................128
NewSeries ........................................................................128
Next ................................................................................129
NoteText .........................................................................129
O ....................................................................................................129
OnKey .............................................................................129
OnUndo ...........................................................................130
Open ................................................................................130
OpenText .........................................................................131
P.....................................................................................................131
Paste ...............................................................................131
PasteSpecial ....................................................................131
PointsToScreenPixelsY ..................................................133
PresetDrop ......................................................................133
PresetGradient ................................................................133
PresetTextured ................................................................134
Previous ..........................................................................134
PrintOut ..........................................................................134

PrintPreview ...................................................................134
Protect ............................................................................135
Q ....................................................................................................135
Quit .................................................................................135
R ....................................................................................................135
RangeFromPoint .............................................................135
Regroup ..........................................................................136
RemoveAllItems .............................................................136
RemoveItem ...................................................................136
Replace ...........................................................................136
ResetAllPageBreaks ........................................................137
ResetColors ....................................................................137
ResetRotation .................................................................137
RunAutoMacros .............................................................137
Save ................................................................................138
SaveAs ............................................................................138
SaveCopyAs ...................................................................138
SaveWorkspace ..............................................................139
ScaleHeight ....................................................................139
ScaleWidth .....................................................................139
Select ..............................................................................139
SetBackgroundPicture ....................................................140
SetSourceData ................................................................140
Show ...............................................................................140
Sort .................................................................................140
T ....................................................................................................141
Text ................................................................................141
TextToColumns ..............................................................141
ToggleVerticalText .........................................................141

Trendlines .......................................................................142
TwoColorGradient ..........................................................142
U ....................................................................................................143
Undo ...............................................................................143
Ungroup ..........................................................................143
Union ..............................................................................143
UnMerge .........................................................................144
Unprotect ........................................................................144
UserPicture .....................................................................144
UserTextured ..................................................................145
V ....................................................................................................145
Volatile ...........................................................................145
W ...................................................................................................145
Wait ................................................................................145
X ....................................................................................................146
XYGroups .......................................................................146
Z ....................................................................................................146
ZOrder .............................................................................146
5

...........................................................................147

A ....................................................................................................148
ActiveCell ........................................................................148
ActiveChart .....................................................................148
ActiveSheet .....................................................................148
ActiveWindow .................................................................148
ActiveWorkbook .............................................................149
AddIndent .......................................................................149
Address ............................................................................149
Areas ...............................................................................149
AutoFilter ........................................................................150

AutoFilterMode ...............................................................150
AutoScaleFont .................................................................150
AutoScaling .....................................................................150
AutoShapeType ...............................................................151
AutoSize ..........................................................................151
AutoText ..........................................................................151
AxisTitle ..........................................................................152
B ....................................................................................................152
BackColor ........................................................................152
Background .....................................................................152
Backward .........................................................................153
BarShape .........................................................................153
BaseUnit ..........................................................................153
BeginArrowheadLength ..................................................154
BeginArrowheadStyle .....................................................154
BeginArrowheadWidth ....................................................155
BlackAndWhite ...............................................................155
Bold .................................................................................155
Border ..............................................................................156
Borders ............................................................................156
BottomMargin .................................................................157
BottomRightCell .............................................................158
Build ................................................................................158
BuiltinDocumentProperties .............................................158
C ....................................................................................................159
Callout .............................................................................159
CapitalizeNamesOfDays .................................................159
Caption ............................................................................159
CategoryType ..................................................................160

CellDragAndDrop ...........................................................160
Cells .................................................................................160
CenterFooter ....................................................................160
CenterHeader ...................................................................161
CenterHorizontally ..........................................................161
CenterVertically ..............................................................161
Characters ........................................................................162
Chart ................................................................................162
ChartArea ........................................................................162
Charts ..............................................................................163
ChartSize .........................................................................163
ChartTitle ........................................................................164
ChartType ........................................................................164
Color ................................................................................164
ColorIndex .......................................................................164
Colors ..............................................................................165
Columns ..........................................................................165
ColumnWidth ..................................................................166
Comments ........................................................................166
ConnectionSiteCount .......................................................166
Connector ........................................................................167
ConnectorFormat .............................................................167
Contrast ...........................................................................167
ControlCharacters ............................................................168
Corners ............................................................................168
CorrectCapsLock .............................................................168
CorrectSentenceCap ........................................................168
Count ...............................................................................168
CreateBackup ..................................................................169

Criteria1 ...........................................................................169
Criteria2 ...........................................................................169
CropBottom .....................................................................170
CropLeft ..........................................................................170
CropRight ........................................................................170
CropTop ..........................................................................171
Crosses ............................................................................171
Cursor ..............................................................................172
CursorMovement .............................................................172
CurrentRegion .................................................................172
CutCopyMode .................................................................173
D ....................................................................................................173
DashStyle ........................................................................173
DataTable ........................................................................174
Date1904 .........................................................................174
DefaultFilePath ................................................................174
DefaultSaveFormat ..........................................................175
DefaultSheetDirection .....................................................175
Depth ...............................................................................175
DepthPercent ...................................................................175
Dialogs ............................................................................175
DisplayBlanksAs .............................................................176
DisplayEquation ..............................................................176
DisplayFormulaBar .........................................................176
DisplayFormulas .............................................................177
DisplayFullScreen ...........................................................177
DisplayGridlines ..............................................................177
DisplayHeadings .............................................................178
DisplayHorizontalScrollBar ............................................178

DisplayNoteIndicator ......................................................178
DisplayPageBreaks ..........................................................178
DisplayRecentFiles ..........................................................179
DisplayStatusBar .............................................................179
DisplayVerticalScrollBar .................................................179
DisplayWorkbookTabs ....................................................179
DisplayZeros ...................................................................179
DownBars ........................................................................180
Draft ................................................................................180
Drop .................................................................................180
DropLines ........................................................................180
E ....................................................................................................181
EditDirectlyInCell ....................................................................181
Elevation ..........................................................................181
Enabled ............................................................................182
EnableEvents ...................................................................182
EnableResize ...................................................................182
EnableSelection ...............................................................182
End ..................................................................................183
EndArrowheadLength .....................................................183
EndArrowheadStyle ........................................................183
EndArrowheadWidth .......................................................184
EndConnected .................................................................184
EndConnectedShape ........................................................184
EndStyle ..........................................................................185
EntireColumn ..................................................................185
EntireRow ........................................................................186
ErrorBars .........................................................................186
Extent ..............................................................................186

ExtrusionColor ................................................................186
ExtrusionColorType ........................................................187
F.....................................................................................................187
FileFormat .......................................................................187
FileSearch ........................................................................188
Fill ...................................................................................188
Filters ...............................................................................189
FirstSliceAngle ................................................................189
FitToPagesTall ................................................................189
FitToPagesWide ..............................................................189
FixedDecimal ..................................................................190
FixedDecimalPlaces ........................................................190
Floor ................................................................................191
Font .................................................................................191
FontBold ..........................................................................191
FontItalic .........................................................................191
FontSize ...........................................................................191
FontStyle .........................................................................192
FooterMargin ...................................................................192
ForeColor ........................................................................193
FormControlType ............................................................193
FormulaHidden ................................................................193
FormulaR1C1 ..................................................................194
Forward ...........................................................................194
FreezePanes .....................................................................194
FullName .........................................................................194
G ....................................................................................................194
Gap ..................................................................................194
GapDepth ........................................................................195

GapWidth ........................................................................195
GradientColorType ..........................................................196
GradientDegree ...............................................................196
GradientStyle ...................................................................196
GradientVariant ...............................................................197
GridlineColor ..................................................................197
GridlineColorIndex ..........................................................198
H ....................................................................................................198
Has3DEffect ....................................................................198
HasAxis ...........................................................................198
HasBorderHorizontal .......................................................199
HasBorderOutline ............................................................199
HasBorderVertical ...........................................................199
HasDataLabel ..................................................................199
HasDataLabels .................................................................200
HasDataTable ..................................................................200
HasDropLines ..................................................................201
HasFormula .....................................................................201
HasHiLoLines .................................................................201
HasLegend .......................................................................202
HasMajorGridlines ..........................................................202
HasMinorGridlines ..........................................................203
HasPassword ...................................................................203
HasTitle ...........................................................................203
HasUpDownBars .............................................................203
HeaderMargin ..................................................................204
Height ..............................................................................204
HeightPercent ..................................................................204
Hidden .............................................................................204

HiLoLines ........................................................................204
HorizontalAlignment .......................................................205
HorizontalFlip .................................................................205
Hyperlink .........................................................................206
I......................................................................................................206
IncludeAlignment ............................................................206
IncludeBorder ..................................................................206
IncludeFont ......................................................................206
IncludeNumber ................................................................207
IncludePatterns ................................................................207
IncludeProtection .............................................................207
IndentLevel ......................................................................208
Index ................................................................................208
InsideHeight ....................................................................208
InsideLeft ........................................................................209
InsideTop .........................................................................209
InsideWidth .....................................................................209
Interactive ........................................................................209
Intercept ...........................................................................209
InterceptIsAuto ................................................................210
Interior .............................................................................210
Italic .................................................................................211
Item .................................................................................211
K ....................................................................................................212
KernedPairs .....................................................................212
L ....................................................................................................212
LargeChange ...................................................................212
LeaderLines .....................................................................212
Left ..................................................................................213

LeftFooter ........................................................................213
LeftHeader .......................................................................213
LeftMargin ......................................................................213
Legend .............................................................................214
LegendKey ......................................................................214
Length .............................................................................214
Line .................................................................................215
Line3DGroup ..................................................................215
LineStyle .........................................................................215
LinkedCell .......................................................................215
ListCount .........................................................................216
ListFillRange ...................................................................216
ListIndex ..........................................................................216
Location ...........................................................................216
LockAspectRatio .............................................................217
LockedText ......................................................................217
M ...................................................................................................217
MajorGridlines ................................................................217
MajorTickMark ...............................................................217
MajorUnit ........................................................................218
MarginBottom .................................................................218
MarginLeft ......................................................................219
MarginRight ....................................................................219
MarginTop .......................................................................219
MarkerBackgroundColor .................................................219
MarkerBackgroundColorIndex ........................................220
MarkerForegroundColor ..................................................220
MarkerForegroundColorIndex .........................................221
MarkerSize ......................................................................221

MarkerStyle .....................................................................222
Max .................................................................................222
Maximum ........................................................................223
MaximumScale ................................................................223
MaximumScaleIsAuto .....................................................223
MemoryFree ....................................................................223
MemoryTotal ...................................................................223
MemoryUsed ...................................................................224
Min ..................................................................................224
MinimumScale ................................................................225
MinimumScaleIsAuto ......................................................225
MinorGridlines ................................................................225
MinorTickMark ...............................................................225
MinorUnit ........................................................................226
MinorUnitIsAuto .............................................................226
MinorUnitScale ...............................................................226
MouseAvailable ...............................................................227
MoveAfterReturn ............................................................227
MoveAfterReturnDirection .............................................228
N ....................................................................................................228
Name ...............................................................................228
NameIsAuto ....................................................................228
Next .................................................................................229
Nodes ...............................................................................229
NormalizedHeight ...........................................................229
NumberFormatLinked .....................................................229
O ....................................................................................................230
Obscured ..........................................................................230
Offset ...............................................................................230

OffsetX ............................................................................230
OffsetY ............................................................................230
OLEFormat ......................................................................231
OnAction .........................................................................231
OnWindow ......................................................................231
Order ...............................................................................231
OperatingSystem .............................................................231
Orientation .......................................................................232
Outline .............................................................................232
OutlineFont ......................................................................233
OutlineLevel ....................................................................233
Overlap ............................................................................233
P.....................................................................................................233
PageBreak ........................................................................233
PageSetup ........................................................................234
Panes ...............................................................................234
PaperSize .........................................................................234
Parent ...............................................................................234
Path ..................................................................................235
PathSeparator ..................................................................235
Pattern .............................................................................235
PatternColor ....................................................................235
PatternColorIndex ...........................................................235
Period ..............................................................................236
Perspective ......................................................................236
PictureFormat ..................................................................236
PictureType .....................................................................236
PlotArea ...........................................................................237
PlotBy ..............................................................................237

PlotOrder .........................................................................237
PlotVisibleOnly ...............................................................237
Points ...............................................................................238
Position ............................................................................238
PrefixCharacter ................................................................239
PresetExtrusionDirection .................................................239
PresetGradientType .........................................................240
PresetLightingSoftness ....................................................241
PresetMaterial ..................................................................242
PresetShape .....................................................................242
PresetTextEffect ..............................................................242
PresetTexture ...................................................................242
PresetThreeDFormat ........................................................243
Previous ...........................................................................243
PrintArea .........................................................................243
PrintComments ................................................................243
PrintGridlines ..................................................................244
PrintHeadings ..................................................................244
PrintNotes ........................................................................244
PrintObject ......................................................................245
PrintTitleColumns ...........................................................245
PrintTitleRows .................................................................245
ProtectChartObject ..........................................................245
ProtectContents ...............................................................245
ProtectData ......................................................................246
ProtectDrawingObjects ....................................................246
ProtectFormatting ............................................................246
ProtectGoalSeek ..............................................................247
ProtectionMode ...............................................................247

ProtectScenarios ..............................................................247
ProtectSelection ...............................................................248
ProtectStructure ...............................................................248
ProtectWindows ..............................................................248
Q ....................................................................................................249
QueryTables ....................................................................249
R ....................................................................................................249
Range ...............................................................................249
ReadingOrder ..................................................................249
ReadOnly .........................................................................249
RecentFiles ......................................................................250
ReferenceStyle .................................................................250
Resize ..............................................................................250
ReversePlotOrder ............................................................250
RGB .................................................................................251
RightFooter ......................................................................251
RightHeader ....................................................................252
RightMargin ....................................................................252
Rotation ...........................................................................252
RotationX ........................................................................252
RotationY ........................................................................252
Row .................................................................................253
RowColSettings ...............................................................253
RowHeight ......................................................................253
Rows ................................................................................253
S.....................................................................................................254
ShapeRange .....................................................................254
Shapes .............................................................................254
Sheets ..............................................................................254

ShowWindow ..................................................................254
ShowWindowsInTaskbar ................................................255
ShrinkToFit .....................................................................255
Size ..................................................................................255
SizeWithWindow ............................................................256
Smooth ............................................................................256
Split .................................................................................256
SplitColumn ....................................................................257
SplitHorizontal ................................................................257
SplitRow ..........................................................................257
SplitVertical ....................................................................257
StandardFont ...................................................................257
StandardFontSize .............................................................258
StandardHeight ................................................................258
StandardWidth .................................................................258
StatusBar .........................................................................258
Strikethrough ...................................................................258
Styles ...............................................................................259
Subscript ..........................................................................259
Superscript .......................................................................260
SurfaceGroup ..................................................................260
T ....................................................................................................260
TableRange2 ....................................................................260
TabRatio ..........................................................................261
Text .................................................................................261
TextFrame .......................................................................261
TextToDisplay .................................................................262
ThisWorkbook .................................................................262
ThreeD .............................................................................262

TickLabelPosition ...........................................................262
TickLabelSpacing ............................................................263
TickMarkSpacing ............................................................263
Top ..................................................................................263
TopLeftCell .....................................................................264
TopMargin .......................................................................264
Type .................................................................................264
U ....................................................................................................265
Underline .........................................................................265
UpBars .............................................................................266
UsableHeight ...................................................................266
UsableWidth ....................................................................266
UsedRange ......................................................................266
UserName ........................................................................266
UseStandardHeight ..........................................................267
UseStandardWidth ...........................................................267
V ....................................................................................................267
Value ...............................................................................267
VaryByCategories ...........................................................268
Version ............................................................................268
VerticalAlignment ...........................................................269
Visible .............................................................................269
VPageBreaks ...................................................................269
W ...................................................................................................269
Walls ...............................................................................269
Weight .............................................................................270
Width ...............................................................................270
WindowNumber ..............................................................270
Windows ..........................................................................270

WindowState ...................................................................270
Workbooks ......................................................................271
Worksheet ........................................................................271
WorksheetFunction ..........................................................271
Worksheets ......................................................................271
WrapText .........................................................................272
X ....................................................................................................272
XValues ...........................................................................272
Z ....................................................................................................272
Zoom ...............................................................................272

1 VBA

Y Excel VBA
VBA Visual Basic for Application
JavaCDelphi VBA

VBA

1.1

VBA Office 97
Office Excel

VBA VBA Visual Basic VBA


VB VBA VB
Excel VBA VB
VBA Excel
Excel VB

1.2

VBA

Visual
Basic

Excel

1
1.2.1

VBA

Excel Excel
VBA

VBA
VBA
Excel
||
Visual Basic Visual Basic 1-1

1-1 VB
1-2
Visual Basic
Visual Basic 1-3

1-2

Y Excel VBA

1-3 VB
1-3
1-4

1-4

1-5

1-5

1-6
4

VBA

4 Excel 2003
3

1-6

VB VB
1-7 VB
VB

1-7 VB
5

Y Excel VBA

1-8

1-8

Microsoft Script

Excel
1-9

1-9

1 Visual Basic
leo
1-10

VBA

1-10

2 1-11

1-11

3 A1 A2
A3
7

Y Excel VBA
4 A1A3
12
5 A1A3
6 B2D2
B3D3
B2
7

Visual Basic VB VBA


1-12

1-12

VBA

VBA Excel

1.2.2

VBA

1 Visual Basic
1-13

1-13
2leo
sheet1 1-14

1-14

1.3

VBA

VBA
VBA VBA

Y Excel VBA

Excel
VBA
1 Excel
2||Visual Basic
Alt+F11 Visual Basic
3 ThisWorkbook
1-15

1-15

ThisWorkbook

4
ThisWorkbook 1-16

1-16
10

VBA

4 ThisWorkbook
Workbook/open 1-17

1-17
5 1-18

1-18
Private Sub Workbook_Open()
'
'
Dim Msg, Style, Title
11

Y Excel VBA
'
Msg = "VBA"
'
Style = vbOKOnly
'
Title = ""
MsgBox Msg, Style, Title
End Sub
6
7 Excel
1-19

1-19
VBA
VBA

1.4
1.4.1

VBA
vbRed
12

VBA

0xFF VBA

1
VBA 16 1-1

1-1

VBA

Calendar
Color
Date

IMEStatus
Keycode
MsgBox
Shell

IME

CallType
Compiler
DirGetAttr
SetAttr
InstrStrComp
Miscellaneous
QueryClose
StrConv

VarType

[Public|Private] Const [As type] =


expression
Public
Private
1.4.2

VBA
VBA

13

Y Excel VBA

Function Add(num)
Temp Val=num+1
End Function
Temp Val Visual
Basic

Option Explicit
2

Dim

Dim [As ]

1.5

VBA

VBA

1.5.1

Boolean

Boolean
Boolean 2 16
True False False

Boolean
True
False
14

1
1.5.2

VBA

Byte

Byte
1 8 Byte
8 0255

1.5.3

Currency

Currency
Currency 8 15 4
-922,337,203,685,477.5808
922,337,203,685,477.5807

Currency
1.5.4

Data

Data
Data 8
100 1 1 9999 12 31
0:00:00 23:59:59
Date
0.5
12 1899 12 31

1.5.5

Decimal

Decimal
Decimal 12 28

+/-7.9228162514264337593543950335
Decimal

0
+/-79,228,162,514,264,337,593,543,950,335
15

Y Excel VBA
1.5.6

Double

Double
Double 8
-1.79769313486231E308-4.94065645841247E-324
4.94065645841247E-3241.79769313486232E308
Double
Double

Currency Decimal
1.5.7

Integer

Integer
Integer 2 -32,768
32,767 Integer
Long
Integer Long
1.5.8

Long

Long
Long 4
-2,147,483,6482,147,483,647
Long
Long
1.5.9

Object

Object
Object 4

1.5.10

Single

Single
Single 4 -3.402823E38
-1.401298E-45 1.401298E-453.402823E38
Single
16

VBA

Single

Currency Decimal
1.5.11

String

StringString
0 255 128 0 127
U.S. 128 ASCII
128 128 255

String
64K

1.5.12

Type

1.5.13

Variant

Variant

Variant

1.6

50 50
50 50
50
Dim score(1 To 50) As Integer
Dim i As Integer
17

Y Excel VBA
For i=0 To 50
score(i) = InputBox("" + i + "
")
Next i

Dim score(1 To 50) As Integer


score 1 50
50
score(1)score(2)
score(3)score(50)

1.6.1

VB 60
Dim (1[,2])[As ]
[ To]
-32768 32767
0-+1
Dim () [As ]
Dim a(5) As Integer 6
a(0)~a(5)
n=10
Dim a(n) As Integer

Dim a(2,3) As Integer


18

VBA

a(0,0) a(0,1) a(0,2) a(0,3)


a(1,0) a(1,1) a(1,2) a(1,3)
a(2,0) a(2,1) a(2,2) a(2,3)
0~2 0~3

Dim a(2,3,4) As Integer


0~2
0~3 0~4
1.6.2

ReDim

Dim array() As Integer


ReDim
ReDim array(1 To 5)
ReDim

Dim

Public
Dim
Static Dim
ReDim Dim Static
ReDim

Preserve ReDim

ReDim Preserve old(UBound(old)+1)


Preserve
19

Y Excel VBA

1.6.3

1.

array
For i=1 to 5
Array(i)=i
Next i
Array
arglist Variant

0
Array(arglist)

exarray exarray

Dim exarray As Variant


exarray=Array(10,20,30)
B=exarray(2)
Array

2.

VBA
Dim a(5) As Integer,b() As Integer
Dim I As Integer
For i=0 To 5
A(i)=i
Next i
b=a
ab

1.7

VB 4

20

VBA

1.7.1

1-2
1-2

+
-

result = expression1 +
expression2
result = number1 number2

*
result = number1 * number2

/
result = number1 / number

\
result = number1\number2

Mod
result = number1 Mod

number2

^
result = number ^ exponent

VB 1-3
1-3

^
-
*/
\
Mod
+-
&
21

Y Excel VBA
1.7.2

Is Like
1-4
1-4

< result = expression1 <


expression2
<= result = expression1
<= expression2
> result = expression1 >
expression2
>= result = expression1
>= expression2
= result = expression1 =
expression2
<> result = expression1

<> expression2
Is
result = object1 Is
object2

expression1
expression2

expression1
expression2 Null
Null

object1 object2
result
Trueresult
False

Like
result = string Like
string pattern
pattern
result True
result False

1-5
1-5

=
<>
<
>
>=
<=
IsLike
22

1
1.7.3

VBA

&

result = expression1 & expression2


result
String result String
+

result = expression1+ expression2

1-6
1-6

Byte
BooleanIntegerLongCurrency
SingleDoubleDate
String

Null Variant
String Null
Variant

String
Null

1.8
1.8.1

Null

Select Case

Select Case testexpression


[Case expressionlist-n
[statements-n]] ...
23

Y Excel VBA
[Case Else
[elsestatements]]
End Select

testexpression

expressionlist-n
testexpression
[statements-n][Case Else
[elsestatements]] case

testexpression Case expressionlist


Case Case
statements
End Select
End Select
testexpression Case
expressionlist

Sub test8()

Dim fenshu As Integer
fenshu = 60
Select Case fenshu

Case 90 To 100
MsgBox ""
Case 75 To 89
MsgBox ""
Case 60 To 74
24

VBA

MsgBox ""
Case Else
MsgBox ""
End Select
End Sub

case 901007589
6074
case case else
1-20

1-20
case
End Select

Sub test9()
Dim fenshu As Integer
fenshu = 83
Select Case fenshu
Case 80 To 100
MsgBox ""
Case 75 To 85
MsgBox ""
Case 60 To 74
MsgBox ""
Case Else
MsgBox ""
End Select
MsgBox ""
End Sub
End select MsgBox ""
case
25

Y Excel VBA
1-21

1-21

Select
If
Select Case
If If
Select Case
1.8.2

With

With

With object
[statements]

End With

Object
Statements object

1-22

1-22
26

VBA

Sub test10()
' muRangeRange
Dim myRange As Range
' sheet3
Worksheets("Sheet3").Activate
' range
With Range("A1:D5")
'
.Formula = "=RAND()"
'
With .Borders(xlEdgeBottom)
'
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = 3
End With
'
With .Font
'
.Size = 16
.Color = vbRed
.FontStyle = "Bold Italic"
End With
End With
End Sub

with

with Borders Font


range

with
27

Y Excel VBA
Sub test11()
' muRangeRange
Dim myRange As Range
' sheet3
Worksheets("Sheet3").Activate
' range
'
Range("A1:D5") .Formula = "=RAND()"
'
Range("A1:D5").Borders(xlEdgeBottom).
LineStyle = xlContinuous
Range("A1:D5").Borders(xlEdgeBottom).
Weight = xlThin
Range("A1:D5").Borders(xlEdgeBottom).
ColorIndex = 3
'
Range("A1:D5").Font.Size = 16
Range("A1:D5").Font.Color = vbRed
Range("A1:D5").Font.FontStyle = "Bold
Italic"
End Sub

1.9

IfThenElse

If Then [1] [Else 2]


1 2

28

VBA

If 1 Then
[1]
[ElseIf 2 Then
[2] ...
[Else
[3]]
End If

Dim As Integer
= 8000
If <1000 Then
Msgbox
Else
Msgbox
End If

Dim As Integer
= 8000
If <1000 Then
Msgbox
Else
Msgbox

Dim As Integer
= 8000
If <1000 Then Msgbox
Else
Msgbox
End If

Ende If
Else If 1-23

29

Y Excel VBA

1-23

If
If Then
Then
If
Then
If Else
If

1.10

1.10.1

DoLoop

Do...Loop
True True
DoLoop
Do [ {While | Until} condition]
[statements]
[Exit Do]
[statements]
Loop

Do
[statements]
[Exit Do]
[statements]
Loop [ {While | Until} condition]
30

VBA

condition True
False condition Null condition
False
Statements
condition True
Do...Loop Exit Do
Do...Loop Exit Do
If...ThenExit Do Loop
1 100
100000
Sub test3()
'
Dim n As Integer, m As Long
'
n = 1
m = 1
Do While n < 100
n = n + 1
m = m * n
If m >= 100000 Then Exit Do
Loop
'
MsgBox " " & n - 1
End Sub

Esc
Ctrl+Break
1.10.2

ForNext

For...Next
For

31

Y Excel VBA
For counter = start To end [Step step]
[statements]
[Exit For]
[statements]
Next [counter]
counter start end
counter [Step step]setp
counter 1
step start >= end
50 For
x Next 1
Sub Beeps()
For x = 1 To 50
Beep
Next x
End Sub
Step
j 2
total 2468 10
Sub TwosTotal()
For j = 2 To 10 Step 2
total = total + j
Next j
MsgBox "The total is " & total
End Sub
Step

myNum 2total
16141210864 2
Sub NewTotal()
For myNum = 16 To 2 Step -2
total = total + myNum
Next myNum
MsgBox "The total is " & total
End Sub
32

VBA

Next

Exit For
For...Next
If...Then...Else
SelectCase True ExitFor
If...Then...Else
False
1.10.3

For EachNext

For Each...Next
Visual
Basic

Sub CloseForms()
For Each frm In Application.Forms
If frm.Caption <> Screen. ActiveForm.Caption
Then frm.Close
Next
End Sub

I
Dim TestArray(10) As Integer, I As Variant
For Each I In TestArray
TestArray(I) = I
Next I
1
For Each...Next
Sheet1 A1:D10
0.01 0
Sub RoundToZero()
For Each myObject in myCollection
If Abs(myObject.Value) < 0.01 Then myObject.
Value = 0
Next
33

Y Excel VBA
End Sub
2For Each...Next
Exit For For Each...Next
If...Then...Else Select Case
True Exit For
If...Then...Else False

A1:B5
Exit For

Sub TestForNumbers()
For Each myObject In MyCollection
If IsNumeric(myObject.Value) = False Then
MsgBox "Object contains a non-numeric value."
Exit For
End If
Next c
End Sub
1.10.4

WhileWend

True

While condition
[statements]
Wend
condition True statements
Wend While
condition condition True True
Wend
While...Wend Wend
While

1.11

34

VBA

Function Sub

1-7

1-7

Sub
Function
Property

1.11.1

Sub
Function Property
Sub Sub

Function Function

PropertyGetProperty Let Property


Set Property
Property GetProperty Set
Property Set

Function

Function VBA
MidCos InputBox Function
Function
Function Function End
Function

35

Y Excel VBA

TimeInt Str

Private|Public][Static]Function ProcedureName
([arguments as Type]) [As type]
functional statements
End Function

[ ]
Visual Basic

ProcedureName

arguments

As Type

functional statements
ProcedureName

ProcuderName
HexNo
HexNo
Public Function HexNo(pNo As Long)
Dim A As Long,B As Long,Counter As Long
For Counter=1 To pNo
B=B+1
If B=16 Then
If A<>16 Then A=A+1
If Counter<>256 Then B=0
36

VBA

End If
Next
HexNo=Mid("0123456789ABCDEF",A+1,1) & Mid
("0123456789ABCDEF",B+1,1)
End Function

1.11.2

Sub

Sub

[Private|Public][Static] Sub ProcedureName


([arguments as Type])
subroutine statements
End Sub
ProcedureName
arguments

subroutine statements

37

Y Excel VBA

0~9
Error

Private Sub txtInput_KeyDown(KeyCode As


Integer,Shift As Integer)
If(KeyCode=13) Then
'

On Error Resume Next


txtInput.Text=LongToHex(CLng(txtInput.
Text))
End If
If Err<>0 Then
'

MsgBox CStr(Err.Number)&":"&Err.Descrip
tion,vbCritical,"Error"
End If
End Sub

Form1 Visual
Basic
Sub End Sub subroutine
statements
Public
arguments

1.11.3

38

VBA

SortArray
inarr Variant

SortArray

Private Sub SortArray(ByRef inarr As


Variant,ByRef index As Variant)

If k<>i Then
vswap=inarr(i): inarr(i)=inarr(k):
inarr(k)=vswap
End If

For j=0 To num-1


If tmp(i)=inarr(j) Then nIndex(i)=j
Next j

index=nIndex
End Sub
1
Variant

Function WhatsForLunch(WeekDay As String,


Hour As Integer) As String
'
If WeekDay="Friday" Then
WhatsForLunch="Fish"
Else
WhatsForLunch="Chicken"
End If
If Hour>4 Then WhatsForLunch="Too late"
End Function
39

Y Excel VBA
2

ByVal

Visual Basic

Visual Basic

3
Optional

Optional

Dim strName As String


Dim strAddress As String
Sub ListText(Optional x As String,Optional y
As String)
List1.AddItem x
List1.AddItem y
End Sub
Private Sub Command1_Click()
strName="yourname"
strAddress=12345
'
Call ListText(strName,strAddress)
End Sub

Dim strName As String


Dim varAddress As Variant
Sub ListText(x As String,Optional y As Variant)
40

1
List1.AddItem x
If Not IsMissing(y) Then
List1.AddItem y
End If
End Sub

VBA

'

Private Sub Command1_Click()


strName="yourname"
'
Call ListText(strName)
End Sub
Empty
IsMissing

Sub ListText(x As String,Optional y As


Integer=12345)
List1.AddItem x
List1.AddItem y
End Sub
Private Sub Command1_Click()
strName="yourname"
'
Call ListText(strName) 'yourname
12345
End Sub
6

ParamArray
Sum
Dim x As Integer
Dim y As Integer
Dim intSum As Integer

41

Y Excel VBA
Sub Sum(ParamArray intNums())
For Each x In intNums
y=y+x
Next x
intSum=y
End Sub
Private Sub Command1_Click()
Sum 1,3,5,7,8
List1.AddItem intSum
End Sub
7
Visual Basic

(MyArgument:="SomeValue")

Sub ListText(strName As String,Optional


strAddress As String)
List1.AddItem strName
List2.AddItem strAddress
End Sub
Private Sub Command1_Click()
ListText strAddress:="12345",strName:="Your
Name"
End Sub
8

AutoQuickInfo

Visual Basic(VB)
Visual Basic for applications(VBA)
42

VBA

Visual Basic(VB) Visual Basic for


applications(VBA)
[ ]

43

VBA

Excel Workbooks
Workbook VBA Forms
Form

A
AddIn
AddIn
AddlnsAddIns Excel

With Worksheets("sheet1")
.Rows(1).Font.Bold = True
.Range("a1:d1").Value = _
Array("Name", "Full Name", "Title",
"Installed")
For i = 1 To AddIns.Count
.Cells(i + 1, 1) = AddIns(i).Name
.Cells(i + 1, 2) = AddIns(i).FullName
.Cells(i + 1, 3) = AddIns(i).Title
.Cells(i + 1, 4) = AddIns(i).Installed
Next
.Range("a1").CurrentRegion.Columns.AutoFit
End With
2-1

2-1

45

Y Excel VBA
Adjustments

Set myDocument = Worksheets(1)


Set rac = myDocument.Shapes.AddShape
(msoShapeRightArrowCallout, _
10, 10, 250, 190)
With rac.Adjustments
.Item(1) = 0.5
.Item(2) = 0.15
.Item(3) = 0.8
.Item(4) = 0.4
End With
2-2

2-2

Application
Excel Excel
Excel 2

Sub test()
Dim mybook As Excel.Application
Set mybook = New Excel.Application
mybook.Visible = True
mybook.SheetsInNewWorkbook = 2
Set zsbworkbook = mybook.Workbooks.Add
46

End Sub
Assistant
Office Application Assistant
Assistant
office assistant
AutoCorrect
Excel

Namem Name
Sub test()
With Application.AutoCorrect
.AddReplacement "Namem", "Name"
End With
End Sub
2-3

2-3

AutoFilter

Sheet3 A1
Mary

Sub test()
Worksheets("Sheet3").Range("A1").AutoFilter _
Field:=1, _
Criteria1:="Mary", _
VisibleDropDown:=True
End Sub
47

Y Excel VBA
2-4

2-4

C
Cells
Worksheet Excel

Excel

Sub test()
With Sheet3
.Cells(1, 2).Value = "12"
.Cells(2, 2).Value = "30"
.Cells(3, 2).Value = "=SUM(B1:B2)"
.Range("A3") = ""
End With
End Sub
2-5

2-5

Chart

Sub test()
Range("A1:B6").Select
Charts.Add
48

ActiveChart.ChartType = xlCylinderColClustered
ActiveChart.SetSourceData Source:=
Sheets("Sheet3").Range("A1:B6"), PlotBy:= _
xlRows
ActiveChart.Location
Where:=xlLocationAsObject, Name:="Sheet3"
End Sub
2-6

2-6

Characters

C1

Sub test()
With Worksheets("sheet2").Range("c1")
.Value = "My Data"
.Characters(4, 5).Font.Bold = True
.Characters(4, 5).Font.Italic = True
End With
End Sub
2-7

2-7

49

Y Excel VBA
Comment
Comment
Comment
AddComment A2

Sub test()
With Worksheets(1).Range("A2").AddComment
.Visible = ture
.Text " "
End With
End Sub
2-8

2-8

D
DataLabel
DataSet DataColumns
DataRows
With Worksheets(1).ChartObjects(1).Chart
.HasDataTable = True
.DataTable.HasBorderOutline = True
End With
Dialog
Show

Sub test()
dlgAnswer = Application.Dialogs (xlDialog
50

Activate).Show
End Sub
2-9

2-9

F
FillFormat

Sub test()
Set myDocument = Worksheets("FillFormat")
With myDocument.Shapes.AddShape _
(msoShapeRightArrowCallout, 80, 20, 50, 60).Fill
.ForeColor.RGB = RGB(45, 46, 128)
End With
End Sub
2-10

2-10
Filter
Filters Filters
51

Y Excel VBA

42
Sub test()
Range("A1:A6").Select
Selection.AutoFilter
Range("A2").Select
Selection.AutoFilter Field:=1, _
Criteria1:=">50", Operator:=xlAnd
End Sub
2-11

2-11
Floor

Sub test()
Worksheets("Gridlines").ChartObjects(1).Activate
ActiveChart.Floor.Border.LineStyle = xlDash
ActiveChart.Floor.Interior.Color= RGB(0, 255, 0)
End Sub
2-12

2-12
52

Font

Sub test()
Worksheets("Font").Range("b2:b3").Font.Name =
""
Worksheets("Font").Range("a1:c5").Font.Size=20
Worksheets("Font").Range("a1:c5").Font.Colo
rIndex _
= xlAutomatic
End Sub
2-13

2-13
FreeformBuilder

Shapes

Sub test1()
Set myDocument = Worksheets("FreeformBuilder")
With myDocument.Shapes.BuildFreeform _
(msoEditingCorner, 100, 200)
.AddNodes msoSegmentCurve, msoEditingCorner, _
200, 200, 100, 150, 400, 200
.AddNodes msoSegmentCurve, msoEditingAuto,
240, 100
.AddNodes msoSegmentLine, msoEditingAuto,
200, 100
.ConvertToShape
End With
End Sub
2-14
53

Y Excel VBA

2-14

G
Gridlines

Sub test()
Worksheets("Gridlines").ChartObjects(1).Activate
With ActiveChart.Axes(xlValue)
.HasMajorGridlines = True
.HasMinorGridlines = False
End With
ActiveChart.Axes(xlValue).MajorGridlines.Select
ActiveChart.PlotArea.Select
ActiveChart.Axes(xlValue).MajorGridlines.Select
With Selection.Border
.ColorIndex = 41
.Weight = xlMedium
.LineStyle = xlDashDot
End With
End Sub
2-15

2-15
54

H
HPageBreak
HPageBreaks

Sub test()
Worksheets("HPageBreak").HPageBreaks _
.Add Before:=Worksheets("HPageBreak").Range("a3")
Worksheets("HPageBreak").VPageBreaks _
.Add Before:=Worksheets("HPageBreak").Cells(3,4)
End Sub
2-16

2-16
Hyperlink
Hyperlinks
A1 HpageBreak
Sub test()
Range("A1").Select
ActiveSheet.Hyperlinks.Add Anchor:=Selection, _
Address:="", SubAddress:= _
"HPageBreak!A1", TextToDisplay:="HPageBreak"
End Sub
2-17

2-17
55

Y Excel VBA

I
Interior

Sub test()
Range("A1:B16").Select
With Selection.Interior
.ColorIndex = 8
.Pattern = xlGray16
.PatternColorIndex = xlAutomatic
End With
End Sub
2-18

2-18

L
Legend

Sub test()
ActiveSheet.ChartObjects(" 2").Activate
ActiveChart.Legend.Select
Selection.Position = xlBottom
Selection.AutoScaleFont = True
With Selection.Font
56

.Name = ""
.FontStyle = ""
.Size = 12
.Underline = xlUnderlineStyleNone
.ColorIndex = 45
.Background = xlAutomatic
End With
End Sub
2-19

2-19
LegendEntry
LegendEntries

Worksheets("sheet1").ChartObjects(1).Chart _
.Legend.LegendEntries(1).Font.Italic = True
2-20

2-20
57

Y Excel VBA
LegendKey

Sub test()
Worksheets("LegendKey").ChartObjects(1).Chart _
.Legend.LegendEntries(2).LegendKey _
.MarkerBackgroundColorIndex = 4
Worksheets("LegendKey").ChartObjects(1).Chart _
.Legend.LegendEntries(1).LegendKey _
.MarkerBackgroundColorIndex = 3
End Sub
2-21

2-21
LineFormat

myDocument
Sub test()
Set myDocument = Worksheets(1)
With myDocument.Shapes.AddLine _
(206.25, 136.5, 310.5, 136.5).Line
.DashStyle = msoLineLongDash
.Style = msoLineSingle
.ForeColor.SchemeColor = 10
58

.BeginArrowheadLength = msoArrowheadLengthMedium
.BeginArrowheadWidth = msoArrowheadWidthMedium
.BeginArrowheadStyle = msoArrowheadNone
.EndArrowheadLength = msoArrowheadLong
.EndArrowheadWidth = msoArrowheadWide
.EndArrowheadStyle = msoArrowheadStealth
End With
End Sub

N
Name

name
Sub test()
Sheets("Name").Select
Sheets("Name").Name = "NameRange"
End Sub

O
Outline
Outline Outline

Sub test()
Worksheets("Outline").Outline.ShowLevels 2
End Sub
2-22

2-22
59

Y Excel VBA

P
PageSetup

Sub test()
With ActiveSheet.PageSetup
.LeftMargin = Application.InchesToPoints(0.55)
.RightMargin = Application.InchesToPoints(0.55)
.TopMargin = Application.InchesToPoints(0.79)
.BottomMargin = Application.InchesToPoints(0.98)
.PaperSize = xlPaperA4
End With
End Sub
Pane
Panes
Microsoft Excel 4.0

Sub test()
Worksheets("Pane").Activate
ActiveWindow.Split = True
ActiveWindow.Panes(4).ScrollRow = 5
End Sub
PictureFormat
OLE

Sub test()
Selection.ShapeRange.PictureFormat.Brightne
ss=0.71
Selection.ShapeRange.PictureFormat.Contrast
=0.66
End Sub
2-23
60

2-23
PivotCache
PivotCaches
PivotCache PivotCache

Sub test()
ActiveWorkbook.PivotCaches.Add(SourceType: _
=xlDatabase, SourceData:= _
"Outline!R1C1:R15C3").CreatePivotTable
TableDestination:="[a.xls]Sheet7!R4C4" _
, TableName:="2", DefaultVersion:
=xlPivotTableVersion10
ActiveWorkbook.ShowPivotTableFieldList = True
ActiveSheet.PivotTables("2")_
.AddDataField ActiveSheet.PivotTables("
2" _
).PivotFields(""), ":", xlSum
End Sub
2-24

2-24
61

Y Excel VBA
PivotField
PivotFields
ColumnFields DataFields
HiddenFields PageFields RowFields
VisibleFields

Sub test()
ActiveSheet.PivotTables("3") _
.PivotFields(":").Function = xlCount
End Sub
2-25

2-25
PivotItem

PivotItems PivotItems PivotField

2000
Sub test()
Worksheets("sheet9").PivotTables(1) _
.PivotFields("
").PivotItems("2000").Visible = False
End Sub
PivotTable
PivotTables

AGP
Sub test()
Worksheets("PivotTable").PivotTables("
6") _
62

.PivotFields("AGP").Orientation=xlRowField
End Sub
2-26

2-26
PlotArea

Sub test()
ActiveSheet.ChartObjects(" 5").Activate
ActiveChart.PlotArea.Border.LineStyle=xlDot
ActiveChart.ChartArea.Select
With Selection.Border
.ColorIndex = 57
.Weight = 3
.LineStyle = 6
End With
End Sub
2-27

2-27
63

Y Excel VBA
Point
Points
Point
X
Sub test()
ActiveChart.SeriesCollection(1).Points(4) _
.ApplyDataLabels AutoText:=True, _
LegendKey:=False, ShowSeriesName: _
=False, ShowCategoryName:=True, _
ShowValue:=False, ShowPercentage:=False,
ShowBubbleSize:=False
End Sub
2-28

2-28
PublishObject
Web

Web
"C:\Documents and Settings\user\\PublishObject.htm"
Sub test()
With ActiveWorkbook.PublishObjects.Add
(xlSourceSheet, _
"C:\Documents and Settings\user\ _
\PublishObject.htm", "PublishObject", "", _
xlHtmlStatic, "_3082", "")
.Publish (True)
64

.AutoRepublish = False
End With
End Sub

R
Range
Excel
Worksheet
Range Font

Sub test()
With Sheet4.Range("A3:K9").Font
.Size = 14
.Bold = True
.Italic = True
.ColorIndex = 3
End With
End Sub
2-29

2-29

RecentFile
RecentFiles

Application.RecentFiles(1).Open
RecentFile
RecentFiles

65

Y Excel VBA
Sub test()
Application.RecentFiles(3).Open
End Sub
RoutingSlip

HasRoutingSlip True RoutingSlip

xlAllAtOnce
Sub test()
ActiveWorkbook.HasRoutingSlip = True
ActiveWorkbook.RoutingSlip.Delivery=xlAllAtOnce
End Sub
Range

A1:B15
PlotArea
Sub test()
range("A1:B15").Value _
=Worksheets("PlotArea").range("A1:B15").Value
End Sub

S
Series
SeriesCollection

Sub test()
ActiveSheet.ChartObjects(" 2").Activate
ActiveChart.SeriesCollection(1).Select
With Selection.Border
66

.ColorIndex = 5
.Weight = xlThin
.LineStyle = xlContinuous
End With
End Sub
2-30

2-30
SeriesLines

Sub test()
ActiveChart.ChartGroups(1).SeriesLines.Select
With Selection.Border
.ColorIndex = 8
.Weight = xlHairline
.LineStyle = xlContinuous
End With
End Sub
2-31

67

Y Excel VBA

2-31
ShadowFormat

Sub test()
Set myDocument = Worksheets("ShadowFormat")
With myDocument.Shapes.AddShape _
(msoShapeRightArrowCallout, _
80, 20, 50, 60).Shadow
.ForeColor.RGB = RGB(202, 45, 128)
.Transparency = 0
.Visible = True
End With
End Sub
2-32

2-32
Shape
OLE
Shapes
68

Sub test()
ActiveSheet.Shapes.AddShape _
(msoShapeRectangle, 159#, 207.75, 87.75,
47.25). _ Select
Selection.ShapeRange.Line.Weight = 1.25
Selection.ShapeRange.Line.Style =
msoLineSingle
Selection.ShapeRange.Line.BackColor.RGB _
= RGB(255, 255, 255)
End Sub
2-33

2-33
Sheets
Chart
Worksheet
Trendline Sheets
Sheets
Sub test()
Sheets(Array("Trendline")).Move before:=
Sheets("Sheets")
Sheets("Sheets").Activate
End Sub

T
Trendline

69

Y Excel VBA

2
Sub test()
ActiveChart.SeriesCollection(1).Select
ActiveChart.SeriesCollection(1).Trendlines. _
Add(Type:=xlMovingAvg, Period:=2 _
,Forward:=0, Backward:=0,DisplayEquation:=False, _
DisplayRSquared:=False).Select
End Sub
2-34

2-34
TextEffectFormat

36

Sub test()
ActiveSheet.Shapes.AddTextEffect _
(msoTextEffect8, "", "", 36#, msoFalse, _
msoFalse, 310.5, 183#).Select
End Sub
2-35

70

2-35
TextFrame

Sub tedsgsddfei()
Set myDocument = Worksheets("TextFrame")
With myDocument.Shapes.AddShape(msoShapeRectangle, _
50, 50, 50, 50).TextFrame
.Characters.Text = ""
End With
End Sub
2-36

2-36
ThreeDFormat
DepthParentVisible

Sub test()
Set myDocument = Worksheets("ThreeDFormat")
With myDocument.Shapes.AddShape _
(msoShapeRightArrowCallout, _
71

Y Excel VBA
80, 20, 50, 60).ThreeD
.Visible = True
.Depth = 50
.ExtrusionColor.RGB = RGB(250, 10, 100)
.ExtrusionColorType = 2
End With
End Sub
2-37

2-37
TickLabels

Sub test()
Selection.TickLabels.AutoScaleFont = True
With Selection.TickLabels.Font
.Name = ""
.FontStyle = ""
End With
Selection.TickLabels.NumberFormatLocal = "0_ "
End Sub
2-38

72

2-38

U
UpBars

1
Sub test()
ActiveSheet.ChartObjects(" 1").Activate
ActiveChart.SeriesCollection(1).Select
With ActiveChart.ChartGroups(1)
.HasUpDownBars = True
.GapWidth = 150
End With
End Sub
2-39

2-39
73

Y Excel VBA

V
VPageBreak
VPageBreaks
F1
Sub Macrsf()
ActiveWindow.SelectedSheets.VPageBreaks _
.Add Before:=Range("f1")
End Sub
2-40

2-40

W
Window

Sub Window()
Application.WindowState = xlNormal
ActiveWindow.ScrollRow = 5
End Sub
Workbook
Application Excel
Workbooks Workbook

C:\Book1.xls
Sub test()
74

Dim oExcel As Object


Dim oBook As Object
Dim oSheet As Object
Set oExcel = CreateObject("Excel.Application")
Set oBook = oExcel.Workbooks.Add
Set oSheet = oBook.Worksheets(1)
oBook.SaveAs "C:\Book1.xls"
oExcel.Quit
End Sub
Worksheets
Worksheet Worksheet
Workbook Excel
5

Sub test()
Worksheets(1).Activate
ThisWorkbook.Saved = True
ThisWorkbook.Close
End Sub

75

Workbook

A
Activate

Private Sub object_Activate()

Sheet3
Sheet1, nihao
Private Sub Worksheet_Activate()
Sheets(1).Select
Cells(ActiveCell.Row, ActiveCell.Column) =
"nihao"
End Sub

B
BeforeClose

Private Sub Workbook_BeforeClose(Cancel As Boolean)


Cancel=True
Workbook
A1:A500

Private Sub Workbook_BeforeClose(Cancel As


Boolean)
For I = 1 To 500
If Cells(I, 1).Interior.ColorIndex = 6 Then
Cells(I, 1).integerior.ColorIndex = 0
End If
Next I
77

Y Excel VBA
ActiveWorkbook.Save
MsgBox ActiveWorkbook.Name
End Sub
BeforeDoubleClick

Private Sub Worksheet_BeforeDoubleClick(ByVal Target As


Range, Cancel As Boolean)
Private Sub object_BeforeDoubleClick(ByVal ElementID As
Long, ByVal Arg1 As Long, ByVal Arg2 As Long, Cancel As Boolean)

Cancel=True Object
Cancel ElementID Arg1
Arg1 ElementID
A2 A100

Private Sub
Worksheet_BeforeDoubleClick(ByVal Target As Range,
Cancel As Boolean)
Dim S, I As Integer
S = 0
For I = 1 To 100
S = S + Cells((I - 1) * 1 + 2, 1)
Next I
Cells(ActiveCell.Row, ActiveCell.Column) = S
End Sub
BeforePrint

Private Sub Workbook_BeforePrint(Cancel As Boolean)

Cancel=True

Private Sub Workbook_BeforePrint(Cancel As


Boolean)
78

MsgBox "Print......", vbYesNo


End Sub
BeforeRightClick

Private Sub object_BeforeRightClick(Cancel As Boolean)


Private Sub Worksheet_BeforeRightClick(ByVal Target As
Range, Cancel As Boolean)

Object
Target Cancel=True

Private Sub Worksheet_BeforeRightClick(ByVal


Target As Range, Cancel As Boolean)
ActiveWindow.DisplayGridlines = False
End Sub
3-1

3-1

BeforeSave

Private Sub Workbook_BeforeSave(ByVal SaveAsUi As Boolean,


Cancel As Boolean)
SaveAsUi=True
Cancel=True

79

Y Excel VBA
Private Sub Workbook_BeforeSave(ByVal
SaveAsUI As Boolean, Cancel As Boolean)
Cells.Interior.ColorIndex = 0
End Sub

C
Calculate

Private Sub object_Calculate()

Private Sub Worksheet_Calculate()


MsgBox Cells(ActiveCell.Row - 1,
ActiveCell.Column)
End Sub
3-2

3-2

Change

Private Sub Worksheet_Change(ByVal Target As Range)


Target

1~9
80

Private Sub Worksheet_Change(ByVal Target As


Range)
If ActiveCell.Row < 10 Then
Cells(ActiveCell.Row, ActiveCell.Column). _
Interior.ColorIndex = 6
Else
MsgBox "", vbExclamation
End If
End Sub

D
Deactivate

Private Sub object_Deactivate()

Private Sub Worksheet_Deactivate()


MsgBox ActiveSheet.Name
End Sub

F
FollowHyperlink

Private Sub Worksheet_FollowHyperlink(ByVal Target As


Hyperlink)
,
Target
Hyperlink

Private Sub Worksheet_FollowHyperlink(ByVal


81

Y Excel VBA
Target As Hyperlink)
Dim F_NAME As String
F_NAME = ActiveWorkbook.Name
ActiveWindow.WindowState = xlMinimized
MsgBox ActiveWorkbook.Name
End Sub
3-3

3-3

G
GotFocus

Private Sub object_GotFocus()


ActiveX
ActiveX OLE

CommandButton1
Caption
Private Sub CommandButton1_GotFocus()
MsgBox CommandButton1.Caption
End Sub
3-4

82

3-4

L
LostFocus

Private Sub object_LostFocus()


ActiveX
ActiveX OLE

CommandButton1
Caption
Private Sub CommandButton1_GotFocus()
MsgBox CommandButton1.Caption
End Sub

M
MouseDown

Private Sub object_MouseDown(ByVal Button As Long, ByVal


Shift As Long, ByVal X As Long, ByVal Y As Long)
object
Chart Button
shift SHIFTCTRLALT
XY
83

Y Excel VBA

Private Sub Chart_MouseDown(ByVal Button As


Long, ByVal Shift As Long, ByVal x As Long, ByVal
y As Long)
If Button = 2 Then
MsgBox "X:" & x & Chr(13) & "Y:" & y
End If
End Sub
3-5

3-5

MouseMove

Private Sub object_MouseMove(ByVal X As Long, ByVal Y


As Long)
object
Chart
XY

X
200 Y
Private Sub Chart_MouseMove(ByVal Button As
Long, ByVal Shift As Long, ByVal x As Long, ByVal
y As Long)
If Button = 1 Then
84

If x > 200 Then


MsgBox "Y:" & y
End If
End If
End Sub
MouseUp

Private Sub object_MouseUp(ByVal Button As Long, ByVal


Shift As Long, ByVal X As Long, ByVal Y As Long)
object
Chart
Button shift SHIFTCTRLALT
XY

Private Sub Chart_MouseUp(ByVal Button As Long,


ByVal Shift As Long, ByVal x As Long, ByVal y As
Long)
If Button = 2 Then
MsgBox "X:" & x & Chr(13) & "Y:" & y
End If
End Sub

N
NewSheet

Private Sub Workbook_NewSheet(ByVal Sh As Object)


Sh

Private Sub Workbook_NewSheet(ByVal Sh As


Object)
ActiveSheet.Name = "NewSht"
End Sub
85

Y Excel VBA

O
Open

Private Sub Workbook_Open()

Private Sub Workbook_Open()


UserForm1.Show
End Sub
3-6

3-6

R
Resize

Private Sub object_Resize()

Chart

Private Sub Chart_Resize()


With ActiveWindow
MsgBox "Width: " & .Width & Chr(13) _
86

& "Height: " & .Height


End With
End Sub
3-7

3-7

S
SelectionChange

Private Sub Worksheet_SelectionChange(ByVal Target As


Excel.Range)
Target

12

Private Sub Worksheet_SelectionChange(ByVal


Target As Range)
If ActiveCell.Row <= 12 Then
Cells(ActiveCell.Row, ActiveCell.Column). _
Interior.ColorIndex = ActiveCell.Row
End If
End Sub
3-8
87

Y Excel VBA

3-8

SheetActivate

Private Sub object_SheetActivate(ByVal Sh As Object)


Sh

2
Private Sub Workbook_SheetActivate(ByVal Sh
As Object)
If ActiveSheet.Name = "Sheet2" Then
Sheets(1).Select
End If
End Sub
SheetBeforeDoubleClick

Private Sub object_SheetBeforeDoubleClick(ByVal Sh As


Object, ByVal Target As Range, ByVal Cancel As Boolean)
Object

Application Target
Cancel=True

Private Sub Workbook_SheetBeforeDoubleClick


(ByVal Sh As Object, ByVal Target As Range, Cancel
As Boolean)
88

Select Case activell.Column


Case 1
Call p1
Case 2
Call p2
Case 3
Call p3
Case Is > 3
Exit Sub
End Select
End Sub
SheetBeforeRightClick

Private Sub object_SheetBeforeRightClick(ByVal Sh As Object,


ByVal Target As Range, ByVal Cancel As Boolean)
Object

Application Target
Cancel=True

A1

Private Sub
Workbook_SheetBeforeRightClick(ByVal Sh As Object,
ByVal Target As Range, Cancel As Boolean)
Cells(1, 1) = ""
End Sub
SheetCalculate

Private Sub object_SheetCalculate(ByVal Sh As Object)

Object
Application
Sh
89

Y Excel VBA

Private Sub Workbook_SheetCalculate(ByVal Sh


As Object)
MsgBox Cells(ActiveCell.Row - 1,
ActiveCell.Column)
End Sub
SheetChange

Private Sub object_SheetChange(ByVal Sh As Object, ByVal


Source As Range)
Object

Application sh
Source

Private Sub Workbook_SheetChange(ByVal Sh As


Object, ByVal Target As Range)
a = 0
Do
a = a + 1
If Sheets(1).Cells(a + 1, 1) = "" Then
Sheets(1).Cells(a + 1, 1) =
ActiveSheet.Name
Exit Do
End If
Loop
End Sub
SheetDeactivate

Private Sub object_SheetDeactivate(ByVal Sh As Object)


object
Application Workbook sh

90

Private Sub Worksheet_Deactivate()


MsgBox ActiveSheet.Name
End Sub
SheetFollowHyperlink

Private Sub Application_SheetFollowHyperlink(ByVal Sh As


Object, ByVal Target As Hyperlink)
Private Sub Workbook_SheetFollowHyperlink(ByVal Sh As
Object, ByVal Target As Hyperlink)

sh Target

Private Sub Workbook_SheetFollowHyperlink


(ByVal Sh As Object, ByVal Target As Hyperlink)
Cells(ActiveCell.Row, ActiveCell.Column). _
Interior.ColorIndex = 6
End Sub
SheetSelectionChange

Private Sub object_SheetSelectionChange(ByVal Sh As


Object, ByVal Target As Excel.Range)

Object
Application
sh Target

12

91

Y Excel VBA
Private Sub Workbook_SheetSelectionChange
(ByVal Sh As Object, ByVal Target As Range)
If ActiveCell.Row <= 12 Then
Cells(ActiveCell.Row,
ActiveCell.Column).Interior.ColorIndex =
ActiveCell.Row
End If
End Sub

W
WindowActivate

Private Sub object_WindowActivate(ByVal Wb As


Excel.Workbook, ByVal Wn As Excel.Window)
Object

Application Wb
Wn

,
Private Sub Workbook_WindowActivate(ByVal Wn
As Window)
Dim wk1, wk2 As Integer
wk1 = Workbooks(1).Name
wk2 = Workbooks(2).Name
If ActiveWorkbook.Name = wk1 Then
Workbooks(wk2).Save
Else
Workbooks(wk1).Save
End If
End Sub
WindowDeactivate

Private Sub object_WindowDeactivate(ByVal Wb As


92

Excel.Workbook, ByVal Wn As Excel.Window)

Object
Application
Wb Wn

Private Sub Workbook_WindowDeactivate(ByVal


Wn As Window)
Dim a As String
a = ActiveWorkbook.Name
MsgBox "" & a & "", vbCritical
End Sub
WindowResize

Private Sub object_WindowResize(ByVal Wb As


Excel.Workbook, ByVal Wn As Excel.Window)
Object

Application Wb
Wn

Private Sub Workbook_WindowResize(ByVal Wn As


Window)
Workbooks(1).Close
End Sub

93

VBA VBA

[]. []

A
Activate

Book1.xls
way
WorkBooks(Book1.xls).Activate
ActiveSheet.Name = "way"
ActivateNext

Window
Book.xls

Workbooks("Book.xls").Activate
Sheets(Array("Sheet2", "Sheet3")).Select
Sheets("Sheet2").Activate
ActiveWindow.SelectedSheets.Delete
ActiveWindow.ActivateNext
ActivatePrevious

ActivateNext Window
Book.xls

Workbooks("Book.xls").Activate
ActiveWindow.ActivatePrevious

95

Y Excel VBA
AddCallout

. AddCallout(
)

1
nihao 12
Sheets(1).Shapes.AddCallout(msoCalloutOne, _
379.5, 208.5, 72#, 48#).Select
Selection.Characters.Text = "nihao"
With Selection.Font
.Name = ""
.Size = 12
End With
AddComment
.
AddComment(Text), Text
A1:A10

For I = 1 To 10
G = Cells(I, 1)
Range("A" & I).AddComment G
Next I
AddConnector
BeginConnect EndConnect
. AddConnector
X Y X
Y XY

ActiveSheet.Shapes.AddConnector(msoConnectorSt
raight, _
173.25, 249.75, 135#, 7.5).Select
96

AddFormControl
Excel . AddFormControl

My Control
ActiveSheet.Shapes.AddFormControl _
(xlButtonControl, 120, 150, 75#, 50#).Select
Selection.Caption = "My Control"
4-1

4-1

AddItem
.
AddItem
ControlFormat

6
ActiveSheet.Shapes.AddFormControl _
(xlDropDown, 120, 150, 75#, 20#).Select
Selection.AddItem "A", 1
Selection.AddItem "B", 2
Selection.AddItem "C", 3
Selection.AddItem "D", 4
Selection.AddItem "E", 5
Selection.AddItem "F", 6
4-2
97

Y Excel VBA

4-2

AddLabel
. AddLabel

NIHAO 20
ActiveSheet.Shapes.AddLabel(msoTextOrientation
Horizontal, _
93#, 267.75, 0#, 0#).Select
Selection.Characters.Text = "NIHAO"
With Selection.Font
.Size = 20
End With
Selection.Font.Bold = True
Selection.Font.Italic = True
Selection.Font.Underline =
xlUnderlineStyleSingle
AddLine
. AddLine( X
Y X , Y ) X
Y

98

7859231190
ActiveSheet.Shapes.AddLine(78, 59, 231,
190).Select
AddNodes

. AddNodes
X1
Y1 X2
Y2 XY

With
ActiveSheet.Shapes.BuildFreeform(msoEditingAuto,
465.75, 123.75)
.AddNodes msoSegmentLine, msoEditingAuto, 597.75,
122.25
.AddNodes msoSegmentLine, msoEditingAuto, 581.25,
253.5
.AddNodes msoSegmentLine, msoEditingAuto, 415.5,
243.75
.AddNodes msoSegmentLine, msoEditingAuto, 465.75,
123.75
.ConvertToShape.Select
End With
AddPicture

. AddPicture

1
Worksheets(1).Shapes.AddPicture "E:\123.JPG", _
True, True, 100, 100, 100, 100
99

Y Excel VBA
AddShape
. AddShape

Excel
139
16

ActiveSheet.Shapes.AddShape(msoShape16point
Star, _
249#, 111.75, 72#, 72#).Select
Selection.ShapeRange.Fill.ForeColor.
SchemeColor=13
Selection.Characters.Text = "NIHAO"
AddTextbox
. AddTextbox

NIHAO
ActiveSheet.Shapes.AddTextbox(msoTextOrient
ationHorizontal, _
153#, 176.25, 282.75, 75.75).Select
Selection.Characters.Text = "NIHAO"
With Selection
.HorizontalAlignment = xlCenter
.VerticalAlignment = xlCenter
End With
Selection.Font.Underline = xlUnderline
StyleSingle
AddTextEffect
. AddTextEffect

100

Excel 30
msoTextEffect1msoTextEffect2msoTextEffect30

NIHAO
ActiveSheet.Shapes.AddTextEffect(msoTextEff
ect1,_
"NIHAO", "", 28#, msoTrue, _
msoTrue, 327#, 191.25).Select
Align

. Align(False) 6
ShapeRange

ActiveSheet.Shapes(1).Select
Selection.ShapeRange.Ungroup.Select
Worksheets(1).Shapes.SelectAll
Selection.ShapeRange.Align msoAlignRights,
False
4-3

4-3

AutoFilter
. AutoFilter(

)
101

Y Excel VBA

1 15 2 30

Rows("1:1").Select
Selection.AutoFilter
Selection.AutoFilter Field:=1, _
Criteria1:=">15", Operator:=xlAnd
Selection.AutoFilter Field:=2, _
Criteria1:="<30", Operator:=xlAnd
Apply
PickUp
. Apply

Worksheets(1).Shapes(1).PickUp
Worksheets(1).Shapes(2).Apply
ApplyCustomType

. ApplyCustomType(
)

Charts(1).ApplyCustomType xlXYScatter
Arrange
.
Arrange

Windows.Arrange ArrangeStyle:=xlHorizontal
Windows.Arrange ArrangeStyle:=xlVertical
Windows.Arrange ArrangeStyle:=xlCascade
4-4
102

4-4

AutoFill

. AutoFill(,
)
A1A2 A1
A24
Range("A1:A2").Select
Selection.AutoFill Destination:= _
Range("A1:A24"), Type:=xlFillDefault
AutoFit
. AutoFit

1 7

Rows("1:7").Select
Rows("1:7").EntireRow.AutoFit
AutoFormat
. AutoFormat(

)
A1:D12
Range("A1:D12").Select
103

Y Excel VBA
Selection.AutoFormat Format:= xlRangeAuto
FormatClassic3
4-5

4-5

B
BarGroups

. BarGroups(). BarGroups

0
ActiveChart.SeriesCollection(1).Select
With ActiveChart.ChartGroups(1)
.GapWidth = 0
End With
4-6

4-6
104

BeginConnect

. BeginConnect(
)

ActiveSheet.Shapes.AddConnector(msoConnecto
rCurve, _
144#, 156#, 253.5, 114.75).Select
Selection.ShapeRange.ConnectorFormat.
BeginConnect _
ActiveSheet.Shapes("Rectangle 1"), 2
Selection.ShapeRange.ConnectorFormat.
EndConnect _
ActiveSheet.Shapes("Rectangle 2"), 3
4-7

4-7

BeginDisconnect

. BeginDisconnect

4-7

ActiveSheet.Shapes.AddConnector(msoConnectorCu
rve, _
105

Y Excel VBA
144#, 156#, 253.5, 114.75).Select
Selection.ShapeRange.ConnectorFormat.
BeginConnect _
ActiveSheet.Shapes("Rectangle 1"), 2
Selection.ShapeRange.ConnectorFormat.
EndConnect_
ActiveSheet.Shapes("Rectangle 2"), 3
Selection.ShapeRange.ConnectorFormat.BeginD
isconnect
Selection.ShapeRange.ConnectorFormat.
EndDisconnect
BorderAround

. BorderAround(
)
, 8 xlContinuous 4
xlThin
RGB 3

10

A = 0
Do
A = A + 1
Cells(Int(Rnd() * 10) + 1, A).BorderAround ,
xlMedium, 6
If A > 10 Then
Exit Do
End If
Loop
4-8

106

4-8

BringToFront
. BringToFront
ChartObject OleObject

Worksheets(2).ChartObjects(1).BringToFront
4-9

4-9

BuildFreeform
. BuildFreeform
X
YXY

With ActiveSheet.Shapes.BuildFreeform
(msoEditingAuto, 105.75, 102#)
.AddNodes msoSegmentLine, msoEditingAuto,
114.75, 203.25
107

Y Excel VBA
.AddNodes msoSegmentLine,
294#, 214.5
.AddNodes msoSegmentLine,
312.75, 90.75
.AddNodes msoSegmentLine,
210#, 149.25
.AddNodes msoSegmentLine,
56.25
.AddNodes msoSegmentLine,
105.75, 102#
.ConvertToShape.Select
End With

msoEditingAuto,
msoEditingAuto,
msoEditingAuto,
msoEditingAuto,87#,
msoEditingAuto,

C
Calculate

Application.Calculate Range.Calculate
. Calculate
A2:E8
Range("A2:E8").Calculate
ChangeFileAccess

. ChangeFileAccess

xlReadWrite

1
xlReadWrite 123
Workbooks(1).ChangeFileAccess xlReadWrite,
"123"
CentimetersToPoints
1 =0.035
. CentimetersToPoints()
5 0.1~0.5
108

For I = 1 To 5
ActiveSheet.Shapes(I).Select
Selection.ShapeRange.Line.Weight = _
Application.CentimetersToPoints(I / 10)
Next I
4-10

4-10
Characters

. Characters(
)

ActiveSheet.Shapes("Rectangle 1").Select
Selection.Characters.Text = ""
ChartGroups
1 .
ChartGroups() 2 . ChartGroups

MsgBox Charts("Graph1").ChartGroups.Count
4-11
109

Y Excel VBA

4-11
ChartObjects

1 . ChartObjects() 2 . ChartObjects

C = ActiveSheet.ChartObjects.Count
For I = 1 To C
ActiveSheet.ChartObjects(I).Activate
ActiveChart.ChartType = xlLineMarkers
Next I
ChartWizard

. ChartWizard
1-10/

Chart
B2 B8
2
ActiveSheet.ChartObjects(1).Activate
ActiveChart.ChartWizard Source:=Range
110

("b2:b8"), _
gallery:=xl3DLine, Format:=2,
PlotBy:=xlColumns
Clear

. Clear
A1:A10

For I = 1 To 10
If Cells(I, 1).Interior.ColorIndex = 6 Then
Cells(I, 1).Clear
End If
Next I
ClearComments

.ClearComments
A1
Worksheets(1).Range("A1").ClearComments
ClearContents

.ClearContents
A1:D20

Worksheets(1).Range("A1:D20"). ClearContents
ClearFormats
. ClearFormats
A1:D20

Worksheets(1).Range("A1:D20"). ClearFormats
ClearNotes
.ClearNotes
111

Y Excel VBA

G9
Range("G9").ClearNotes
ClearOutline
. ClearOutline
2 10
Worksheets(1).Rows("2:10").ClearOutline
Close
1 . Close
Workbooks 2 . Close

Workbooks(2).Activate
Columns("A:A").Select
Selection.Copy
Workbooks(1).Activate
Cells(1, 1).Select
ActiveSheet.Paste
Workbooks(2).Close
Copy
1 . Copy;
2 . Copy() 3 .
Copy(, )

1
2
Workbooks(2).Activate
Sheets(1).Select
Range("A1:D10").Select
Selection.Copy
Workbooks(1).Activate
112

Sheets(1).Select
Range("A1").Select
ActiveSheet.Paste
Book3 A
Book2 1
Windows("Book3").Activate
Sheets("A").Select
Sheets("A").Copy
Before:=Workbooks("Book2").Sheets(1)
CopyPicture

.CopyPicture

Bmp
ActiveSheet.Shapes(1).Select
Selection.CopyPicture xlScreen, xlBitmap
Cells(1, 1).Select
ActiveSheet.Paste
CustomDrop

.CustomDrop() CalloutFormat

h = ActiveSheet.Shapes("AutoShape 1").Height
ActiveSheet.Shapes("AutoShape 1"). _
Callout.CustomDrop h / 2
Cut
. Cut

A1:D4 F1:I4

113

Y Excel VBA
Range("A1:D1").Cut
Range("F1").Select
ActiveSheet.Paste

D
DataLabels

1 . DataLabels(
) 2 . DataLabels

ActiveChart.SeriesCollection(2).ApplyDataLabel
s Type:=xlDataLabelsShowLabel, _
AutoText:=True, LegendKey:=False
DataSeries

. DataSeries(
)

+10
Private Sub Workbook_SheetSelectionChange _
(ByVal Sh As Object, ByVal Target As Range)
A = Cells(ActiveCell.Row, ActiveCell.Column)
ActiveCell.DataSeries Rowcol:=xlColumns, _
Step:=1, Stop:=A + 10
End Sub
Delete
1 . Delete
Point LegendKey 2
. Delete()xlShiftUp
xlShiftToLeft

A = 0
c = 0
114

Do
A = A + 1
lp1:
If Cells(A, 1) = "" Then
c = c + 1
Rows(A).Delete Shift:=xlUp
GoTo lp1
End If
Loop
MsgBox "" & c & ""
Deselect
. Deselect

ActiveSheet.ChartObjects(1).Activate
ActiveChart.ChartArea.Select
ActiveChart.Deselect
DoubleClick

Application . DoubleClick
C2
Cells(2, 3).Select
Application.DoubleClick
Duplicate

. Duplicate

ActiveSheet.Shapes(1).Duplicate
4-12

4-12
115

Y Excel VBA

E
EndConnect

.EndConnect(
) ConnectorFormat

ActiveSheet.Shapes.AddConnector(msoConnectorSt
raight, _
135#, 117.75, 6.75, 103.5).Select
Selection.ShapeRange.Flip msoFlipHorizontal
Selection.ShapeRange.Flip msoFlipVertical
Selection.ShapeRange.ConnectorFormat.EndConnect _
ActiveSheet.Shapes("Rectangle 1"), 3
EndDisconnect

. EndDisconnect
ConnectorFormat

ActiveSheet.Shapes("AutoShape 10").Select
Selection.ShapeRange.ConnectorFormat.EndDisconnect
ErrorBar
. ErrorBar(
)

ActiveChart.SeriesCollection(1).Select
ActiveChart.SeriesCollection(1).ErrorBar _
Direction:=xlY, Include:=xlMinusValues, _
Type:=xlFixedValue, Amount:=0.005
116

ExecuteExcel4Macro
Microsoft Excel 4.0

. ExecuteExcel4Macro( Microsoft Excel


4.0 ) CR

MsgBox ExecuteExcel4Macro("LEFT(""QWERT"",2)")
4-13

4-13
Export
.
Export(
)

JPG 123
Worksheets(3).ChartObjects(1).Chart.Export
Filename:="123.JPG"
Extend

.Extend/
SeriesCollection

A1 A10
ActiveSheet.ChartObjects(1).Chart. _
SeriesCollection.Extend Range("A1:A10")

117

Y Excel VBA

F
FillAcrossSheets

. FillAcrossSheets

2
3
Sheets(Array("Sheet1", "Sheet2",
"Sheet3")).FillAcrossSheets _
Worksheets(1).Range("A1")
FillDown

. FillDown
A1:B1
A10:B10
Range("A1:B10").FillDown
FillLeft

. FillLeft
J1:J2
A1:A2
Range("J1:A2"). FillLeft
FillRight

. FillRight
A1 J1
Range("A1:J1").FillRight
FillUp

. FillUp
118

A
A1
Cells(65536, 1).Select
Selection.End(xlUp).Select
Cells(ActiveCell.Row + 1, 1).Select
Range(Cells(ActiveCell, Row, 1), Cells(1,
1)).FillUp
Find

. Find

A1 A1000
OK
Range("A1:A1000").Find("OK").Activate
ActiveCell.Interior.ColorIndex = 6
FindFile
,
.FindFile
D:\123.xls,
A1 A1
Dim f0, f1 As String
f0 = ActiveWorkbook.Name
Application.FindFile
f1 = ActiveWorkbook.Name
Workbooks(f0).Sheets(1).Cells(1, 1) = Cells(1,
1)
ActiveWorkbook.Close
FindNext
Find
Range
. FindNext()
119

Y Excel VBA

A NG

Columns("A:A").Select
Selection.Find(What:="NG", After:=
ActiveCell, _
LookIn:=xlFormulas, LookAt:=xlPart, _
SearchOrder:=xlByRows,
SearchDirection:=xlNext, _
MatchCase:=False).Activate
Selection.FindNext(After:=
ActiveCell).Activate
FindPrevious
Find
Range . FindPrevious(
)
A OK

Columns("A:A").Select
Selection.Find(What:="OK", After:=
ActiveCell, _
LookIn:=xlFormulas, LookAt _
:=xlPart, SearchOrder:=xlByRows, _
SearchDirection:=xlNext, MatchCase:=
False).Activate
Selection.FindNext(After:= ActiveCell).
Activate
Cells(2, 2) = ActiveCell.Row
Selection.FindNext(After:= ActiveCell).
Activate
Cells(3, 2) = ActiveCell.Row
Selection.FindPrevious(After:= Active
Cell) .Activate
Cells(4, 2) = ActiveCell.Row
120

4-14

4-14
Flip

. Flip()
msoFlipHorizontal
msoFlipVertical

ActiveSheet.Shapes("AutoShape 5").Select
Selection.ShapeRange.Flip msoFlipVertical
FunctionWizard
. FunctionWizard

Cells(4, 4).FunctionWizard
4-15

4-15
121

Y Excel VBA

G
GetOpenFilename

. GetOpenFilename(
)

A1
100
Dim f0, f1, f_path As String
Dim i, j As Integer
f0 = Application.GetOpenFilename()
f_path = CurDir(f0)
With Application.FileSearch
.LookIn = Fz_PATH
.Filename = "*.xls"
If .Execute() > 0 Then
For i = 1 To .FoundFiles.Count
Workbooks.Open
Filename:=.FoundFiles(i)
f1 = ActiveWorkbook.Name
C = Sheets.Count
For j = 1 To C
Sheets(j).Cells(1, 1) = 100
Next j
Workbooks(f1).Save
Workbooks(f1).Close
Next i
End If
End With
GetSaveAsFilename

. GetSaveAsFilename(
)
122

Dim f0 As String
f0 = Application.GetSaveAsFilename()
Workbooks(1).SaveAs Filename:=f0
Goto
Application. Goto(
)
2 A1
Application.Goto (Sheets(2).Cells(1, 1))
Group 1
. Group

3
ActiveSheet.Shapes("Line 14").Select
ActiveSheet.Shapes("Rectangle 13").Select
ActiveSheet.Shapes.Range(Array("Rectangle
13", "Line 14")).Select
Selection.ShapeRange.Group
Group 2
. Group

2 20
Rows("2:20").Select
Selection.Rows.Group
4-16

123

Y Excel VBA

4-16

H
Help
. Help

Application.Help "XLTIP9.HLP"

I
InchesToPoints
. InchesToPoints

3
MsgBox Application.InchesToPoints(3)
IncrementBrightness
. IncrementBrightness
0 0 1.0

ActiveSheet.Shapes("Picture 13").Select
Selection.ShapeRange.PictureFormat. _
IncrementBrightness 0.4
124

IncrementContrast
. IncrementContrast
0 0 1

ActiveSheet.Shapes("Picture 13").Select
Selection.ShapeRange.PictureFormat.IncrementContra
st 0.3
IncrementLeft
. IncrementLeft
0

ActiveSheet.Shapes("Picture 13").Select
Selection.ShapeRange.IncrementLeft 0.75
IncrementOffsetX
.
IncrementOffsetX 0

ActiveSheet.Shapes("Picture 1").Select
Selection.ShapeRange.Shadow.IncrementOffset
X -1#
IncrementOffsetY
. Increment OffsetX
0
IncrementOffsetX
IncrementRotationX
X
. IncrementRotationX X
125

Y Excel VBA
-90 90 0 0
X
Y
ActiveSheet.Shapes("Rectangle 1").Select
Selection.ShapeRange.ThreeD.Visible =
msoTrue
Selection.ShapeRange.ThreeD.Increment
RotationX -5#
Selection.ShapeRange.ThreeD.Increment
RotationY 5#
IncrementTop
. IncrementTop
0
0
IncrementLeft
InputBox

Application.InputBox(
X Y
)
, A=123
Dim a As String
a = InputBox("hello!", "Title", "123")
4-17

4-17
Insert

126

10
Rows("10").Select
Selection.Insert Shift:=xlDown
Item

2
Workbooks.Item(2).Activate

ActiveSheet.Shapes.Item(2).Select

J
Justify

. Justify

A1
Range("A1").Justify

L
LargeScroll
. LargeScroll

3
ActiveWindow.LargeScroll toright:=3
List

. List
1
MsgBox ListBox1.List(0)
127

Y Excel VBA
Location
. Location

ActiveChart.ChartArea.Select
ActiveChart.Location Where:= _
xlLocationAsObject, Name:="Sheet1"

M
Merge
. Merge

B14 F26
Range("B14:F26").Select
Selection.Merge
Move
. Move

1 4
Sheets("Sheet1").Select
Sheets("Sheet1").Move After:=Sheets(4)

N
NewSeries
. NewSeries

ActiveChart.SeriesCollection.NewSeries
ActiveChart.SeriesCollection(2).Values=
"=Sheet1!R2C1:R7C1"
NewWindow
128

.NewWindow
Book4.xls
ActiveWorkbook.NewWindow
4-18

4-18
Next
. Next

A4
nihao
Range("A4").Comment.Next.Text "nihao"
NoteText

.NoteText()
255
B5
nihao
Cells(5, 2).NoteText "nihao"

O
OnKey
. OnKey(
)
129

Y Excel VBA
A
Dim G As String
G = MsgBox("HELLO", vbExclamation)
Application.OnKey "A", "G"
OnTime

. OnTime

A1
Sub wer()
Application.OnTime Now + TimeValue("00:00:02"),
"wer"
Cells(1, 1) = Time
End Sub
OnUndo
.
OnUndo

Sub jk()
MsgBox "", vbInformation
End Sub
Sub jl()
Application.OnUndo "back", "Book.xls!jk"
End Sub
Open
. Open

Workbooks.Open Filename:="D:\Book1.xls"
130

OpenText
Excel
. OpenText

5 (
)
Workbooks.OpenText Filename:="D:\# 64M.DVO", _
StartRow:=1, DataType:=xlDelimited,
TextQualifier:= _
xlDoubleQuote, ConsecutiveDelimiter:=False,
Tab:=True, _
Semicolon:=False, Comma:=True, Space:=False,
Other:=False, _
FieldInfo:=Array(Array(1, 1), Array(2, 1), _
Array(3, 1), Array(4, 1), Array(5, 1))

P
Paste

A1
A1
Cells(1, 1).Select
Selection.Copy
Workbooks.Open Filename:="D:\Book1.xls"
Sheets(1).Select
Cells(1, 1).Select
ActiveSheet.Paste
Application.CutCopyMode = False
PasteSpecial

A1 A2
131

Y Excel VBA
Range("A1").Select
Selection.Copy
Range("B1").Select
Selection.PasteSpecial Paste:=xlFormulas
Patterned
. Patterned()
49

ActiveSheet.Shapes(1).Select
Selection.ShapeRange.Fill.Patterned
msoPatternDashedUpwardDiagonal
PointsToScreenPixelsX

. PointsToScreenPixelsX

Dim A, B As Long
Dim C, D As Long
A = ActiveWindow.PointsToScreenPixelsX
(ActiveWindow.Left)
B = ActiveWindow.PointsToScreenPixelsX
(ActiveWindow.Top)
MsgBox "X: " & A & " , " & "Y: " & B
4-19

4-19

132

PointsToScreenPixelsY

. PointsToScreenPixelsY

PointsToScreenPixelsX
PresetDrop

.PresetDrop
3
msoCalloutDropBottom
msoCalloutDropCenter
msoCalloutDropTop

ActiveSheet.Shapes(1).Callout.PresetDrop
msoCalloutDropTop
PresetGradient

. PresetGradient

Selection.ShapeRange.Fill.PresetGradient
msoGradientDiagonalUp, 1, _
MsoGradientDaybreak
4-20

4-20
133

Y Excel VBA
PresetTextured

. PresetTextured 25

Selection.ShapeRange.Fill.PresetTextured
msoTextureBlueTissuePaper
4-21

4-21
Previous
. Previous

C14
HELLO
Range("C14").Comment.Previous.Text "HELLO"
PrintOut
. PrintOut

1~10
ActiveWindow.PrintOut 1, 10
PrintPreview
. PrintPreview

134

ActiveWindow.SelectedSheets.PrintPreview
Protect

. Protect

ActiveSheet.Protect

Q
Quit
Microsoft Excel Application. Quit

Excel
Dim xlsapp As Excel.Application
Dim wkapp As Excel.Workbook
Set xlsapp = CreateObject("Excel.Application")
Set wkapp =
xlsapp.Workbooks.Open("D:\Book1.xls")
wkapp.Close
xlsapp.Quit
Set xlsapp = Nothing

R
RangeFromPoint
.
RangeFromPoint

ActiveWindow.RangeFromPoint(200, 150).Select
135

Y Excel VBA
Selection.Interior.ColorIndex = 6
Regroup
. Regroup

ActiveSheet.Shapes(1).Select
Selection.ShapeRange.Ungroup.Select
Selection.ShapeRange.Regroup.Select
RemoveAllItems
Microsoft Excel
. RemoveAllItems ControlFormat
Microsoft Excel

ActiveSheet.Shapes(1).Select
ActiveSheet.Shapes(1).ControlFormat.RemoveAllI
tems
RemoveItem
.
RemoveItem
+

Sheets(1).ListBox1.RemoveItem , 1
*
Replace
. Replace

A 1 2
Columns("A:A").Select
ActiveCell.Replace What:="1", Replacement:
="2", _
LookAt:=xlPart, SearchOrder:=xlByRows
136

ResetAllPageBreaks

. ResetAllPageBreaks
1
Worksheets(1).ResetAllPageBreaks
ActiveWorkbook.PrintOut
ResetColors

. ResetColors
2
Workbooks(2).ResetColors
ResetRotation

. ResetRotation

Selection.ShapeRange.ScaleWidth 2.06, _
msoFalse, msoScaleFromTopLeft
Selection.ShapeRange.ScaleHeight 2.03, _
msoFalse, msoScaleFromBottomRight
Selection.ShapeRange.ThreeD.ResetRotation
Run
. Run

Book1.xls
Application.Run "Book1!Macro3"
RunAutoMacros
. RunAutoMacros

Auto_Open
Auto_Close
Auto_Activate
Auto_Deactivate
137

Y Excel VBA

Workbooks.Open Filename:="D:\Book1.xls"
Workbooks(2).RunAutoMacros xlAutoOpen
S
Save
. Save
Book1.xls
Dim xlsapp As Excel.Application
Dim wkapp As Excel.Workbook
Dim shtapp As Excel.Worksheet
Set xlsapp = CreateObject("Excel.Application")
Set wkapp =
xlsapp.Workbooks.Open("D:\Book1.xls")
Set shtapp = wkapp.Sheets(1)
shtapp.Cells(1, 1) = "Word"
wkapp.Save
wkapp.Close
xlsapp.Quit
Set xlsapp = Nothing
SaveAs
. SaveAs

D:\Book1.xls
ActiveWorkbook.SaveAs Filename:="D:\Book1.xls"
SaveCopyAs

d:\1.xls
ActiveWorkbook.SaveCopyAs "D:\1.xls"

138

SaveWorkspace

. SaveWorkspace
d:\2.xls
Application.SaveWorkspace "d:\2.xls"
ScaleHeight

.ScaleHeight

Selection.ShapeRange.ScaleWidth 2, _
msoFalse, msoScaleFromTopLeft
Selection.ShapeRange.ScaleHeight 2, _
msoFalse, msoScaleFromBottomRight
ScaleWidth

.ScaleWidth

ScaleHeight
Select
. Select
A1 A3
Cells(1, 1).Select
Selection.Copy
Cells(3, 1).Select
ActiveSheet.Paste
Application.CutCopyMode = False
SelectAll
. SelectAll

Sheets(1).Shapes.SelectAll
Selection.ShapeRange.Group
139

Y Excel VBA
SetBackgroundPicture

. SetBackgroundPicture

ActiveSheet.SetBackgroundPicture Filename:= _
"C:\ 011.jpg"
SetSourceData
. SetSourceData(
)

Range("G1,G4:G28").Select
Charts.Add
ActiveChart.ChartType = xlColumnClustered
ActiveChart.SetSourceData Source:= _
Sheets("Sheet1").Range("G1,G4:G28"), _
PlotBy:=xlColumns
Show
. Show

UserForm1.Show

Application.Dialogs(1).Show
Sort
. Sort

/
4 28 A
B
Rows("4:28").Select
Selection.Sort Key1:=Range("A4"), _
Order1:=xlAscending, Key2:=Range("B4") _
140

, Order2:=xlDescending, Header:=xlGuess, _
OrderCustom:=1, MatchCase:= _
False, Orientation:=xlTopToBottom, _
SortMethod:=xlPinYin

T
Text
. Text

ActiveSheet.Shapes("Rectangle 1").Select
Selection.Characters.Text = "123456789"
Range("E12").Comment.Text Text:="123456789"
Range("E14").Select
TextToColumns

.TextToColumns

D
Columns("D:D").Select
Selection.TextToColumns Destination:= _
Range("D1"), DataType:=xlFixedWidth, _
FieldInfo:=Array(Array(0, 1), Array(1, 1))
ToggleVerticalText
.
ToggleVerticalText

Selection.ShapeRange.TextEffect.ToggleVertical
Text
141

Y Excel VBA
Trendlines

. Trendlines

ActiveSheet.ChartObjects(" 1").Activate
ActiveChart.SeriesCollection(1).Select
ActiveChart.SeriesCollection(1).
Trendlines.Add _
(Type:=xlLogarithmic, Forward _
:=0, Backward:=0, DisplayEquation:=False, _
DisplayRSquared:=False).Select
ActiveChart.SeriesCollection(1).
Trendlines(1).Select
4-22

4-22
TwoColorGradient
.
TwoColorGradient 6
1~4

1
142

ActiveSheet.Shapes.AddShape(msoShapeRectang
le,_
132.75, 109.5, 72#, 72#).Select
Selection.ShapeRange.Fill. _
TwoColorGradient msoGradientVertical, 1

U
Undo

.Undo

Application.Undo
Ungroup
. Ungroup Shape
ShapeRange

ActiveSheet.Shapes.Range(Array("Rectangle 1", _
"Rectangle 2", "Oval 3")).Select
Selection.ShapeRange.Group.Select
Selection.ShapeRange.Ungroup.Select
Union

. Union 1 2
A1:B4 E1:I4

Application.Union(Range("A1:B4"), _
Range("E1:I4")).Select
Selection.Interior.ColorIndex = 6
A6:B9 E6:I9

Range("A6:B9", "E6:I9").Select
Selection.Interior.ColorIndex = 6
143

Y Excel VBA
4-23

4-23
UnMerge

.UnMerge
A1:F10
Range("A1:F10").Select
Selection.Merge
Selection.UnMerge
Unprotect

. Unprotect

ActiveSheet.Unprotect
UserPicture

.UserPicture

ActiveSheet.Shapes(1).Fill. UserPicture
"d:\tu.bmp"

144

UserTextured
.
UserTextured

ActiveSheet.Shapes(1").Fill. UserTextured
"d:\tu.bmp"
UserPicture UserTextured
4-24

4-24

V
Volatile

. Volatile()
CPK
Function CPK(AVE, S, UCL, LCL)
Application.Volatile (True)
CP = (UCL - LCL) / (6 * S)
K = Abs((UCL + LCL) - 2 * AVE) / (UCL - LCL)
CPK = (1 - K) * CP
End Function

W
Wait

.Wait(
) Microsoft Excel

5
145

Y Excel VBA
If Application.Wait(Now + TimeValue("00:00:05"))
Then
Workbooks(2).Close
End If

X
XYGroups
. XYGroups()

MsgBox ActiveChart.XYGroups.Count

Z
ZOrder
. ZOrder(
) msoBringForward msoBring
ToFrontmsoSendBackwardmsoSendToBack

ActiveSheet.Shapes(1).Select
Selection.ShapeRange.ZOrder msoBringForward

146

Y Excel VBA
Vba

A
ActiveCell

Cells(10000, 1).Select
Selection.End(xlUp).Select
Cells(ActiveCell.Row + 1, 1).Select
ActiveChart

ActiveSheet.ChartObjects(1).Activate
ActiveChart.SeriesCollection(1).Select
With Selection.Interior
.ColorIndex = 8
End With
ActiveSheet

MsgBox ActiveSheet.Name
ActiveWindow

ActiveWindow.WindowState = xlMaximized

148

ActiveWorkbook

ActiveWorkbook.Close
AddIndent

Range("D8").Select
With Selection
.HorizontalAlignment = xlJustify
.VerticalAlignment = xlBottom
.AddIndent = False
End With
Address

MsgBox ActiveCell.Address
5-1

5-1

Areas

Range("C4:D8,E11:E15,G7:H11,C20:D23,F28:G34")
.Select
MsgBox Selection.Areas.Count
149

Y Excel VBA
AutoFilter

G -20
Columns("G:G").Select
Selection.AutoFilter
Selection.AutoFilter Field:=1, Criteria1:
="-20"
AutoFilterMode

G -20

Columns("G:G").Select
Selection.AutoFilter
Selection.AutoFilter Field:=1, Criteria1:=
"-20.1"
Rows("5:1195").Select
Selection.Copy
Sheets("Sheet3").Select
Range("A1").Select
ActiveSheet.Paste
Sheets("Sheet2").Select
Worksheets(2).AutoFilterMode = False
AutoScaleFont

ActiveSheet.ChartObjects(1).Activate
ActiveChart.ChartTitle.AutoScaleFont = True
AutoScaling

ActiveSheet.ChartObjects(1).Activate
ActiveChart.AutoScaling = True
150

AutoShapeType

ActiveSheet.Shapes.AddShape(msoShapeOval,
117.75, 241.5, 211.5, 108#). _
Select
ActiveSheet.Shapes(1).AutoShapeType =
msoShapeRectangle
AutoSize

ActiveSheet.Shapes.AddLabel(msoTextOrientatio
nHorizontal, _
207.75, 165.75, 0#, 0#).Select
Selection.ShapeRange(1).TextFrame.AutoSize =
msoTrue
AutoText

ActiveChart.SeriesCollection(1).Select
ActiveChart.SeriesCollection(1).DataLabels.Se
lect
Selection.AutoText = True
5-2

5-2

151

Y Excel VBA
AxisTitle

xy
ActiveChart.ChartArea.Select
With ActiveChart
.Axes(xlCategory, xlPrimary).AxisTitle _
.Characters.Text = "AB"
.Axes(xlValue, xlPrimary).AxisTitle. _
Characters.Text = "C"
End With

B
BackColor

With CommandButton1
If .Caption = "" Then
.BackColor = &HFF&
.Caption = ""
Else
.BackColor = &HFFFF&
.Caption = ""
End If
End With
Background

x
Selection.AutoScaleFont = True
With Selection.Font
.Background = xlTransparent
End With

152

Backward

0.5
ActiveChart.SeriesCollection(1).Select
ActiveChart.SeriesCollection(1).Trendlines.Ad
d(Type:=xlLinear, _
Backward:=0.5).Select
BarShape

xlBox
xlConeToMax
xlConeToPoint
xlCylinder
xlPyramidToMax
xlPyramidToPoint

ActiveSheet.ChartObjects(1).Activate
ActiveChart.SeriesCollection(1).Select
Selection.BarShape = xlConeToPoint
BaseUnit

xlDays

xlMonths
xlYears

ActiveChart.PlotArea.Select
With ActiveChart
.HasAxis(xlCategory, xlPrimary)=True
.HasAxis(xlValue, xlPrimary) = True
.Axes(xlCategory).BaseUnit = xlMonths
End With
153

Y Excel VBA
BeginArrowheadLength
LineFormat :
msoArrowheadLengthMedium
msoArrowheadLong
msoArrowheadShort

ActiveSheet.Shapes("Line 1").Select
Selection.ShapeRange.Line.BeginArrowheadLengt
h _
= msoArrowheadShort
BeginArrowheadStyle

LineFormat
msoArrowheadDiamond
msoArrowheadNone
msoArrowheadOpen
msoArrowheadOval
msoArrowheadStealth
msoArrowheadStyleMixed
msoArrowheadTriangle

ActiveSheet.Shapes("Line 1").Select
Selection.ShapeRange.Line.BeginArrowheadStyle
= msoArrowheadDiamond
ActiveSheet.Shapes("Line 2").Select
Selection.ShapeRange.Line.BeginArrowheadStyle
= msoArrowheadOval
ActiveSheet.Shapes("Line 3").Select
Selection.ShapeRange.Line.BeginArrowheadStyle
= msoArrowheadTriangle
ActiveSheet.Shapes("Line 4").Select
Selection.ShapeRange.Line.BeginArrowheadStyle
= msoArrowheadStealth
154

ActiveSheet.Shapes("Line 5").Select
Selection.ShapeRange.Line.BeginArrowheadStyle
= msoArrowheadOpen
5-3

5-3

BeginArrowheadWidth
LineFormat
:
msoArrowheadNarrow
msoArrowheadWide
msoArrowheadWidthMedium
msoArrowheadWidthMixed

Selection.ShapeRange.Line.BeginArrowheadWid
th _
= msoArrowheadWide
BlackAndWhite
True
PageSetup

ActiveSheet.PageSetup.BlackAndWhite = True
Bold

Font
A1:A20 56 100
56 100
155

Y Excel VBA
For I = 1 To 50
If Cells(I, 1) > 56 And Cells(I, 1) < 100 Then
Cells(I, 1).Font.Bold = True
ElseIf Cells(I, 1) < 56 Then
Cells(I, 1).Font.Italic = True
Else
Cells(I, 1).Font.Underline = _
xlUnderlineStyleSingle
End If
Next I
Border

ActiveSheet.ChartObjects(1).Activate
ActiveChart.ChartArea.Select
With Selection.Border
.ColorIndex = 3
.Weight = 4
End With
5-4

5-4

Borders

BordersxlTop
156

A1 A100

Max = Cells(1, 1)
Min = Cells(1, 1)
For I = 1 To 100
If Cells(I, 1) > Max Then
Max = Cells(I, 1)
End If
If Cells(I, 1) < Min Then
Max = Cells(I, 1)
End If
Next I
For I = 1 To 100
If Cells(I, 1) = Max Then
With Cells(I, 1).Borders
.LineStyle = xlContinuous
.Weight = xlMedium
.ColorIndex = 3
End With
ElseIf Cells(I, 1) = Min Then
With Cells(I, 1).Borders
.LineStyle = xlContinuous
.Weight = xlMedium
.ColorIndex = 5
End With
End If
Next I
BottomMargin

PageSetup
InchesToPoints
CentimetersToPoints

With ActiveSheet.PageSetup
.LeftMargin =
157

Y Excel VBA
Application.InchesToPoints(0.7)
.RightMargin =
Application.InchesToPoints(0.7)
.TopMargin =
Application.InchesToPoints(0.9)
.BottomMargin =
Application.InchesToPoints(0.2)
End With
ActiveWindow.SelectedSheets.PrintPreview
BottomRightCell

ActiveSheet.Shapes("Rectangle 2").Select
Selection.TopLeftCell.Select
Selection.Interior.ColorIndex = 6
Build

Excel
MsgBox Application.Build
MsgBox Application.Version
BuiltinDocumentProperties
30
30
A1 E6
c = ActiveWorkbook.BuiltinDocumentProperties.
Count
For i = 1 To c / 6
For j = 1 To 6
Cells(j, i) = ActiveWorkbook. _
BuiltinDocumentProperties _
((i - 1) * 1 + (j - 1) * 5 + 1).Name
Next j
158

Next I

C
Callout

ActiveSheet.Shapes.AddShape(msoShapeLineCallo
ut2, _
313.5, 237#, 72#, 48#).Select
Selection.Characters.Text = ""
With ActiveSheet.Shapes.AddShape
(msoShapeLineCallout2,_
313.5, 237#, 72#, 48#).Callout.Accent =
True
End With
CapitalizeNamesOfDays
True

Application.AutoCorrect.CapitalizeNamesOfDays
= True
Caption
Application AxisTitle
ChartTitle
DataLabel
Run
CommandButton1.Caption = "Run"
Chart1.
ActiveSheet.ChartObjects(1).Activate
ActiveChart.ChartTitle.Select
Selection.Characters.Caption = "Chart1"

159

Y Excel VBA
CategoryType
x

ActiveSheet.ChartObjects(1).Activate
ActiveChart.PlotArea.Select
ActiveChart.Axes(xlCategory, xlPrimary)._
CategoryType = xlCategoryScale
CellDragAndDrop

True False

Application.CellDragAndDrop = False
Cells

Cells() A2 Cells(21)

A1:A10
Dim I, J As Integer
Dim MIN As Integer
For I = 1 To 10
MIN = Cells(I, 1)
For J = I To 10
If Cells(J, 1) < MIN Then
MIN = Cells(J, 1)
Cells(J, 1) = Cells(I, 1)
Cells(I, 1) = MIN
End If
Next J
Next I
CenterFooter
PageSetup
160

With ActiveSheet.PageSetup
.LeftFooter = "LEFT_P"
.CenterFooter = "MID_P"
.RightFooter = "RIGHT_P"
End With
CenterHeader
PageSetup

With ActiveSheet.PageSetup
.LeftHeader = "LEFT"
.CenterHeader = "MID"
.RightHeader = "RIGHT"
End With
CenterHorizontally
PageSetup

With ActiveSheet.PageSetup
.CenterHorizontally = True
End With
ActiveWindow.SelectedSheets.PrintPreview
CenterVertically
PageSetup

With ActiveSheet.PageSetup
.CenterVertically = True
End With
ActiveWindow.SelectedSheets.PrintPreview
161

Y Excel VBA
Characters

30
ActiveChart.ChartTitle.Select
Selection.Characters.Text = "chart1"
With Selection.Characters _
(Start:=1, Length:=1).Font
.Size = 30
.Underline = xlUnderlineStyleDouble
End With
ActiveChart.ChartArea.Select
5-5

5-5

Chart
ChartObjects

ActiveSheet.ChartObjects(1).Activate
ActiveChart.ChartArea.Select
ChartArea
Chart
162

ActiveSheet.ChartObjects(" 2").Activate
ActiveChart.ChartArea.Select
ActiveChart.PlotArea.Select
Selection.Fill.TwoColorGradient Style:= _
msoGradientVertical, Variant:=1
ActiveChart.SeriesCollection(1).Select
With Selection.Border
.ColorIndex = 6
.Weight = xlThin
.LineStyle = xlContinuous
End With
Charts

c = ActiveWorkbook.Charts.Count
For i = 1 To c
Charts(i).Select
Charts(i).Name = "" & i
ActiveChart.PlotArea.Select
With Selection.Interior
.ColorIndex = 35
End With
Next i
ChartSize

xlScreenSizexlFitToPage
xlFullPage

163

Y Excel VBA

With ActiveChart.PageSetup
.ChartSize = xlFullPage
End With
ActiveWindow.SelectedSheets.PrintPreview
ChartTitle

ActiveChart.ChartArea.Select
With ActiveChart
.ChartTitle.Characters.Text = "Chart1"
End With
ChartType

14
73

ActiveChart.ChartType = xlLineMarkers
Color
RGB

Color= RGB(R,G,B)3
0~255
A3
Range("A3").Select
With Selection.Borders(xlEdgeRight)
.Color = RGB(255, 125, 255)
End With
ColorIndex

1~56 ColorIndex=
164

A1-A10

For I = 1 To 10
Cells(I, 1).Interior.ColorIndex = I
Next I
Colors
RGB ColorIndex
Workbook . Colors()=RGB(R,G,B)
1~56
6
A1
Workbooks(1).Colors(6) = RGB(255, 125, 255)
Cells(1, 1).Interior.ColorIndex = 6
Columns

1~100

For i = 1 To 256
a = 0
b = 0
Do
a = a + 1
If a > 100 Then
Exit Do
End If
If Cells(a, i) <> "" Then
b = b + 1
Exit Do
End If
Loop
165

Y Excel VBA
If b > 0 Then
Columns(i).Select
Selection.Copy
Range("A1").Select
Selection.PasteSpecial Paste:=xlValues, _
Operation:=xlAdd
End If
Next i
ColumnWidth

0
Null
A J
For I = 2 To 10
If ActiveSheet.Columns(I).ColumnWidth <> _
ActiveSheet.Columns(1).ColumnWidth Then
GoTo lp1
End If
Next I
MsgBox ActiveSheet.Columns(1).ColumnWidth
lp1:
Exit Sub
Comments
Comment
Comment
255
1
MsgBox Sheets(1).Comments.Count
ConnectionSiteCount

ActiveSheet.Shapes("Rectangle 1").Select
166

MsgBox ActiveSheet.Shapes("Rectangle 1"). _


ConnectionSiteCount
Connector

True
False

c = ActiveSheet.Shapes.Count
For i = 1 To c
If ActiveSheet.Shapes(i).Connector Then
ActiveSheet.Shapes(i).Delete
End If
Next i
ConnectorFormat

ActiveSheet.Shapes.AddConnector(msoConnectorE
lbow, _
133.5, 184.5, 40.5, 43.5).Select
Selection.ShapeRange.ConnectorFormat.BeginCon
nect _
ActiveSheet.Shapes("Oval 18"), 5
Selection.ShapeRange.ConnectorFormat.EndConne
ct _
ActiveSheet.Shapes("Rectangle 15"), 2
Contrast
0-1.0

0.3
ActiveSheet.Shapes("Picture 1").Select
ActiveSheet.Shapes("Picture 1"). _
PictureFormat.Contrast = 0.3

167

Y Excel VBA
ControlCharacters

Excel

Application.ControlCharacters = True
Corners

ActiveSheet.ChartObjects(" 1").Activate
ActiveChart.ChartArea.Select
ActiveChart.Walls.Select
ActiveChart.Corners.Select
CorrectCapsLock

True False

Application.AutoCorrect.CorrectCapsLock=True
CorrectSentenceCap

True False

Application.AutoCorrect.CorrectSentenceCap = True
Count

Application.WorksheetFunction.Count()

168

With Application.FileSearch
.LookIn = "D\123"
.Filename = "*.xls"
If .Execute() > 0 Then
For i = 1 To .FoundFiles.Count
Workbooks.Open Filename:= _
.FoundFiles(i)
Next i
End If
End With
CreateBackup

True

Private Sub Workbook_BeforeSave _


(ByVal SaveAsUI As Boolean, Cancel As Boolean)
If ActiveWorkbook.CreateBackup = True Then
MsgBox ""
End If
End Sub
Criteria1

37
Rows("1:1").Select
Selection.AutoFilter
Range("G4").Select
Selection.AutoFilter Field:=1,
Criteria1:=">37"
Criteria2
Criteria2
Filter Operator 0
37 49
Rows("1:1").Select
169

Y Excel VBA
Selection.AutoFilter
Range("G4").Select
Selection.AutoFilterField:=1,Criteria1:=">37",
Operator:=xlAnd, Criteria2:="<49"
CropBottom

PictureFormat
20
ActiveSheet.Shapes("Picture 1").Select
ActiveSheet.Shapes("Picture 1").Picture
Format. _
CropLeft = 20
CropLeft

PictureFormat
20
ActiveSheet.Shapes("Picture 1").Select
ActiveSheet.Shapes("Picture
1").PictureFormat. _
CropBottom = 20
CropRight

PictureFormat
20
ActiveSheet.Shapes("Picture 1").Select
ActiveSheet.Shapes("Picture 1").Picture
Format. _
CropRight = 20

170

CropTop

PictureFormat
100
ActiveSheet.Shapes("Picture 1").Select
ActiveSheet.Shapes("Picture 1").Picture
Format. _
CropTop = 100
5-6

5-6

Crosses

x y
ActiveChart.Axes(xlCategory).Select
With ActiveChart.Axes(xlCategory)
.Crosses = xlMaximum
End With
5-7

171

Y Excel VBA

5-7

Cursor
Excel
xlDefaultxlWaitxlNorthwestArrowxlIBeam

Application.Cursor = xlWait
Call
Application.Cursor = xlDefault
CursorMovement
xlLogicalCursor
xlVisualCursor

Application.CursorMovement = xlLogicalCursor
CurrentRegion

ActiveCell.CurrentRegion.Select
Selection.Interior.ColorIndex = 6
5-10

ActiveCell.CurrentRegion.Select
R = Selection.Rows.Count
172

C = Selection.Columns.Count
Range("IV1").Select
Selection.End(xlToLeft).Select
C1 = ActiveCell.Column
Range("A60000").Select
Selection.End(xlUp).Select
R1 = ActiveCell.Row
If R = R1 And C = C1 Then
MsgBox "OK"
Else
MsgBox "NG"
End If
5-8

5-8

CutCopyMode
False xlCopy
xlCut

Cells(1, 1).Select
Selection.Copy
Cells(1, 2).Select
ActiveSheet.Paste
Application.CutCopyMode = False

D
DashStyle
7
173

Y Excel VBA
Line

ActiveSheet.Shapes("Line 9").Select
Selection.ShapeRange.Line.DashStyle = _
MsoLineRoundDot
DataTable

ActiveSheet.ChartObjects(1).Activate
ActiveChart.ChartArea.Select
ActiveChart.HasDataTable = True
ActiveChart.DataTable.ShowLegendKey = True
Date1904
1904
True False
1 1904

2 4 5
Workbooks(1).Date1904 = True
Workbooks(2).Date1904 = False
5-9

5-9

DefaultFilePath
Excel
D

Application.DefaultFilePath = "D:\"
MsgBox Application.DefaultFilePath
174

DefaultSaveFormat

41 xlCSVxlWK1xlExcel2xlHTMLxlIntlMacroxlSYLK

xlExcel9795
Application.DefaultSaveFormat = xlExcel9795
DefaultSheetDirection

Application.DefaultSheetDirection = xlLTR
Depth
-600~9600
0 0
100
ActiveSheet.Shapes("Rectangle 1").Select
ActiveSheet.Shapes("Rectangle
1").ThreeD.Depth = 100
DepthPercent
20%~2000%

ActiveSheet.ChartObjects(" 1").Activate
MsgBox ActiveChart.DepthPercent
Dialogs

1 5 6 7
8 9 12 17 28
258
175

Y Excel VBA

Application.Dialogs(1).Show

Application.Dialogs(5).Show
DisplayBlanksAs
3 0

0
ActiveChart.DisplayBlanksAs = xlNotPlotted
5-10

5-10
DisplayEquation
False

ActiveChart.SeriesCollection(1).Trendlines(1)
.Select
With Selection
.Type = xlLogarithmic
.DisplayEquation = True
.DisplayRSquared = True
End With
DisplayFormulaBar
True Fasle

176

Application.DisplayFormulaBar = False
DisplayFormulas
True False

ActiveWindow.DisplayFormulas = True
5-11

5-11
DisplayFullScreen

Application.DisplayFullScreen = True
5-12

5-12
DisplayGridlines
True False

ActiveWindow. DisplayGridlines = True


177

Y Excel VBA
DisplayHeadings
True False

ActiveWindow.DisplayHeadings = False
5-13

5-13
DisplayHorizontalScrollBar
True False

ActiveWindow.DisplayHorizontalScrollBar =True
DisplayNoteIndicator
True False

ActiveWindow. DisplayNoteIndicator =True


DisplayPageBreaks
True False

ActiveWindow. DisplayPageBreaks =True


178

DisplayRecentFiles
True
False

Application.DisplayRecentFiles = True
DisplayStatusBar
True False

Application. DisplayStatusBar = True


DisplayVerticalScrollBar
True False

ActiveWindow. DisplayVerticalScrollBar=True
DisplayWorkbookTabs
True False

ActiveWindow. DisplayWorkbookTabs=False
5-14

5-14
DisplayZeros
0 True
179

Y Excel VBA
False

0
ActiveWindow. DisplayZeros=True
DownBars

ActiveChart.ChartGroups(1).DownBars.Select
With Selection.Interior
.ColorIndex = 48
End With
Draft
True

PageSetup
1
Worksheets(1).PageSetup.Draft = True
Drop

20
ActiveSheet.Shapes("AutoShape 1").Select
ActiveSheet.Shapes("AutoShape 1").Callout.
DropType _
= msoCalloutDropCustom
ActiveSheet.Shapes("AutoShape 1").Callout.
Drop = 20
DropLines

180

ActiveSheet.ChartObjects(" 1").Activate
ActiveChart.SeriesCollection(1).Select
With ActiveChart.ChartGroups(1)
.HasDropLines = True
End With
ActiveChart.PlotArea.Select
ActiveChart.ChartGroups(1).DropLines.Select
With Selection.Border
.ColorIndex = 3
.Weight = xlMedium
.LineStyle = xlContinuous
End With

E
EditDirectlyInCell
True False

Application.EditDirectlyInCell = True
Elevation

15 -90 90
0~44
30
ActiveChart.Walls.Select
ActiveChart.Corners.Select
With ActiveChart
.Elevation = 30
End With

181

Y Excel VBA
Enabled
True
FalseVB
TextBox1

If TextBox1.Text = "2546" Then


TextBox1.Enabled = True
Else
MsgBox "", vbCritical
End If
EnableEvents

Private Sub Worksheet_BeforeDoubleClick _


(ByVal Target As Range, Cancel As Boolean)
Application.EnableEvents = False
MsgBox "nihao"
End Sub
EnableResize
Windows True

50

If ActiveWindow.Height > 50 Then


ActiveWindow.EnableResize = False
End If
EnableSelection

xlNoRestrictions
xlNoSelection
xlUnlockedCells
182

ActiveSheet.Protect
ActiveSheet.EnableSelection _
= xlNoRestrictions
End
End+
.End() xlUp
xlDownxlLeftxlRight
A1:A1200
A1 A1200
Cells(1, 1).End(xlDown).Select

Range(Selection, ActiveCell. _
SpecialCells(xlLastCell)).Select
EndArrowheadLength
:
msoArrowheadLengthMedium
msoArrowheadLengthMixed
msoArrowheadLong
msoArrowheadShort

Selection.ShapeRange.Line.EndArrowheadLengt
h _
= msoArrowheadLengthMedium
Selection.ShapeRange.Line.EndArrowheadWidth_
= msoArrowheadWide
Selection.ShapeRange.Line.EndArrowheadStyle_
= msoArrowheadTriangle
EndArrowheadStyle

183

Y Excel VBA
msoArrowheadDiamond
msoArrowheadNone
msoArrowheadOpen
msoArrowheadOval
msoArrowheadStealth
msoArrowheadStyleMixed
msoArrowheadTriangle
EndArrowheadLength
EndArrowheadWidth
:
msoArrowheadNarrow
msoArrowheadWide
msoArrowheadWidthMedium
msoArrowheadWidthMixed
EndArrowheadLength
EndConnected
True
False

If ActiveSheet.Shapes("AutoShape 1"). _
ConnectorFormat.EndConnected = True Then
MsgBox ""
End If
EndConnectedShape

ActiveSheet.Shapes("AutoShape 1"). _
ConnectorFormat.EndConnectedShape.Select
Selection.ShapeRange.Fill.OneColorGradient _
msoGradientHorizontal, 3, 0.23
184

EndStyle
xlCapxlNoCap

xlNoCap
ActiveChart.SeriesCollection(1).ErrorBars.Sel
ect
With Selection.Border
.LineStyle = xlContinuous
.ColorIndex = 3
.Weight = xlThick
End With
Selection.EndStyle = xlNoCap
5-15

5-15
EntireColumn

10

For I = 1 To 256
If Cells(10, I) <> "" Then
Cells(10, I).EntireColumn.Select
Selection.Interior.ColorIndex = 6
End If
Next I
185

Y Excel VBA
EntireRow

10
<1000
For I = 1 To 1000
If Cells(I, 10) <> "" Then
Cells(I, 10). EntireRow.Select
Selection.Interior.ColorIndex = 6
End If
Next I
ErrorBars

ActiveSheet.ChartObjects(" 32").Activate
ActiveChart.SeriesCollection(1).Select
ActiveChart.SeriesCollection(1).ErrorBar
Direction:=xlY
Extent

xlPageBreakFull xlPageBreakPartial
xlPageBreakFull
Worksheets(1).HPageBreaks.Extent =
xlPageBreakFull
ExtrusionColor

ActiveSheet.Shapes("Rectangle 30").Select
Selection.ShapeRange.ThreeD.Extrusion
Color. _
186

SchemeColor = 13
Selection.ShapeRange.ThreeD.Visible =
msoTrue
Selection.ShapeRange.Shadow.Visible =
msoFalse
5-16

5-16
ExtrusionColorType
3
msoExtrusionColorAutomatic

msoExtrusionColorCustom
msoExtrusionColorTypeMixed

ActiveSheet.Shapes("Rectangle 1").Select
Selection.ShapeRange.ThreeD.ExtrusionColorTyp
e = _
MsoExtrusionColorTypeMixed

F
FileFormat
Excel
Excel 41
CSV

187

Y Excel VBA
ActiveWorkbook.SaveAs Filename:= _
"C:\SD3#060421.csv", FileFormat:=xlCSV
FileSearch

*
D CSV

f0 = ActiveWorkbook.Name
With Application.FileSearch
.LookIn = "d:\"
.Filename = "*.csv"
If .Execute() > 0 Then
For i = 1 To .FoundFiles.Count
Workbooks.Open
Filename:=.FoundFiles(i)
f1 = ActiveWorkbook.Name
Cells(60000, 1).Select
Selection.End(xlUp).Select
r = ActiveCell.Row
Rows("1:" & r).Select
Selection.Copy
Workbooks(f0).Select
Cells(60000, 1).Select
Selection.End(xlUp).Select
Cells(ActiveCell.Row + 1, 1).Select
ActiveSheet.Paste
Application.CutCopyMode = False
Workbooks(f1).Close
Next i
End If
End With
Fill

188

Selection.ShapeRange.Fill.ForeColor.SchemeCol
or = 9
Selection.ShapeRange.Fill.OneColorGradient
msoGradientHorizontal, 1, 0.23
Filters

=62
Rows("1:1").Select
Selection.AutoFilter
Selection.AutoFilter.Filters (2),
Criteria1:="62"
FirstSliceAngle

15
ActiveSheet.ChartObjects(" 1").Activate
ActiveChart.ChartArea.Select
ActiveChart.ChartGroups(1).FirstSliceAngle=15
FitToPagesTall

False PageSetup

ActiveSheet.PageSetup.FitToPagesTall = 1
FitToPagesWide

False PageSetup

ActiveSheet.PageSetup. FitToPagesWide = 1

189

Y Excel VBA
FixedDecimal
True
FixedDecimalPlaces
1000

Application.FixedDecimal = True
If Cells(1, 1) > 1000 Then
Application.FixedDecimalPlaces = 3
End If
FixedDecimalPlaces
FixedDecimal True

A1 1
B
B = Len(Cells(1, 1)) - 1
Select Case B
Case 0
Cells(1, 2) = ""
Case 1
Cells(1, 2) = ""
Case 2
Cells(1, 2) = ""
Case 3
Cells(1, 2) = ""
Case 4
Cells(1, 2) = ""
Case 5
Cells(1, 2) = ""
Case 6
Cells(1, 2) = ""
End Select
Application.FixedDecimal = True
Application.Fixed13DecimalPlaces = b

190

Floor

ActiveChart.Floor.Select
With Selection.Interior
.ColorIndex = 6
End With
Font

Range("I24").Select
With Selection.Font
.Name = ""
.FontStyle = " "
.Size = 16
.ColorIndex = 3
End With
FontBold

Selection.ShapeRange.TextEffect. _
FontBold = msoTrue
FontItalic

Selection.ShapeRange.TextEffect. _
FontItalic = msoTrue
FontSize

191

Y Excel VBA

NIHAO 60#
ActiveSheet.Shapes("WordArt 1").Select
Selection.ShapeRange.TextEffect.Text = "NIHAO"
Selection.ShapeRange.TextEffect.FontSize=60#
FontStyle
Excel 30
msoTextEffect+

msoTextEffect10 10
ActiveSheet.Shapes("WordArt 1").Select
Selection.ShapeRange.TextEffect.PresetTextEff
ect = _
msoTextEffect10
ActiveSheet.Shapes("WordArt 2").Select
Selection.ShapeRange.TextEffect.PresetTextEff
ect = 10
5-17

5-17
FooterMargin

PageSetup

With ActiveSheet.PageSetup
192

.FooterMargin = Application. _
InchesToPoints(0.23)
End With
ActiveWindow.SelectedSheets.PrintPreview
ForeColor

Selection.ShapeRange.Line. _
ForeColor.SchemeColor = 10
FormControlType
Excel
xlButtonControl
xlCheckBox
xlDropDown
xlEditBox
xlGroupBox
xlLabel
xlListBox
xlOptionButton
xlScrollBar
xlSpinner

ActiveSheet.Shapes.AddFormControl _
(xlButtonControl, 100, 10, 100, 100).Select
MsgBox ActiveSheet.Shapes(1).FormControlType
FormulaHidden
True

A1

193

Y Excel VBA
Cells(1, 1) = "=SUM(A2:A2000)"
ActiveSheet.Protect
Worksheets(1).Rows(1).FormulaHidden = True
FormulaR1C1

MsgBox ActiveCell.FormulaR1C1
Forward

00.5
0.5
ActiveChart.SeriesCollection(1).Select
ActiveChart.SeriesCollection(1).Trendlines.Ad
d(Type:=xlLinear, _
Forward:=0.5).Select
FreezePanes

ActiveWindow.FreezePanes = True
ActiveWindow.FreezePanes = False
FullName

MsgBox ActiveWorkbook.FullName

G
Gap

194

4
20304050
For i = 1 To 4
ActiveSheet.Shapes(i).Callout.Gap = (i - 1) *
10 + 20
Next I
5-18

5-18
GapDepth

0~500

170
ActiveChart.SeriesCollection(1).Select
With ActiveChart
.GapDepth = 170
End With
GapWidth
0~500

5~500
180
ActiveChart.SeriesCollection(1).Select
ActiveChart.ChartGroups(1).GapWidth = 180
195

Y Excel VBA
GradientColorType

msoGradientColorMixed
msoGradientOneColor
msoGradientPresetColors
msoGradientTwoColors

ActiveSheet.Shapes("Rectangle 2").Select
Selection.ShapeRange.Fill.OneColorGradient _
msoGradientHorizontal, 1, 0.23
MsgBox "" & Selection.ShapeRange. _
Fill.GradientColorType
GradientDegree
0.0~1.0

ActiveSheet.Shapes("Rectangle 2").Select
Selection.ShapeRange.Fill.OneColorGradient_
msoGradientHorizontal, 1, 0.23
MsgBox "" & Selection. _
ShapeRange.Fill.GradientDegree
GradientStyle

msoGradientDiagonalDown
msoGradientDiagonalUp
msoGradientFromCenter
msoGradientFromCorner
msoGradientFromTitle
msoGradientHorizontal
196

msoGradientMixed
msoGradientVertical

ActiveChart.ChartArea.Select
Selection.Fill.TwoColorGradient Style:= _
msoGradientHorizontal, Variant:=2
GradientVariant
1~4

ActiveSheet.Shapes("Rectangle 2").Select
Selection.ShapeRange.Fill.OneColor
Gradient _
msoGradientHorizontal, 1, 0.23
MsgBox "" & Selection. _
ShapeRange.Fill.GradientVariant
GridlineColor
RGB
GridlineColorIndex

ActiveWindow.GridlineColor = RGB(0, 0, 255)


5-19

5-19
197

Y Excel VBA
GridlineColorIndex

56

ActiveWindow.GridlineColorIndex = 5
5-20

H
Has3DEffect
True

ActiveSheet.ChartObjects(" 1").Activate
ActiveChart.ChartArea.Select
ActiveChart.SeriesCollection(1).Select
Selection.InvertIfNegative = True
Selection.Has3DEffect = True
Selection.Interior.ColorIndex = xlAutomatic
5-20

5-20
HasAxis
.HasAxis
xlCategoryxlValue
198

xlSeriesAxis xlPrimaryxlSecondary

X Y

ActiveSheet.ChartObjects(" 1").Activate
ActiveChart.PlotArea.Select
With ActiveChart
.HasAxis(xlCategory, xlPrimary) = True
.HasAxis(xlValue, xlPrimary) = True
End With
ActiveChart.Axes(xlCategory, xlPrimary). _
CategoryType = xlCategoryScale
HasBorderHorizontal

ActiveChart.DataTable.HasBorderHorizontal =
False
HasBorderOutline
True

ActiveChart.DataTable.HasBorderOutline = False
HasBorderVertical

ActiveChart.DataTable.HasBorderHorizontal =
False
HasDataLabel
True False

199

Y Excel VBA
ActiveChart.SeriesCollection(1).Select
c = ActiveChart.SeriesCollection(1). Points.
Count
For i = 1 To c
ActiveChart.SeriesCollection(1). Points
(i). _
HasDataLabel = True
Next I
5-21

5-21
HasDataLabels
True False

ActiveChart.SeriesCollection(1).HasDataLabels
= True
HasDataTable
X

ActiveChart.HasDataTable = True
5-22
200

5-22
HasDropLines

True False

ActiveChart.ChartArea.Select
ActiveChart.SeriesCollection(1).Select
With ActiveChart.ChartGroups(1)
.HasDropLines = True
End With
HasFormula
True
False

If Range("d2:d7").HasFormula = True Then


MsgBox ""
ElseIf Range("d2:d7").HasFormula = False Then
MsgBox ""
Else
MsgBox ""
End If
HasHiLoLines

201

Y Excel VBA
ActiveChart.ChartArea.Select
ActiveChart.SeriesCollection(1).Select
With ActiveChart.ChartGroups(1)
.HasDropLines = False
.HasHiLoLines = True
.HasUpDownBars = False
End With
5-23

5-23
HasLegend
True False

ActiveChart.HasLegend = True
HasMajorGridlines

ActiveSheet.ChartObjects(" 1").Activate
ActiveChart.PlotArea.Select
With ActiveChart.Axes(xlCategory)
.HasMajorGridlines = True
.HasMinorGridlines = True
End With
With ActiveChart.Axes(xlValue)
202

.HasMajorGridlines = True
.HasMinorGridlines = True
End With
HasMinorGridlines

HasMajorGridlines
HasPassword
True False

If ActiveWorkbook.HasPassword = True Then


MsgBox ""
Else
MsgBox ""
End If
HasTitle
True
False

ActiveChart.HasTitle = True
HasUpDownBars
True False

ActiveChart.ChartArea.Select
ActiveChart.SeriesCollection(1).Select
With ActiveChart.ChartGroups(1)
.HasDropLines = False
.HasHiLoLines = False
.HasUpDownBars = True
End With
203

Y Excel VBA
HeaderMargin

PageSetup

0.12
With ActiveSheet.PageSetup
.HeaderMargin = Application. _
InchesToPoints(0.12)
End With
Height

200

ActiveWindow.Height = 200
HeightPercent

5%~500%
100%
ActiveSheet.ChartObjects(1).Activate
ActiveChart.HeightPercent = 100
Hidden

3 9
Rows("3:9").Select
Selection.EntireRow.Hidden = True
HiLoLines

204

ActiveChart.ChartGroups(1).HiLoLines.Select
With Selection.Border
.ColorIndex = 3
.Weight = xlThick
.LineStyle = xlContinuous
End With
HorizontalAlignment

xlHAlignCenter
xlHAlignDistributed
xlHAlignJustify
xlHAlignLeft
xlHAlignRight
xlHAlignCenterAcrossSelection
xlHAlignFill
xlHAlignGeneral
3

ActiveChart.ChartArea.Select
With ActiveChart
.HasTitle = True
.ChartTitle.Characters.Text = "chart1"
End With
ActiveChart.ChartTitle.HorizontalAlignment_
= xlHAlignCenter
HorizontalFlip

True

If ActiveSheet.Shapes("AutoShape
50").HorizontalFlip _
= True Then
MsgBox ""
205

Y Excel VBA
End If
Hyperlink

ActiveSheet.Shapes(1).Select
ActiveSheet.Hyperlinks.Add Anchor:=
Selection._
ShapeRange.Item(1), Address:= _
"", SubAddress:="Database"

I
IncludeAlignment
HorizontalAlignmentVerticalAlignment
True False

If Range(Cells(1, 1), Cells(10, 10)).Style. _


IncludeAlignment = True Then
MsgBox ""
Else
MsgBox ""
End If
IncludeBorder
ColorIndexWeightColor
True False

If Range(Cells(1, 1), Cells(10, 10)).Style. _


IncludeBorder = True Then
MsgBox ""
Else
MsgBox ""
End If
IncludeFont
BoldColorItalicNameOutlineFont
206

True False

If Range(Cells(1, 1), Cells(10, 10)).Style. _


IncludeFont = True Then
MsgBox ""
Else
MsgBox ""
End If
IncludeNumber
True False

If Range(Cells(1, 1), Cells(10, 10)).Style. _


IncludeNumber = True Then
MsgBox ""
Else
MsgBox ""
End If
IncludePatterns
ColorIndexInvertIfNegativeColor
True False

If Range(Cells(1, 1), Cells(10, 10)).Style. _


IncludePatterns = True Then
MsgBox ""
Else
MsgBox ""
End If
IncludeProtection
FormulaHiddenLocked
True False
IncludeFont
207

Y Excel VBA
IndentLevel
0~15

A1 A16 0~15
For I = 1 To 16
Cells(I, 1).IndentLevel = I - 1
Next I
5-24

5-24
Index

Application.WorksheetFunction Index

1st
Sheets(1).Name = "1st"

ActiveSheet.ChartObjects(2).Delete
InsideHeight

ActiveSheet.ChartObjects(1).Activate
ActiveChart.ChartArea.Select
MsgBox ActiveChart.PlotArea.InsideHeight
208

InsideLeft

ActiveSheet.ChartObjects(1).Activate
ActiveChart.ChartArea.Select
MsgBox ActiveChart.PlotArea. InsideLeft
InsideTop

ActiveSheet.ChartObjects(1).Activate
ActiveChart.ChartArea.Select
MsgBox ActiveChart.PlotArea. InsideTop
InsideWidth

ActiveSheet.ChartObjects(1).Activate
ActiveChart.ChartArea.Select
MsgBox ActiveChart.PlotArea. InsideWidth
Interactive
False, True
Excel

Application.Interactive = False
Intercept

Application.WorksheetFunction
Intercept 0
209

Y Excel VBA

ActiveChart.ChartArea.Select
ActiveChart.SeriesCollection(1).Trendlines(1)
.Select
MsgBox Selection.Intercept
InterceptIsAuto
True
False

ActiveSheet.ChartObjects(" 1").Activate
ActiveChart.SeriesCollection(1).Select
ActiveChart.SeriesCollection(1).Trendlines. _
Add(Type:=xlLogarithmic).Select
If ActiveChart.SeriesCollection(1).
Trendlines(1). _
InterceptIsAuto = True Then
MsgBox ActiveChart.SeriesCollection(1). _
Trendlines(1).Intercept
End If
Interior

For i = 1 To 100
If Val(Cells(i, 1)) / 2 = Int(Val(Cells(i,
1)) / 2) Then
Cells(i, 1).Interior.ColorIndex = 6
ElseIf Val(Cells(i, 1)) / 2 <> Int(Val
(Cells(i, 1)) / 2) Then
Cells(i, 1).Interior.ColorIndex = 5
ElseIf Cells(i, 1) = "" Then
210

GoTo lp1
End If
lp1:
Next I
Italic

min = Cells(1, 1)
max = Cells(1, 1)
For i = 1 To 10
If Cells(i, 1) > max Then
max = Cells(i, 1)
End If
If Cells(i, 1) < min Then
min = Cells(i, 1)
End If
Next i
For i = 1 To 10
If Cells(i, 1) = min Or Cells(i, 1) = max
Then
Cells(i, 1).Italic = True
End If
Next i
Item

c = Sheets.Count
For i = 1 To c
If Left(Sheets.Item(i).Name, 1) = "n" Then
Sheets.Item(i).Delete
End If
Next i
211

Y Excel VBA
* Sheets.Item(i) Sheets(i).

K
KernedPairs
True

If Selection.ShapeRange.TextEffect.Kerned
Pairs = True Then
MsgBox ""
Else
MsgBox ""
End If

L
LargeChange
Excel

Worksheets(1).Shapes.AddFormControl(xlScrollBar, _
Left:=50, Top:=10, Width:=10,
Height:=200).Select
With ActiveSheet.Shapes("Scroll Bar 1")
.Max = 200
.Min = 0
.LargeChange = 20
.SmallChange = 2
End With
LeaderLines

212

ActiveChart.SeriesCollection(1).Select
ActiveChart.SeriesCollection(1).ApplyDataLa
bels _
Type:=xlDataLabelsShowPercent, AutoText:=
True, _
LegendKey:=True, HasLeaderLines:=True
ActiveChart.SeriesCollection(1).
LeaderLines. _
Border.ColorIndex = 5
Left

20
If ActiveWindow.Left < 20 Then
ActiveWindow.Left = 20
End If
LeftFooter
PageSetup
NIHAO
With ActiveSheet.PageSetup
.LeftFooter = "NIHAO"
End With
LeftHeader
PageSetup
NIHAO
With ActiveSheet.PageSetup
.LeftHeader= "NIHAO"
End With
LeftMargin

213

Y Excel VBA

With ActiveSheet.PageSetup
.LeftMargin =
Application.InchesToPoints(0.787)
End With
Legend

ActiveChart.Legend.Select
Selection.AutoScaleFont = True
With Selection.Font
.Size = 14
End With
LegendKey

ActiveChart.Legend.LegendEntries(1).LegendKey
.Select
With Selection
.MarkerBackgroundColorIndex = 3
.MarkerForegroundColorIndex = 3
.MarkerStyle = xlX
.MarkerSize = 7
End With
Length

2 AutoLength False

ActiveSheet.Shapes("AutoShape 2").Select
MsgBox ActiveSheet.Shapes("AutoShape 2"). _
214

Callout.Length
Line

3#
ActiveSheet.Shapes("Rectangle 6").Select
Selection.ShapeRange.Line.Weight = 3#
Line3DGroup

ActiveSheet.ChartObjects(1).Activate
ActiveChart.SeriesCollection(1).Select
With ActiveChart.Line3DGroup
.HasDropLines = True
.VaryByCategories = True
End With
LineStyle

Range("G20:H22").Select
With Selection.Borders(xlEdgeLeft)
.LineStyle = xlDashDotDot
.Weight = xlThin
.ColorIndex = xlAutomatic
End With
LinkedCell
Excel

Excel
D4
Worksheets(1).Shapes.AddFormControl(xlScrollB
215

Y Excel VBA
ar, _
Left:=50, Top:=10, Width:=10, Height:=
200).Select
With ActiveSheet.Shapes("Scroll Bar 12").
ControlFormat
.LinkedCell = Range("D4")
End With
ListCount

0 Excel
2
MsgBox Sheets(2).Shapes(1).ControlFormat.
ListCount
ListFillRange

Excel
A1 A8
Sheets(1).Shapes("List Box 1").ControlFormat. _
ListFillRange = "A1:A8"
ListIndex
EXCEL

Worksheets(1).Shapes(2). Select
MsgBox Selection.ListIndex
Location

1
H10
C = ActiveSheet.HPageBreaks.Count
216

If C >= 1 Then
ActiveSheet.HPageBreaks(1).Location = Range
("H10")
End If
LockAspectRatio
True

ActiveSheet.Shapes(1).Select
ActiveSheet.Shapes(1).LockAspectRatio =
True
LockedText

Excel

ActiveSheet.Shapes(1).LockedText = False

M
MajorGridlines

MinorGridlines
Y
ActiveChart.Axes(xlValue).MajorGridlines.
Select
With Selection.Border
.ColorIndex = 5
End With
MajorTickMark
:
xlTickMarkNone
217

Y Excel VBA
xlTickMarkInside
xlTickMarkOutside
xlTickMarkCross
X
ActiveChart.Axes(xlCategory).Select
With Selection
.MajorTickMark = xlCross
.TickLabelPosition = xlNextToAxis
End With
MajorUnit

Y 10
ActiveChart.Axes(xlValue).Select
With ActiveChart.Axes(xlValue)
.MinorUnit = 10
.MajorUnit = 10
End With
MajorUnitIsAuto
True

ActiveSheet.ChartObjects(1).Activate
ActiveChart.Axes(xlValue).Select
With ActiveChart.Axes(xlValue)
.MinimumScaleIsAuto = True
.MaximumScaleIsAuto = True
.MinorUnitIsAuto = True
.MajorUnitIsAuto = True
.Crosses = xlAutomatic
.ScaleType = xlLinear
.DisplayUnit = xlNone
End With
MarginBottom

218

TextFrame
20
ActiveSheet.Shapes("Rectangle 8").Select
Selection.Characters.Text = "nihao"
ActiveSheet.Shapes("Rectangle 8"). _
TextFrame.MarginBottom =20
MarginLeft

TextFrame
10
ActiveSheet.Shapes("Rectangle 8").Select
Selection.Characters.Text = "nihao"
ActiveSheet.Shapes("Rectangle 8"). _
TextFrame. MarginLeft = 10
MarginRight

TextFrame
10
ActiveSheet.Shapes("Rectangle 8").Select
Selection.Characters.Text = "nihao"
ActiveSheet.Shapes("Rectangle 8"). _
TextFrame. MarginRight = 10
MarginTop

TextFrame
10
ActiveSheet.Shapes("Rectangle 8").Select
Selection.Characters.Text = "nihao"
ActiveSheet.Shapes("Rectangle 8"). _
TextFrame. MarginRight = 10
MarkerBackgroundColor
RGB
219

Y Excel VBA
MarkerForegroundColor

ActiveChart.ChartArea.Select
ActiveChart.SeriesCollection(1).Select
C = Selection.Points.Count
For I = 1 To C
Selection.Points(I).MarkerBackground
Color _
= RGB(255, 0, 255)
Next I
MarkerBackgroundColorIndex

MarkerForegroundColorIndex

ActiveChart.ChartArea.Select
ActiveChart.SeriesCollection(1).Select
C = Selection.Points.Count
For I = 1 To C
Selection.Points(I).MarkerBackground
ColorIndex _
= 6
Next I
MarkerForegroundColor
RGB
MarkerBackgroundColor

ActiveChart.ChartArea.Select
ActiveChart.SeriesCollection(1).Select
220

C = Selection.Points.Count
For I = 1 To C
Selection.Points(I). MarkerForeground
Color _
= RGB(255, 0, 255)
Next I
MarkerForegroundColorIndex

MarkerBackgroundColorIndex

ActiveChart.ChartArea.Select
ActiveChart.SeriesCollection(1).Select
C = Selection.Points.Count
For I = 1 To C
Selection.Points(I). MarkerForeground
ColorIndex _
= 6
Next I
5-25

5-25
MarkerSize

221

Y Excel VBA
16
ActiveChart.SeriesCollection(1).Select
C = Selection.Points.Count
For I = 1 To C
Selection.Points(I).MarkerSize = 16
Next I
MarkerStyle

12

ActiveChart.ChartArea.Select
ActiveChart.SeriesCollection(1).Select
C = Selection.Points.Count
For i = 1 To C
Selection.Points(i).MarkerStyle= xlMarker
StyleNone
Next I
Max
Excel

150 5
Worksheets(1).Shapes.AddFormControl(xlScrollB
ar, _
Left:=50, Top:=10, Width:=10,Height:
=200).Select
With ActiveSheet.Shapes("Scroll Bar 1") .
ControlFormat
.Max = 150
.Min = 5
End With

222

Maximum
0~9
RecentFiles
5
Application.RecentFiles.Maximum = 5
MaximumScale

MinimumScale
Y 100
ActiveSheet.ChartObjects(1).Activate
ActiveChart.Axes(xlValue).Select
With ActiveChart.Axes(xlValue)
.MaximumScale = 100
End With
MaximumScaleIsAuto
True

ActiveSheet.ChartObjects(1).Activate
ActiveChart.Axes(xlValue).Select
With ActiveChart.Axes(xlValue)
.MinimumScaleIsAuto = True
.MaximumScaleIsAuto = True
End With
MemoryFree

MemoryTotal
MemoryUsed

MsgBox Application.MemoryFree
MemoryTotal

223

Y Excel VBA
MemoryFree
MemoryUsed

MsgBox Application.MemoryTotal
MemoryUsed

MemoryFree
MemoryTotal

Dim t, u, f As String
With Application
t = (.MemoryTotal / 1000) & " Kb"
u = (.MemoryUsed / 1000) & " Kb"
f = (.MemoryFree / 1000) & " Kb"
End With
MsgBox "Total :" & t & Chr(13) & "Used :" & _
u & Chr(13) & "Free :" & f , vbInformation,
"Memory"
Min
Excel

150 5
Worksheets(1).Shapes.AddFormControl(xlScrollB
ar, _
Left:=50, Top:=10, Width:=10,
Height:=200).Select
With ActiveSheet.Shapes("Scroll Bar
1") .ControlFormat
.Max = 150
.Min = 5
End With
224

MinimumScale

MaximumScale
Y 0
ActiveSheet.ChartObjects(1).Activate
ActiveChart.Axes(xlValue).Select
With ActiveChart.Axes(xlValue)
. MinimumScale = 0
End With
MinimumScaleIsAuto
True

ActiveSheet.ChartObjects(1).Activate
ActiveChart.Axes(xlValue).Select
With ActiveChart.Axes(xlValue)
.MinimumScaleIsAuto = True
.MaximumScaleIsAuto = True
End With
MinorGridlines

MajorGridlines
Y
ActiveChart.Axes(xlValue).MinorGridlines.Se
lect
With Selection.Border
.ColorIndex = 6
End With
MinorTickMark
:
xlTickMarkNone
225

Y Excel VBA
xlTickMarkInside
xlTickMarkOutside
xlTickMarkCross

ActiveSheet.ChartObjects(1).Activate
ActiveChart.Axes(xlCategory).Select
With Selection
.MajorTickMark = xlInside
.MinorTickMark = xlOutside
End With
MinorUnit

0.0003
ActiveSheet.ChartObjects(1).Activate
ActiveChart.Axes(xlValue).Select
With ActiveChart.Axes(xlValue)
.MinorUnit = 0.0003
End With
MinorUnitIsAuto
True

ActiveSheet.ChartObjects(1).Activate
ActiveChart.Axes(xlValue).Select
With ActiveChart.Axes(xlValue)
.MinorUnitIsAuto = True
End With
MinorUnitScale
,:
226

xlDays
xlMonths
xlYears
3

4 2
ActiveSheet.ChartObjects(1).Activate
ActiveChart.Axes(xlCategory).Select
With ActiveChart.Axes(xlCategory)
.MajorUnit = 4
.MajorUnitScale = xlDays
.MinorUnit = 2
.MinorUnitScale = xlDays
End With
5-26

5-26
MouseAvailable
True

OK
If Application.MouseAvailable = True Then
MsgBox "OK"
End If
MoveAfterReturn
False
True
227

Y Excel VBA

Application.MoveAfterReturn = False
MoveAfterReturnDirection
4

Application.MoveAfterReturnDirection = xlToLeft
Application.MoveAfterReturnDirection =
xlToRight

Application.MoveAfterReturnDirection = xlUp
Application.MoveAfterReturnDirection = xlDown

N
Name

C = Sheets.Count
For I = 1 To C
Cells(I, 1) = Sheets(I).Name
Next I
NameIsAuto
True

If ActiveChart.SeriesCollection(1).Trendlines
(1). _
NameIsAuto = True Then
228

MsgBox ""
End If
Next

ActiveSheet.Next.Select
Nodes

5
ActiveSheet.Shapes(1).Select
Selection.ShapeRange.Nodes. _
SetPosition 5, 322.5, 175.5
NormalizedHeight
True

ActiveSheet.Shapes("WordArt 1").Select
ActiveSheet.Shapes("WordArt 1").TextEffect. _
NormalizedHeight = True
NumberFormatLinked
True

ActiveSheet.ChartObjects(1).Activate
ActiveChart.SeriesCollection(1).Select
ActiveChart.SeriesCollection(1).ApplyData
Labels _
Type:=xlDataLabelsShowValue, AutoText:=True
229

Y Excel VBA
ActiveChart.SeriesCollection(1).DataLabels. _
NumberFormatLinked = True

O
Obscured
True
False

False
ActiveSheet.Shapes("Rectangle 3").Select
ActiveSheet.Shapes("Rectangle 3").Shadow._
Obscured = False
Offset

. Offset
>0
3
4
Cells(1, 1).Offset(3, 4).Select
OffsetX
>0 <0
OffsetY
>0 <0
50
50
ActiveSheet.Shapes("Freeform 3").Select
ActiveSheet.Shapes(1).Shadow.OffsetX = -50
ActiveSheet.Shapes(1).Shadow.OffsetY = 50
OffsetY
>0 <0
OffsetX
>0 <0
230

OffsetX
OLEFormat
OLE OLE

OLE
ActiveSheet.Shapes("Object 1").Select
ActiveSheet.Shapes("Object 1").OLEFormat.
Activate
OnAction

. OnAction=

ActiveSheet.Shapes(1).OnAction = "Macro1"
OnWindow

.OnWindow =

Windows(2).OnWindow = "Macro1"
Order
1
xlPolynomial xlDownThenOver
xlOverThenDown

ActiveSheet.PageSetup.Order = xlDownThenOver
OperatingSystem

MsgBox Application.OperatingSystem
231

Y Excel VBA
Orientation
xlMove
xlFreeFloatingxlMoveAndSize xlLandscape
xlPortrait-90~90
-45
ActiveChart.Axes(xlCategory).Select
With Selection.TickLabels
.Orientation = -45
End With
-45
Range("B1").Select
With Selection
.Orientation = -45
End With
5-27

5-27
Outline

Rows("3:27").Select
Selection.Rows.Group
Rows("3:12").Select
Selection.Rows.Group
Range("B8").Select
ActiveSheet.Outline.ShowLevels RowLevels:
=3
ActiveSheet.Outline.ShowLevels RowLevels:
=2
ActiveSheet.Outline.ShowLevels RowLevels:
=1
232

OutlineFont

With Selection.Font
.OutlineFont = True
End With
OutlineLevel

3~13
3
Rows("3:27").Select
Selection.Rows.Group
Rows("3:12").Select
Selection.Rows.Group
Range("B8").Select
ActiveSheet.Rows("3:13").OutlineLevel = 3
Overlap
-100 100 -100
0 100
0
ActiveChart.SeriesCollection(1).Select
With ActiveChart.ChartGroups(1)
.Overlap = 0
End With

P
PageBreak

xlPageBreakAutomatic
xlPageBreakManual
xlPageBreakNone

10
233

Y Excel VBA
ActiveSheet.Rows(10).PageBreak = xlPageBreak
Manual
PageSetup

0.1
With ActiveChart.PageSetup
.LeftMargin = Application.InchesToPoints
(0.1)
.RightMargin=Application.InchesToPoints
(0.1)
.TopMargin = Application.InchesToPoints
(0.1)
.BottomMargin=Application.InchesToPoint
s (0.1)
.HeaderMargin=Application.InchesToPoint
s (0.1)
.FooterMargin=Application.InchesToPoint
s(0.1)
End With
Panes

MsgBox ActiveWindow.Panes.Count
PaperSize
PageSetup 42

A4
ActiveSheet.PageSetup.PaperSize = xlPaperA4
Parent

234

Sheets(1).Comments(1).Parent.Select
Selection.Interior.ColorIndex = 6
Path

Application.Path Excel

MsgBox ActiveWorkbook.Path
123.xls
p = ActiveWorkbook.Path
Workbooks.Open Filename:=p & "\" & "123.xls"
PathSeparator
\,

j = Application.PathSeparator
Workbooks.Open Filename:="D:" & j & "1.xls"
Pattern
Interior 20
FillFormat 49

Cells(1, 1).Interior.Pattern = xlPatternChecker


PatternColor
RGB Interior

Cells(1, 1).Interior.PatternColor = RGB(255,


0, 0)
PatternColorIndex

Interior
235

Y Excel VBA

Cells(1, 1).Interior.PatternColorIndex = 3
Period

3
ActiveChart.SeriesCollection(1).Select
ActiveChart.SeriesCollection(1).Trendlines.
Add_
(Type:=xlMovingAvg, Period:=3).Select
Perspective
0~100

50
ActiveSheet.ChartObjects(1).Activate
ActiveChart.Perspective = 50
PictureFormat

0.5
ActiveSheet.Shapes("Picture 1").Select
ActiveSheet.Shapes("Picture 1"). Picture
Format. _
Brightness = 0.5
PictureType

xlStretch()xlStack()
xlScale()xlTile()

ActiveSheet.ChartObjects(1).Activate
ActiveChart.SeriesCollection(1).PictureType
236

=xlTile
PlotArea

ActiveChart.PlotArea.Select
Selection.Height = 136
Selection.Top = 49
Selection.Width= 119
Selection.Left = 8
PlotBy

xlColumnsxlRows

ActiveChart.SetSourceData Source:= _
Sheets("1st").Range("A1:A10"), PlotBy:=
xlRows
PlotOrder

ActiveSheet.ChartObjects(1).Activate
ActiveChart.ChartArea.Select
ActiveChart.ChartGroups(1).SeriesCollection
(1)._
PlotOrder = 4
PlotVisibleOnly
True False

ActiveSheet.ChartObjects(1).Activate
237

Y Excel VBA
ActiveChart.ChartArea.Select
ActiveChart.PlotVisibleOnly = False
ActiveSheet.ChartObjects(2).Activate
ActiveChart.ChartArea.Select
ActiveChart.PlotVisibleOnly = True
Points

ReDim a(x, y) As Single


ActiveSheet.Shapes("Freeform 1").Select
For i = 1 To ActiveSheet.Shapes("Freeform
1")._
Nodes.Count
a = ActiveSheet.Shapes("Freeform 1"). _
Nodes(i).Points
Cells(i, 1) = a(1, 1): Cells(i, 2) = a(1,2)
Next I
Position

ActiveChart.Legend.Select
Selection.Position = xlLeft
5-28

5-28
238

PrefixCharacter

'/
"
^
\

B1 B100 A1 A100

For I = 1 To 100
Select Case Range("A" & I).PrefixCharacter
Case "'"
Cells(I, 2) = "/"
Case """ "
Cells(I, 2) = ""
Case "^"
Cells(I, 2) = ""
Case "\"
Cells(I, 2) = ""
End Select
Next I
PresetExtrusionDirection

9
msoExtrusionBottomRight
msoExtrusionBottomLeft
msoExtrusionBottom
msoExtrusionLeft
msoExtrusionNone
msoExtrusionRight
msoExtrusionTop
msoExtrusionTopLeft
msoExtrusionTopRight

239

Y Excel VBA
ActiveSheet.Shapes(1).Select
Selection.ShapeRange.ThreeD.SetThreeD
Format _
msoThreeD1
MsgBox Selection.ShapeRange.ThreeD. _
PresetExtrusionDirection
PresetGradientType
25
PresetGradient

ActiveSheet.Shapes(1).Select
MsgBox ActiveSheet.Shapes(1). _
Fill.PresetGradientType
PresetLightingDirection

10
msoLightingBottom
msoLightingBottomLeft
msoLightingTopLeft
msoLightingTopRight
msoPresetLightingDirectionMixed
msoLightingBottomRight
msoLightingLeft
msoLightingNone
msoLightingRight
msoLightingTop

ActiveSheet.Shapes.AddShape(msoShapeRectangle,_
195#, 256.5, 72#, 72#).Select
Selection.ShapeRange.ThreeD.SetThreeD Format
msoThreeD1
Selection.ShapeRange.ThreeD.PresetLighting
Direction _
240

= msoLightingBottom
Selection.ShapeRange.ThreeD.PresetLighting
Softness _
= msoLightingBright
5-29

5-29
PresetLightingSoftness
4
msoLightingBright
msoLightingDim
msoLightingNormal
msoPresetLightingSoftnessMixed

ActiveSheet.Shapes(1).Select
Selection.ShapeRange.ThreeD.PresetLighting
Softness _
= msoLightingNormal
5-30

5-30
241

Y Excel VBA
PresetMaterial
5
msoMaterialMatte
msoMaterialMetal
msoMaterialPlastic
msoMaterialWireFrame
msoPresetMaterialMixed

ActiveSheet.Shapes(1).Select
Selection.ShapeRange.ThreeD.PresetMaterial _
= msoMaterialMetal
5-32
PresetShape
41

ActiveSheet.Shapes("WordArt 1").Select
Selection.ShapeRange.TextEffect. _
PresetShape = msoTextEffectShapePlainText
PresetTextEffect
31

ActiveSheet.Shapes("WordArt 1").Select
Selection.ShapeRange.TextEffect. _
PresetTextEffect = msoTextEffect26
PresetTexture
25
PresetTextured

ActiveSheet.Shapes(1).Select
242

MsgBox ActiveSheet.Shapes(1).Fill.Preset
Texture
PresetThreeDFormat
19
msoThreeD+ msoThreeD10msoThreeD4
msoThreeD17 SetThreeDFormat

ActiveSheet.Shapes(1).Select
MsgBox ActiveSheet.Shapes("Rectangle 40")._
ThreeD.PresetThreeDFormat
Previous

Shift+Tab

Sheets(2).Previous.Select
MsgBox ActiveSheet.Index
PrintArea
PageSetup
A1
A1 H80
ActiveSheet.PageSetup.PrintArea = Range
("A1:H80")
PrintComments
3
xlPrintInPlace
xlPrintNoComments
xlPrintSheetEnd
PageSetup

ActiveSheet.PageSetup.PrintComments _
= xlPrintInPlace
5-31
243

Y Excel VBA

5-31
PrintGridlines
True

With ActiveSheet.PageSetup
.PrintGridlines = True
End With
ActiveWindow.SelectedSheets.PrintPreview
PrintHeadings
True

With ActiveSheet.PageSetup
. PrintHeadings = True
End With
ActiveWindow.SelectedSheets.PrintPreview
PrintNotes
True

With ActiveSheet.PageSetup
. PrintNotes = True
End With
ActiveWindow.SelectedSheets.PrintPreview
244

PrintObject
True

With ActiveSheet.PageSetup
. PrintObject = True
End With
ActiveWindow.SelectedSheets.PrintPreview
PrintTitleColumns
False
True PrintTitleRows

Sheets(1).PageSetup.PrintTitleColumns = _
ActiveSheet.Columns("A:A").Address
PrintTitleRows
False
True PrintTitleColumns

Sheets(1).PageSetup. PrintTitleRows = _
ActiveSheet. Rows ("1:1").Address
ProtectChartObject
True

ActiveSheet.ChartObjects(1). _
ProtectChartObject = True
ProtectContents

245

Y Excel VBA
True

Protected
If Sheets(1).ProtectContents = False Then
MsgBox "no"
Else
MsgBox " Protected"
End If
ProtectData

True

Protected
If Sheets(1). ProtectData = False Then
MsgBox "no"
Else
MsgBox " Protected"
End If
ProtectDrawingObjects
True

Protected
If Sheets(1). ProtectDrawingObjects = False Then
MsgBox "no"
Else
MsgBox " Protected"
End If
ProtectFormatting

True

Protected
If Sheets(1). ProtectFormatting = False Then
246

MsgBox "no"
Else
MsgBox " Protected"
End If
ProtectGoalSeek

True

Protected
If Charts(1). ProtectGoalSeek = False Then
MsgBox "no"
Else
MsgBox " Protected"
End If
ProtectionMode

True

Protected
If Sheets(1). ProtectionMode = False Then
MsgBox "no"
Else
MsgBox " Protected"
End If
ProtectScenarios

True

Protected
If Sheets(1). ProtectScenarios = False Then
MsgBox "no"
Else
MsgBox " Protected"
247

Y Excel VBA
End If
ProtectSelection

True

Protected
I If Charts(1). ProtectSelection = False Then
MsgBox "no"
Else
MsgBox " Protected"
End If
ProtectStructure

True

Protected
If Sheets(1). ProtectStructure = False Then
MsgBox "no"
Else
MsgBox " Protected"
End If
ProtectWindows

True

Protected
If Sheets(1). ProtectWindows = False Then
MsgBox "no"
Else
MsgBox " Protected"
End If

248

Q
QueryTables

MsgBox Sheets(1).QueryTables.Count

R
Range

Range() Range()
A1

A1 H10

Range("A1:H10").Interior.ColorIndex = 6

Range(Cells(1, 1), Cells(10, 8)). _


Interior.ColorIndex = 6
ReadingOrder
xlRTLxlLTR
xlContext 3
A1

Range("A1").ReadingOrder = xlRTL
ReadOnly

If ActiveWorkbook.ReadOnly = True Then


249

Y Excel VBA
ActiveWorkbook.Close
End If
RecentFiles

MsgBox Application.RecentFiles.Count

c = Application.RecentFiles.Count
For i = 1 To c
Application.RecentFiles(i).Open
ActiveWorkbook.Close
Next i
ReferenceStyle
A1 R1C1
xlA1xlR1C1
A1
Application.ReferenceStyle = xlA1
Resize

.Resize

Cells(1, 1).Resize(8, 8).Select


ReversePlotOrder
True

ActiveSheet.ChartObjects(1).Activate
ActiveChart.ChartArea.Select
ActiveChart.Axes(xlValue).ReversePlotOrder =
True
250

ActiveChart.Axes(xlCategory).ReversePlotOrder
= True
5-32

5-32
RGB

30 30 50

a = 0
Do
a = a + 1
Cells(Int(Rnd() * 30 + 1), Int(Rnd() * 30 +
1)).Interior.Color = _
RGB(Int(Rnd() * 255 + 1), Int(Rnd() * 255 + 2),
Int(Rnd() * 255 + 3))
If a > 50 Then
Exit Do
End If
Loop
RightFooter
PageSetup
RightHeader

HELLO
ActiveSheet.PageSetup.PrintArea = ""
251

Y Excel VBA
With ActiveSheet.PageSetup
.RightHeader = "HELLO"
.RightFooter = "HELLO"
End With
RightHeader
PageSetup
RightFooter
RightFooter
RightMargin

With ActiveSheet.PageSetup
.RightMargin = Application. _
InchesToPoints(1.26)
End With
ActiveWindow.SelectedSheets.PrintPreview
Rotation

0~360 0~44
45
ActiveChart.Rotation = 45
RotationX
X -90
90 0 RotationY
Y RotationX

Selection.ShapeRange.ThreeD.RotationX = 5
Selection.ShapeRange.ThreeD.RotationY = 10
RotationY
Y -90
252

90 0 RotationX
X RotationY
RotationX
Row

MsgBox ActiveCell.Row
RowColSettings
True

True
If ActiveWorkbook.CustomViews("ET"). RowCol
Settings _
= True Then
MsgBox ""
Else
MsgBox ""
End If
RowHeight

MsgBox Rows("1:10").RowHeight
Rows

A1 A100
2
C = 0
For I = 1 To 100
If Sheets(1).Cells(I, 1) <> "" Then
C = C + 1
253

Y Excel VBA
Rows(I).Select
Selection.Copy
Sheets(2).Select
Cells(C, 1).Select
ActiveSheet.Paste
Application.CutCopyMode = False
Sheets(1).Select
End If
Next I

S
ShapeRange

ActiveSheet.Shapes("Oval 2").Select
Selection.ShapeRange.Select
Shapes

MsgBox ActiveSheet.Shapes.Count
Sheets

MsgBox Sheets.Count
ShowWindow

Chart

ActiveSheet.ChartObjects(" 1").Activate
ActiveChart.ChartArea.Select
254

ActiveChart.ShowWindow = True
5-33

5-33
ShowWindowsInTaskbar
Windows
Windows

Application.ShowWindowsInTaskbar = False
ShrinkToFit

A1
Range("A1").ShrinkToFit = True
Size

Font
A1 A10
1~10
For I = 1 To 10
Cells(I, 1).Font.Size = I
Next I

255

Y Excel VBA
SizeWithWindow

Sheets("2").Select
ActiveChart.ChartArea.Select
ActiveChart.SizeWithWindow = True
Smooth

ActiveChart.SeriesCollection(1).Select
With Selection
.Smooth = True
End With
5-34

5-34
Split
4

If ActiveWindow.Split = True Then


ActiveWindow.Split = False
Else
256

ActiveWindow.Split = True
End If
SplitColumn

Windows

MsgBox ActiveWindow. SplitColumn


SplitHorizontal
Windows

Application.OnTime Now + TimeValue("00:00:01"),


"PRO"
ActiveWindow.SplitVertical = ActiveWindow.
SplitVertical _
+ 90
SplitRow

Windows

MsgBox ActiveWindow.SplitRow
SplitVertical

Application.OnTime Now + TimeValue("00:00:01"),


"PRO"
ActiveWindow.SplitVertical = ActiveWindow.
SplitVertical + 90
StandardFont

257

Y Excel VBA
Application.StandardFont = ""
StandardFontSize

EXCEL 10.5
Application.StandardFontSize = 10.5
StandardHeight
,

1
Sheets(1). StandardHeight = True
StandardWidth

1
Sheets(1).StandardWidth = True
StatusBar
TrueFalse

NIHAO
Application.StatusBar = "NIHAO"
5-35

5-35
Strikethrough
Font

B1 P1
Dim I, J As Integer
258

Dim A As Integer
For I = 1 To 15
A = 0
For J = 2 To Int((Cells(1, I + 1)) ^ 0.5)
If Cells(1, (I + 1)) / J = Int(Cells(1, (I
+ 1)) / J) Then
A = A + 1
End If
Next J
If A = 0 Then
Cells(1, (I + 1)).Font.Strikethrough = True
End If
Next I
5-36

5-36
Styles

Range("Q10:Q14").Select
With ActiveWorkbook.Styles("Normal")
.IncludeNumber = True
.IncludeFont = True
.IncludeAlignment = True
.IncludeBorder = False
.IncludePatterns = True
.IncludeProtection = True
End With
Selection.Style = "Normal"
Subscript

Font
259

Y Excel VBA
H2
ActiveCell.FormulaR1C1 = "H2"
With ActiveCell.Characters(Start:=2, Length:
=1).Font
. Subscript = True
End With
Superscript

Font
H2
ActiveCell.FormulaR1C1 = "H2"
With ActiveCell.Characters(Start:=2, Length:
=1).Font
.Superscript = True
End With
SurfaceGroup

Range("A1:P2").Select
Charts.Add
ActiveChart.ChartType = xlSurface
ActiveChart.SetSourceData Source:=Sheets
("Sheet1").Range("A1:P2"), PlotBy:= _
xlRows
ActiveChart.SurfaceGroup.Has3DShading = True

T
TableRange2

Range("A4").PivotTable.TableRange2.Select
Selection.Interior.ColorIndex = 6
260

TabRatio

1 0.1 0.8
Sheets(1).Select
ActiveWindow.TabRatio = 0.8
ActiveWindow.TabRatio = 0.1
0.8 5-37 0.1
5-38

5-37

5-38
Text

TextBox1.Text = "ABCDEF"
TextFrame

ActiveSheet.Shapes.AddShape(msoShapeRectangle,
105.75, 150#, 72#, 72#). Select
Selection.Characters.Text = "JIUSHI"
Selection.ShapeRange.TextFrame.MarginLeft = 0#
Selection.ShapeRange.TextFrame.MarginRight =
7.09
Selection.ShapeRange.TextFrame.MarginTop =
6.52
261

Y Excel VBA
TextToDisplay

SHRT
123
ActiveSheet.Hyperlinks.Add Anchor:=Selection,
Address:="", _
SubAddress:="Sheet3!A1",
TextToDisplay:="SHRT"
Selection.Hyperlinks(1).TextToDisplay =
"123"
ThisWorkbook

MsgBox Application.ThisWorkbook.Name
ThreeD

ActiveSheet.Shapes("Rectangle 4").Select
Selection.ShapeRange.ThreeD. _
SetThreeDFormat msoThreeD1
TickLabelPosition

Y
ActiveChart.Axes(xlValue).Select
With Selection
.MajorTickMark = xlInside
.TickLabelPosition = xlNone
End With
5-49
262

5-39
TickLabelSpacing

TickMarkSpacing
TickMarkSpacing

X 2
ActiveChart.Axes(xlValue).MajorGridlines.Sele
ct
ActiveChart.Axes(xlCategory).Select
With ActiveChart.Axes(xlCategory)
.CrossesAt = 2
.TickLabelSpacing = 2
.TickMarkSpacing = 2
End With
Top

20
Application.OnTime Now + TimeValue("00:00:01"),
"17"
ActiveSheet.Shapes("Rectangle 2").Select
Selection.Top = Selection.Top + 20
263

Y Excel VBA
TopLeftCell

ActiveSheet.Shapes("Rectangle 2").Select
Selection.TopLeftCell.Select
Selection.Interior.ColorIndex = 6
5-40

5-40
TopMargin

:
0.17
With ActiveSheet.PageSetup
.TopMargin = Application.InchesToPoints
(0.17)
.FitToPagesWide = 1
.FitToPagesTall = 1
End With
ActiveWindow.SelectedSheets.PrintPreview
Type

Charts.Add
ActiveChart.ChartType = xlColumnClustered
264

ActiveChart.SetSourceData Source:=Sheets
("Sheet1"). _
Range("A1:P1"), PlotBy:=xlRows

ActiveChart.SeriesCollection(1).Select
ActiveChart.SeriesCollection(1).Trendlines. _
Add(Type:=xlLinear).Select

U
Underline
Font
xlUnderlineStyleNone
xlUnderlineStyleSingle
xlUnderlineStyleDouble
xlUnderlineStyleSingleAccounting
xlUnderlineStyleDoubleAccounting
A1:P2
For I = 1 To 10
For J = 1 To 2
If Int(Cells((J - 1) * 1 + 1, (I - 1) * 1 +
2) / 2) = _
Cells((J - 1) * 1 + 1, (I - 1) * 1 + 2) /
2 Then
Cells((J - 1) * 1 + 1, (I - 1) * 1 +
2).Font.Underline = True
End If
Next J
Next I
5-41

5-41
265

Y Excel VBA
UpBars

ActiveChart.SeriesCollection(1).Select
ActiveChart.ChartGroups(1).UpBars.Select
With Selection.Interior
.ColorIndex = 6
End With
UsableHeight

MsgBox Application.UsableHeight
UsableWidth

MsgBox Application.UsableWidth
UsedRange

For C = 1 To Sheets.Count
Sheets(C).UsedRange.Interior.ColorIndex = 6
Next C
UserName

T_JL
2
266

If Application.UserName = T_JL Then


If ActiveSheet.Name = "Sheets2" Then
Sheets(2).Select
End If
Else
If ActiveSheet.Name = "Sheets2" Then
Sheets(1).Select
End If
End If
UseStandardHeight

A1 40
ABC,
UseStandardWidth
UseStandardWidth

A1 40
ABC
Range("A1").Font.Size = 40
Range("A1") = "ABC"
Range("A1").UseStandardWidth = True
Range("A1").UseStandardHeight = True

V
Value

On Error GoTo lp1


MsgBox Cells(2, 1).Value
267

Y Excel VBA
lp1:
Exit Sub
VaryByCategories

ActiveSheet.ChartObjects(1).Activate
ActiveChart.Axes(xlValue).MajorGridlines.Select
ActiveChart.SeriesCollection(1).Select
ActiveChart.SeriesCollection(1).ApplyDataLabe
ls Type:= _
xlDataLabelsShowValue, AutoText:=True, Legend
Key:=False
ActiveChart.ChartGroups(1).VaryByCategories =
True
5-42

5-42
Version
Excel
Excel
MsgBox Application.Version
5-43

268

5-43
VerticalAlignment

ActiveSheet.Shapes("Text Box 8").Select


With Selection
.HorizontalAlignment = xlLeft
.VerticalAlignment = xlTop
End With
Visible

True False

Label1.Visible = False
VPageBreaks

MsgBox Sheets(1).VPageBreaks.Count

W
Walls

269

Y Excel VBA

ActiveChart.Walls.Select
With Selection.Interior
.ColorIndex = 6
End With
Weight

xlHairlinexlThinxlMediumxlThick
3#
ActiveSheet.Shapes(1).Select
Selection.ShapeRange.Line.Weight = 3#
Width
VBA

CommandButton1.Width = 123
WindowNumber

c = ActiveWindow.WindowNumber
Windows(c).Close
Windows

Application.Windows.Arrange
ArrangeStyle:=xlVertical
WindowState

ActiveWindow.WindowState = xlMaximized
270

Workbooks
Excel Excel

Application.Workbooks.Open Filename:= "D:\


123.xls"
Worksheet

A1 OK
For I = 1 To Sheets.Count
Sheets(I).Select
If Cells(1, 1) = "OK" Then
MsgBox Cells(1, 1).Worksheet.Name
End If
Next I
WorksheetFunction
VBA Max
Range
A1:A10
c = Application.WorksheetFunction.Max (Range
("A1:A10"))
Worksheets

2
c = Workbooks(2).Worksheets.Count
For i = 1 To c
Cells(i, 1) = Workbooks(2).Worksheets(i).
Name
Next i

271

Y Excel VBA
WrapText

Range("E12").Select
With Selection
.WrapText = True
End With

X
XValues
x

x
ActiveSheet.ChartObjects(1).Activate
ActiveChart.SeriesCollection(1).Select
ActiveChart.SeriesCollection(1).XValues=_
"=Sheet1!R2C3:R7C3"

Z
Zoom
400%
10%
200%
ActiveWindow.Zoom = 200

272

You might also like