Você está na página 1de 920

Microsoft

2010

VBA

-:



Microsoft

Excel 2010

VBA

Excel 2010
Power Programming
with VBA

by John Walkenbach

WILEY

Wiley Publishing, Inc.

Microsoft -

Excel 2010

VBA

-
2012

32.973.26-018.2.75
62
681.3.07

..
. ..
..
:
info@dialektika.com, http://www.dialektika.com

, .
62
Excel 2010: VBA.: . . . :
.. , 2012. 944 . : . . . .
ISBN 978-5-8459-1721-8 (.)
32.973.26-018.2.7S

.

, ,
, Wiley Publishing, Inc.
Copyright 2012 by Dialektika Computer Publishing.
Original English language edition Copyright 2010 by Wiley Publishing, Inc.
All rights reserved including the right of reproduction in whole or in part in any form. This translation is pub
lished by arrangement with Wiley Publishing, Inc.

Excel 2010: VBA


JI.H. , .
. .
..
..

06.04.1012. 70x100/16
Times.
. . . 76,11. .-. . 52,8
. 1000 . 3107


199034, -, 9- , 12/28
. . , 127055, . , . , . 43, . 1
ISBN 978-5-8459-1721-8 (.)
ISBN 978-0-470-47535-5 (.)

- , 2012,
, ,
Wiley Publishing, Inc., 2010

25
26

I. Excel

33

1. Excel 2010:
2. Excel
3.
4. Excel

35
49
77
101

II. Excel
5.
6.
III. Visual Basic for Applications
7. VBA
8. VBA
9. VBA
10.
11. VBA

123
125
137
159
161
211
253
287
325

IV.

385

12.
13.
14.
15.

387
405
439
473

V.

515

16. Excel VBA


17.
18.
19. Excel
20.
21.

517
537
553
603
637
659

VI.

685

22.
23.
24.
25.

687
719
737
757

VII.

771

26.
27. VBA
28. Visual Basic
29.
30.
31. Excel

773
785
813
835
849
873

VIII.
. Excel
. VBA
. VBA
. -

905
907
913
921
925
941

25
26

I. Excel

33

1. Excel 2010:

VisiCalc
Lotus 1-2-3
Quattro Pro
Microsoft Excel

Excel
Excel Microsoft

35
35
35
36
39
40
45
46
47

2. Excel




XLM
Excel 5/95
Excel

-


-



,





VBA-

SmartArt

49
50
50
51
52
52
53
54
55
60
61
62
62
62
63
64
64
66
66
67
68
69
69
70
70
71
71



Excel



Excel

72
72
72
73
75
75
75
76

3.




R11










Excel










1900

77
77
78
79
79
80
81
82
82
84
85
85
85
85
87
88
89
90
90
91
91
92
93
94
95
95
95
96
96

4. Excel
Excel

Excel




101
101
104
104
105
106
107
108
108



Excel


OfficeUI
XLB

Excel

Excel

II. Excel

109
111
112
112
115
116
117
117
118
118
119
123

5.





Excel




-
-





125
125
126
126
128
128
129
130
131
131
131
132
132
133
133
134
134
134
135

6.








ActiveX


137
137
138
139
142
143
144
144
145
146
147
148
148

10



,



Excel,
,

III. Visual Basic for Applications


7. VBA
BASIC
VBA

VBA XLM
VBA
Visual Basic

VBE
VBE
Project Explorer
VBA
VBA



VB
VBA
VBE
Editor
Editor Format
General
Docking









150
151
153
154
154
155
155
155
156
156
156
159
161
161
162
162
163
163
166
166
167
167
168
170
170
170
170
171
171
172
177
178
181
182
183
183
184
185
188
188
190
190
191
191
192

11



Comment:
Comment
Comment
Comment
Comments
Comment
, Comment

Comment
1 i a t i on
Range
Range
Cells
Offset


192
193
194
194
196
196
197
198
198
199
200
200
202
202
204
206
207
207
208

8.
VBA








With - End With
For Each - Next

GoTo
If- Then
Select Case

211
211
213
215
216
218
220
223
225
225
226
229
229
229
230
230
231
232
235
235
236
237
238
238
242
245

12

9. VBA

Sub


Run Sub/UserForm












253
253
254
255
256
257
257
258
259
259
259
263
265
265
265
269
269
270
273
274
274
274
275
275
276
277
278
279
282
282
285
286

10. '




VBA







287
287
288
288
289
290
291
292
293
294
297
297
298
300

13




VBA,
,





M a c ro O p tio n s



Windows API
Windows API
Windows
<Shift>
Windows API

302
303
304
305
307
309
310
312
314
315
316
317
319
320
320
321
321
322
323

11. VBA














,




V a r i a n t





325
325
326
326
327
328
328
330
331
332
334
335
336
339
339
341
341
342
343
345
345
346
347
348
348
349
350

14


VBA






VBA
FileExists
FileNameOnly
PathExists
RangeNameExists
Sheet Exists
WorkbookI sOpen

Excel







n-


SheetOf f set



Windows API






IV.
12.
...

InputBox VBA
Excel InputBox
VBA MsgBox

351
352
352
352
353
354
356
357
358
359
359
359
360
360
360
361
362
363
364
364
365
366
367
368
369
370
370
371
372
373
374
376
376
377
377
378
379
381
385
387
387
388
388
389
392

15

Excel G e tO p e n F ile n a m e
Excel G e ts a v e As F i 1 ename

Excel


VBA

395
398
399
399
401
401
403

13.
Excel
UserForm

Toolbox

405
405
406
407
408
408
408
409
409
409
409
409
409
410
410
410
410
410
410
410
412
414
414
415
416
418
418

Checkbox
ComboBox
CommandButton
Frame
Image
Label
ListBox
MultiPage
OptionButton
RefEdit
ScrollBar
SpinButton
TabStrip
TextBox
ToggleButton



Properties













, !

419
419
419
420
421
421
423
424
425
427
427

16

UserForm

UserForm
SpinButton
SpinButton TextBox

oolbox


ActiveX

427
428
429
429
431
433
435
435
435
436
437
438

14.
UserForm
CommandButton
List Box





ListBox
ListBox


ListBox
ListBox
ListBox
ListBox
ListBox
ListBox
Mul t iPage

Label

439
439
440
440
441
443
445
446
448
449
450
455
455
457
457
459
460
462
464
466
468
470

15.



473
474
477
478

MultiPage


Mul t iPage

Mul t iPage

481
484
484
486
487




MsgBox
MyMsgBox

MyMsgBox
Use Form
UserForm
UserForm
UserForm


UserForm
GIF-
Picture Image



Enhanced Data Form

UserForm
V.
16. Excel
Excel
VB

Text Tools





Modulel
UserForml




RibbonX


Excel

17

487
489
490
491
492
493
494
494
495
497
499
503
505
507
508
508
509
510
512
513
513
514
515
517
517
518
518
519
520
520
521
522
522
523
525
527
528
530
532
533
534
535
535

18

17.








537
537
538
539
540
542
544
545
546
549

18.






VBA



ChartObj ects Charts






VBA



Chart

Chart


/







553
554
554
555
555
556
558
558
559
561
561
562
562
564
565
566
567
568
570
573
575
577
578
581
582
584
584
584
585
588
590
591
592
593
595
596

19

597
597
598
598
599

19. Excel
Excel




,
Workbook
Open
Activate
Sheet Activate
NewSheet
BeforeSave
Deactivate
BeforePrint
Bef oreClose
Worksheet
Change
S 1 t ionChange
BeforeDoubleClick
Bef oreRightClick
Chart
App 1 i a t ion
Applicat ion

Appl icat ion
UserForm
,
OnTime

603
603
604
605
606
607
608
610
611
611
612
612
612
613
613
615
616
617
622
622
623
624
626
627
627
629
630
631
631
633

20.
Excel
Shell
API- She 11 Execute
Excel
ti vat
Microsoft Office

637
637
637
640
641
641
642
642
643
644

20



Word Excel
Excel
Outlook
Excel
SendK eys

644
647
648
650
653
655
657

21.



Excel








XLAM XLSM

XSLM XLAM
XLSM XLAM
VBA-
VBA
Addins
Addins
Addin

Addin

,


Excel

659
659
660
661
662
663
664
665
666
667
668
668
668
670
670
670
671
672
675
675
676
677
679
680
680
681
681
683
684

VI.
22.

VBA



685
687
687
690
691
692
694
695

21

RibbonX
RibbonX
RibbonX

Dynami cMenu


, Excel 2010

695
698
702
705
710
713
714
715
715

23.
CommandBar
CommandBar

CommandBar
CommandBar
CommandBar

VBA








719
719
720
720
721
721
723
723
726
726
726
727
727
729
731
732
733
733

24.
Excel

, Excel





HTML-
MHTML
HTML Help
Help

VBA

737
737
738
740
740
742
743
743
748
748
748
750
752
753
754

25.
,

757
757
758

22

759
759
761
768

VII.

771

26.



Macintosh
64- Excel


VB


773
773
774
775
776
777
779
780
781
781
782
784

27. VBA

VBA
F ile S y s te m O b je c t












Excel

HTML
XML-



ADO

785
785
786
790
793
794
795
796
796
796
797
797
798
798
798
801
802
802
803
806
808
808
810
811

28. Visual Basic


IDE
IDE

813
813
816

23

VBPro jects
VBA
VBA,

VBA VB
UserForm

UserForm

100 CommandButton
UserForm

816
818
819
820
822
824
825
826
828
828
830

29.



VBA
NumLockClass




CSVFileClass



CSVFileClass

835
835
836
837
837
839
840
840
842
842
843
843
844
844
846

30.

RGB
HSL













849
849
850
851
851
854
854
855
857
858
858
859
863
864
865
867
869
870

&

24

31. Excel

Excel
Visual Basic
'

, ,


VIII.

873
873
874
879
881
886
888
896
901
903
905

. Excel
Excel
Microsoft

Microsoft
Microsoft Excel
Microsoft Office




-
The Spreadsheet Page
, Excel


Contextures
Pointy Haired Dilbert

Excel

907
907
908
908
908
908
908
909
909
909
910
911
911
911
911
912
912
912
912
912

. VBA
Excel VBA

913
916

. VBA

921

. -

-
, -


925
925
926
926
926
926
940

941


50 , .
. - h t t p : / / s p r e a d s h e e t p a g e . com.


, !
, ,
Excel, , , .


Visual Basic for
Applications (VBA), Excel, ,
Microsoft Office. ,
Excel,

, .
Microsoft Visual Studio Tools for
Office (VSTO). ,
Visual Basic .NET Microsoft Visual #. VSTO
Excel
Microsoft Office.


Excel.
, Excel 2010.
(, 2011),
Excel ( ).
,
Excel.
. , :

, , ..;

Excel;

Excel;

Windows, , ,
.
, , , ,
. , , .
, Excel 2010,
2.

27


Excel 2010.
, , Excel 2003 2007,
, Excel 2010. Excel 2007 Excel 2010
, VBA
. ,
Excel, Excel 2010.
, Excel Macintosh. ,
( ).
Windows,
. Excel
,
.
1280x1024 ,
1600x1200 .
,
Excel, Visual Basic Editor.
-
-.

,
, ,
.

Excel
Excel 2007 ,
.
. (,
(Insert), (View) ..).
, .
, .
, .
, ,
, ,
. , , ,
:
^^ (Horned Alignment^Wrap Text).
, (File),
Backstage. ,
, .. ,
Backstage, ,
. ,
Excel (Excel Options):
^ Excel (File1^ Excel Options).

28

VBA
VBA ,
VBA. ,
. , ,
Tools ()
References ():
Tools'^ References.


, , ,
=(2 :50) 51.
,
. ,
:
=VLOOKUP(StockNumber,PriceList,2)

VBA
VBA,
. ,
. ,
. , ,
, .
,
VBA : ,
. ,
. ,
.
If Right(ActiveCell, 1) = "!" Then _
ActiveCell = Left(ActiveCell, Len(ActiveCell) - 1)

, (.. ),
, .

,
Excel
(, 20 )- , ,
VBA (
G e tT o ta ls ). , ,
, .

( myf i l e . x lsm ).


.
, .

29

,
Excel 2010.

, ,

.


- , , , .

-
,
- (.
- ).

,
.


,
, .

I. Excel
. 1
. , Excel
. 2 Excel 2010
,
Excel. 3,
, , . 4
,
Excel.

II. Excel
. 5
. 6 :
.

30

III. Visual Basic for Applications


7-11. VBA.
VB,
VBA. 11 VBA
.

IV.
. 12
.
,
, 13. 14 15
, .

V.
, ,
, . ,
VBA
, , Excel 2010. 19
, ,
, . 20
(, , Word). V
21, .

VI.
,
. 22 , 23
Excel, 24
25
, .

VII.
, .
26. 27
VBA . 28, ,
VBA Visual Basic,
. 29 . 30
Excel. 31,
Excel.

VIII.
.
, Excel.
VBA ( ). VBA

31

. , ,
-.

-
- ,
. , , ,
. , ,
, , .
,
.
- ,
, .


, , .

Power Utility
Power Utility
Excel, .
VBA.
,
Excel. VBA
. ,
.
30- Power Utility
http://spreadsheetpage.com.


, .
. ,
. ,
, ,
. ,
.


.
,
Wiley Publishing. ,
. ( www. wiley.com Contact Us.)
, . ,
, . , ,
, .

32


. ! ,
. ,
.
,
Excel:
http://spreadsheetpage.com .

!
, , .
, ,
. .
.
-
. , ,
, ,
.
, ,
.
.
:
E-mail:
info@dialektika.com
WWW:

http://www.dialektika.com

:
:
:

127055, . , . , . 43, . 1
03150, , / 152


Excel
...
1
Excel 2010:

2
Excel

4
Excel

Excel 2010:

...

Excel
Excel Microsoft



. , , , , ,
.
, .

VisiCalc
VisiCalc
1978 ,
. VisiCalc Apple II
, . (,
Apple II .) VisiCalc
, (
) . VisiCalc
, Apple II
, .
VisiCalc ,
Apple II .

I. Excel

36

,
/. Sorcim SuperCalc
, .
1981 IBM PC,
, VisiCorp
VisiCalc . Sorcim
SuperCalc, .
VisiCalc, SuperCalc
. , , , , ..
. ,

.

VisiCalc, ,
- (www.bricklin.com). 30
( 27 )
(. 1.1).

123473
833

I n come .
Expenses,

*>3660

Net

v-4

V,

"

Y
(j* f * .Vv -it-*'

. 1.1. VisiCalc, DOS


Windows

Lotus 1 -2-3
VisiCalc, ,
, ,
.

. , The Wall Street Journal
Lotus 1-2-3, . ,
.
1983 Lotus Development Corporation,
. 495 (,
),
, VisiCalc,
.

1. Excel 2010:

37

Lotus 1 -2-3
Lotus 1-2-3 VisiCalc SuperCalc , ,
16- IBM PC .
, Lotus 1-2-3 DOS
,
, .
, .
, , Lotus 1-2-3
.
,

. ,
. , Lotus
1-2-3 ,
.
Lotus 1-2-3 ( ) ,
(1)
(2) ,
(3). , 1-2-3?
Lotus , Lotus 1-2-3
1983 1.
Lotus
. 1985 1 2,
2.01 . 2,
, (add-ins) ,
, .
, 2 ,
,
.
,
.
, Lotus 1-2-3
,
, , .
Twin Mosaic Software VP Planner
Paperback Software. , (
Lotus 1-2-3) Lotus Paperback Software
. , Lotus, ,
Paperback.
1989 Lotus DOS- OS/2- 3.
, ,
.
. ,
.
Boeing Calc;
, SuperCalc 5 CubeCalc.

38

I. Excel

3 Lotus 1-2-3
, .
, ,
,
. ,
: .
3 ,
80286
1 1989 . Lotus
, .
3 ,
2.01 (
Lotus 1-2-3 2.2). 3
2. Lotus ,
: ,
, , .
, ...
, 2.2 Lotus 1-2-3
, - .
Allways,
, ,
. ,
WYSIWYG (What You See Is What You Get , ). ,
,
. ,
, Lotus 1-2-3 , ,
, -
.
1990 Microsoft Windows 3.0. , , ,
.
, , Lotus , Windows
, ,
Windows. Lotus 1-2-3 Windows
1991 . , ,
, . Windows
.
. PC World 1-2-3 For Windows
Complete Handbook, .
Excel, Windows
,
Windows- ( ). Lotus,
1993 : Lotus 1-2-3 4 Windows.
. 5 Windows
1994 .
Lotus 4.0 DOS (Lotus 1-2-3
Release 4.0 for DOS). ( ) ,

1. Excel 2010:

39

Windows. ;
3.4.
Windows ,
Lotus 1-2-3 DOS, .
Lotus (
Notes). 1995 IBM Lotus Development
Corporation. Lotus 1-2-3, , ,
, , . Excel
, a Lotus 1-2-3 .

Quattro Pro

(, , ) Borland International. 1994
Novell WordPerfect International Borland ,
. 1996 WordPerfect, Quattro Pro
Corel Corporation. Borland
1987 , , Quattro.
Buddha,
Lotus ( ). , , Lotus 1-2-3,
, , .
, . ,
, Lotus 1-2-3, , ,
,
Lotus 1-2-3.
1989 Borland Quattro Pro
, , Quattro, Lotus 1-2-3
. , Quattro Pro
, ,
. ,
. : Quattro Pro
Surpass, Borland.
1990 2.0 Quattro Pro (Quattro Pro
Version 2.0),
Paradox Borland.
Quattro Pro 3.0,

-. 1992 4,
,
. 5, 1994 ,
, ,
(.. ).
Lotus, Borland Windows. ,
1992 Quattro Pro Windows ,
Windows-,
: Excel 4.0 Lotus 1-2-3 1.1 Windows. ,
Quattro Pro Windows , UI Builder

40

I. Excel

( ).
.
, Lotus Borland. Lotus
, Borland Quattro Pro Lotus 1-2-3
, Lotus 1-2-3. ,
1994 , , Quattro Pro
, Lotus 1-2-3 (
- ). ,
, .
Borland 5 Quattro Pro
Windows. Novell Borland ,
, 5 6.
1996 Corel Corporation WordPerfect Quattro Pro.
Quattro Pro 14,
WordPerfect Office 4.
Quattro Pro
, Excel 5.

Microsoft Excel
.
, Microsoft
1980- .
Microsoft : MultiPlan,
, Excel 2010,
.
MultiPlan
1982 Microsoft MultiPlan
. ,
/,
, Apple , Apple III, XENIX MS-DOS.
MultiPlan
. ,
. ,
Lotus 1-2-3.
Excel
MultiPlan Excel,
Macintosh 1985 . Mac-, Excel
( MultiPlan). 1987
Microsoft Excel, Windows (
Excel 2.0 Windows,
, Macintosh). Windows
, Excel 2.0
Windows, Excel.
Microsoft Excel 2.1 (Excel Version 2.1). 1990
(2.lb), Windows 3.0.

1. Excel 2010:

41

2.x (. 1.2)
,
,
.
Microsoft Excel RST0 60.XLS

Microsoft Excel

Chart!
Hour H an d

Now

Chart3

Hour
1)01 A n g le
3 .Length
llfctl Is h o r t

. 1.2. Excel 2.1 Windows (


Microsoft)

Excel (XLM), ,
. ,
. , XML VBA,
. Excel 2010 XLM.
, Microsoft Excel ( 2.20) OS/2
Presentation Manager. 1989 ,
( 2.21). ,
IBM, OS/2 .
1990 Microsoft Excel 3 Windows
, (. 1.3).
, , ,
OLE (Object Linking and Embedding
), , ,
,
. , Excel 3
( Q+E).
Excel OS/2.

I. Excel

42

M icrosoft Excel REVENUE.XL3


Options Macro Is&indow
idelp
F orm al
Qata

d it Formula
FT ~ ~
1Normal w a r n -
r
1
F36
|
|
Forma Income Statement Five-year Projection

Revenues

North America

Europe

(1

France
Germany
Other European
United Kingdom

Australia
Japan
Korea
Taiwan
Fat East

' " 1
1

1992

1993

1994

1995

184,845
49,292
1.232,300

203,330
49,785
1.355.530

223,663
50,283
1,219,977

246,029
50,786
1,341,975

270,632
51,294
1,476,173

1,468,437

1,808,645

1.493.923

1,638,790

1.798.099

184,845
308.075
61.615
61.615

194.087
369,690
92,423
67,777

203,791
373.387
184.846
74,555

213.981
410.726
258.784
82.011

224.680
414,833
382,298
90,212

l i

[fj

616,150

723,977
53,231
P7Qoco
( 4j,OD4L
65,990 1
82,488

6 rest increase I 965,502


from 1991
1 64.409

1,092,023

48,392
XOQQOII
43.993
65,990

(m thousands)

Canada
Mexico
United States

m m am m
|

1991

103.110

|>287.641
N8.478
12 8

598.306

1.081.571

2,020,373

2.629.41

2.680.893

3.414.193

4.350,875

5.233.708

1,34(^.447

1.474.492

1,621,941

1.7.84,135

70,850
2,973,933
222.717
161,110

Total Revenue

Cost of Goods Sold

fJ

6,318.732

1.962.549

\m

. 1.3. Excel 3
( Microsoft)

4, 1992 , .
,
(. 1.4). ,
, Excel 4
. Microsoft IBM ; Excel 4
OS/2 , a Microsoft
Excel, .
VBA
Excel 5 1994
. ,
,
. Lotus 1-2-3 5
Windows Quattro Pro Windows ,
, , Excel 5
. , ,
VBA.
Excel 95 ( Excel 7) Microsoft
Windows 95. Microsoft , ,
Office, . , Excel 95
Excel 5. ,
. ,

1. Excel 2010:

43

Excel 95 , Excel 5. ,
Excel .
, , VBA
. , Excel 95
, Excel 5 ( , ).

File

Edit

Microsoft Excel - 60SEC.XLS


Format Data Options Macro Window

Formula

Help

Noimal

Exotic Excursions

Exotic Excursions
1992 Q1
Q2
Q3
Q4
Golf
1,000 1,100 1,200 1,300
Safari 2,000 2,200 2,400 2,600
Tennis 3,000 3,300 3,600 3,900
AutoFormat
Table Format:
Classic 1
Classic 2
Classic 3
Financial 1
Financial 2
Financial 3
Colorful 1

Colorful 3

Jan Feb
East
West
South

Total

7
6
S
18

7
4
7
18

Mar

Total

5!
8
9
22-

O p tio n s |

List 1

. 1.4. Excel 4 , Excel 5


( Microsoft)

1997 Microsoft Office 97,


Excel 97 (Excel 97 Excel 8).
,
VBA.
(
, ). Microsoft
Excel 97 ,
. , Excel 5
Excel 95, Excel 97 ,
.


26.

Excel 2000 1999 ;


Office 2000. ,

44

I. Excel

Excel 2000, ,
.
Excel 2002 ( Excel )
2001 . , ,
, . ,
.
,
Excel.
Excel 2003 ( 2003 )
Excel. . Microsoft
XML (extensible
Markup Language )
, , ,
. , Microsoft
(, ,
, ). Excel 2003
( ),
.

Microsoft Excel 2003. XML


Excel, Excel,
Office 2003 Professional. Excel
.


2006 Excel 2007 ( 12),
Microsoft Office 2007.
.
. ,
, Excel 2007 ,
, Open XML.
,
.
.
, , , .
, Excel 2007
. , Excel 2007
, .
Excel 2010, ,
Microsoft Office 2010. , Microsoft .
13,
13, Excel 14.
Excel 2010 ,
. ,
- , .
, .

1. Excel 2010:

45

Backstage , ,
. Excel
. ,
,
, ,
.


, 30-
. , ,
.
. Microsoft
, .
, OpenOffice StarOffice. ,
, Google
Spreadsheets (. 1.5). Microsoft
- Excel Office 2010.

4*

Google

123

10pt

nt

D-. -

hltp:/ 'spreadsheets.googJe.corn('ctc?key=tD?dSTCLaSZMv-Gq2Hnv

Reader

. %

: -(

| ser9eev@dialektika.c0m | |

<

^ ;

03

........................... .

2010 <-


01 01 2010
08 03 2010
01 05 2010
09 05 2010
28.06 2010
26 08 2010 (

1 S

. 1.5. - Google


Microsoft. Microsoft .
Excel
. Excel
Microsoft.

I. Excel

46

Excel

Excel
.
Excel .

.
. ,

.
VBA, .

Visual Basic for Applications.


Excel. ,
, .

. Excel
, ,
. .

. , U s e rForms, .

. VBA
, .

.
.
.
Excel 2007 .
, , .

. VBA
, .

, .
Excel ,
.

Microsoft Query.
.
, , -.

.
,
.

. -
, ,
Excel.

. VBA
, . , VBA-
Microsoft Word.

1. Excel 2010:

47

-. HTML-
Excel. , HTML- ,
-.

Excel Microsoft
Excel Microsoft Office
, (
Office). , ,
Microsoft. Office
, VBA.
, VBA Excel,

.


Excel
...



Excel


,

SmartArt

Excel



Excel

, Excel.
, Excel 2010.

50

I. Excel


Excel ( VBA),
Excel,
. Excel:

Excel;

Excel;

L i s t Box () (
);

.
, :
Excel , ,
, , .
Excel. Excel ,
VBA.
Microsoft Office.


.
Excel, VBA.
.


Excel . ,
Excel, , ,
XLSX. Excel
( ). :

XLM (, );

( , ).
( ),
. ,
. ,
, .
.
, ,
, ..

2. Excel

51

^1^
(View^ Window^ Hide). ,
.
^^ (View^Window^Unhide).
( ^1^
(View1^ W indow^New Window)).
.


.
, .
, .
Excel 2010 16 384 1 048 576 .
,
, .

, Excel 2007,
XLS, 65 536 256 .
Excel 2010
, .
XLSX XLSM-. .


.
(16384x1048576), ,
17 179 869 184 .
. .
1600x1200 ,
,
24 49 ( 1176 ) 0,000068%
. , ,
, 14,6 . .

, 500
.
36 . , 4 .
, .
. 64-
Excel, , a Excel
.


, .

. , ,
, ,

52

I. Excel

.
(
).

.
,
.
, , ^
Excel (File^Excel Options), (General)
(Include This Many Sheets).


. , , (
) . , ,
(, , ,
, SmartArt, ,
).

( , ).
( )
, .

Excel 56 . Excel 2007


. , Excel 2007
. ,
, .


.
,
. , ,
. ,
. . 2.1 ,
.

XLM
XLM ( MS Excel 4), ,
, . ,
XLM , .
, .
, XLM
XLM. XLM ,
Excel (4.0 ). , Excel 2010
XLM,
. XLM .
VBA.

2. Excel

53

. 2.1.

Excel 5 /9 5
Excel 5 Excel 95
. Excel 97
,
(UserForm). Visual Basic
.
, Excel 5/95,
, .
,
Excel 5/95.
Excel 2010
Excel 2010.

64- . Windows 64-, 64- Excel,


. -
. , ,
32- Windows API, 64-
Excel 2010. ,
API- Excel.

. ,
.

.
.

. Excel 2010
.

54

I. Excel

Office. Office,
Excel 2007, (File), .
Office Backstage,
. Back
stage (File) (Print),
.

.
,
.

.
Excel. ,
.

. Excel 2010
, ,
.

.
, .

.
(Paste)
.
.

.
. , VBA
.

.
.

. Microsoft
; .

. ,
,
. ,
.

(Solver). Excel 2010


.

VBA.
VBA ,
XLM. , ,
, .

Excel

.
, , , , ..
Excel 2007
. Excel :

2. Excel

55

;
;
;
;
-;
.

Office 2007 Microsoft


. ,
, .
, ( (),
(Insert) (Page Layout)),
. Office 2007 ,
.
.
, ,
Excel. , ,
, , .
. . 2.2 (),
. . 2.3 Excel.

. . 2.4 , .
,
.
-

? - Mktoioft !

ftmwTK*

{0 *
/

* .

*
> -

*
: *
'

Pturxntpoumtc

% t tf -*3
*
--.:

" * *

|? 3

S *
-

h 'W
Jflk

e ra

U ' *
.

........

. ..

. 2.2.
* *

g jiH

2 - Microsoft Excel

Calibri

j l l

|j

...

1 |1 ^ 1

,0 ,00
.00 *,0
rj

t* |^

* v

<2

Calibri

- |

...

- ! <3* *

iW 9/*

17,

*,

-0 3 =

]ll

<$

23
22

&

'

2 - Microsoft Excel

. 2.3. Excel
f f l l H 4 ~

* %

. 2.4. Excel

13

[j0 3

{ -

...

I. Excel

56

,
. ,
.
, .
/
<Ctrl+F1> ,
.


Excel .
, -
(, , SmartArt).
. 2.5 ,
. Excel :
(Format) ( ) (Design) ( ).
, Excel
( (Drawing Tools)
(Equation Tools)).
.

*) ; *

ofll

? Microsoft

f z z * Vx
*

TextBox 1

FS

1
3

'

1*!

iim
*

'

~f ] -----
i............i i........... ........... .........
-by/ lh2 4 ac
tX
m
4.... =7?
tr ii
;
1
---i
zzzl |
.......j fcH -... t .... I--+ -H .....1
ziztzz:
r.....
1
.... j j
-f...;
..
|......
*

9 ----------

J
6
7

........

.............. ...............

...............

4-

-----

;..........

10

* ---------------------- ------------- -----

If
12
13

------------ !-------- ;

------------

!...............

................

is

_______

'

17

|-----------IS
21

------------

------------

23

|_...........
25

.............I............ j.............!........-... j............!........ j...... i... - ....... |... 1

27

*HLftHJ:.

SSS.

/Vct3 .

.........

. 2.5. ,


, .
, .

. .
(Increase Font

2. Excel

57

Size) (Font) ().


; ,
.
.
. ,
.
(Bold) (Font)
(). ,
. ,
.
.
.
, , . ,
.
(Merge and Center) (Align
ment) ().
, .
.
( )
( ).
. , .
,
.
(Paste),
(Clipboard) ().
, .
, , (. 2.6).
. /.
(Gridlines)
(Show/Hide) (View). ,
. , .
. (Scale to Fit)
(Page Layout).
;
.


Excel 22.

,
. ,
(Alignment) () (. 2.7).
(Format Cells)
(Number). , .

I. Excel

58

*
0

<
-

11
- -

D

21 *"1 5

...

. 2.6.

Excel 2007 ,
Excel 2010
.
22.

. 2.7. ,


.

. .
.

(Show Quick Access Toolbar Below the Ribbon).
:
(Save), (Undo) (Redo). ,
.

2. Excel

59

,
(Add
Quick Access Toolbar).
Excel , .
.
. 2.8,
(Quick Access toolbar) Excel (Excel Options).
.

(Customize Quick Access Toolbar).
Excel

... ....

| ( }

< >

&

I
I
|>


...

1?

>|

...

...

...
!_________ ______________________

]>

CftpOC

. 2.8.
Excel


,
. ,
, , (
<Alt>) .
. <Alt>.
, , .

, ,
<Alt>.

60

I. Excel

. 2.9 () <Alt> (
). ,
, . ,
,
<Alt>, <> ( ()),
<> <L> ( (Align Left)).
( ),
.

. 2.9. <Alt>

<Alt>
> < . ,
<1> . > <
. <Enter>.
, ,
, .

Excel 2010 Excel 2003,


. , ,
, <Alt+ES>
( (Paste Special)).

-
, Excel, .

. -. ,
,
. ,
, , ..

- .
. . 2.10 -
, .
VBA ,
. VBA
- .


23.

2. Excel

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24

61

Calibri

J]

* *
154,541
*

' A ' i' S H

- ^

fcart
yftj

* <8 <9

&

.,.
...
...

...
...
...

...

........ ; : i

. 2.10.
-


.
,
.
Excel .
.
, - .
(Format Cells).
- , ,
. ,
(Cancel) .
.
. ,
(Format),
.
(Close) , (Cancel).
Excel ,
.
. (
. 2.11) .

UserForm ( ).
, .

I. Excel

62

- I

:
I

... j

-------------------------------------------
|

X: jo irr

X: 1100% |

: |0

~ ||j

Y: | l 0 0 % J j |

: [

&-

. 2.11.


IV.


Excel .
,
, <Ctrl+D>. Excel
,
, .
Excel.
,
.
, .

-
- ,
. -
,
. ,
- (. 2.12).


Excel 2002. ,
,
. .

2. Excel

63

,
, , ,
XML (extensible Markup Language). . 2.13,
(Clip Art).

:
I
Office.com
I ......

1
J_

9 4 /8

9 9 ,2 !

JL

1 0 4 ,5 ;

JL
8

H I
............7
s
]

Mia- *

11

-------------- ]........................4

12

\jm

----

13
15 --------------

L iz :

1-------------- t~------------- 1

17

it

----

-----i

s a ia
............."1 ------------1......

Office.com

i....... ..z ..

. 2.12. -,

. 2.13.

Visual Basic Editor


.
Excel 2010
VBA, VB Editor ,
Excel. Microsoft Office
, VB Editor
- .
, VB Editor ,
.


Excel
( , , ..).
(View).
Excel ,
. ,
^ ^ (View^Workbook Views^
Full Screen), .

64

I. Excel

, .

(Close Full Screen).
,
.
. ,
.


Excel .
Excel :

( / );

( );

.
(=). Excel
Lotus 1-2-3 (@),
(+) (-).
<Enter>.

,
, .
Excel ,
. ,
, , (
, , ).

3.

Excel ,
, .
^
(Formulas^Formula Auditing).
^
(Formulas^Formula Auditing^Error Checking).

. . 2.14 , Excel ,
, .

, .
Excel .

(Insert Function), . 2.15.

2. Excel

65

(Insert Function),
, <Shift+F3>.
(Function Arguments),
.

142

142

142

142

142

196

177

196

180

196

254

136

136

136
*6

136

143
143

136

106

106

106
6

106

106
106

106

148

222

148

148

148

148

127

127

143

127

127

127

150

150

150

150

150

150

190

190

190

190

190

190

114

114

114

114

114

114

102

102

654

102

102

765

167

167

167

167

167

167

2146

5357|

1585

2299

142

1578

1633

. 13

=(13:013)___

.....

.

. 2.14. Excel
- 1 2
:
,
(, "
;

ABS
ACOS
ASIN
ASINH
ATAN
ATAN2

________

05( )
.

. 2.15.


Excel 2007 ,
Analysis ToolPak ( ), .
, ,
Analysis ToolPak .

. 3107

I. Excel

66


Excel
VBA.
10.

, , ,
, .
, (
). , .


3.
, .


, Windows.
,
. , ,
. ,
<Ctrl>. ,
, ,
, , <Shift>,
.

.
, <Ctrl>
.

,
. ,
<Esc>
<Ctrl>.

Excel : .
, .
,
(. 2.16).
.

. , (
),
.
,
.

2. Excel

67

JJiSl

J J

| |

J j

"3:

. 2.16. Excel

,
.
,
(Format) ,
.

<Ctrl+l>.

(Format ), .
. ,
.
Excel , .
, 1^
^ (Horned Styles^Conditional Formatting).
,
. , ,
.
Excel 2007 ,
, .
. 2.17
.


Excel . ,
,
VBA-.

68

I. Excel
'

1
2
3
4

" ......

21
-9

_ 3 M

9
10

12 _________
13 _________

14
15

14
-19
-19
-7

___ 53

49
---------- -------------------- L

16
17

.......

. 2.17. ,


.
.
1. , .
2.
(Format Cells).
3. (Format Cells),
(Protection).
4. (Locked).
5. .
6. ^1^ (Review^
Changes^Protect Sheet).
(Protect Sheet), . 2.18.
7. ,
, ( )
.

().
, .

, Excel
. ,
(Hidden) (Protection)
(Format Cells).

2. Excel

69


,
.
(Protect Structure and Windows), ^^ (Review^Changes1^ Protect Workbook).
. 2.19. (Structure).
(Windows),
.

Jjxj

W
|
*
*

"

"
_______________

-----



( ):

OK

. 2.18.

. 2.19.



, .
^1^
^ (File^Info^Protect Workbook^Encrypt With
Password). (Encrypt Document)
(. 2.20). .


:

'|

!
.
.
,
.

. 2.20.

I. Excel

70

VBA-
VBA-,
. VBE
( <Alt+Fl 1>) Projects ().
Tools^xxx Properties ( ).
.
, Protection () (. 2.21).
Lock Project for Viewing ( )
. .
.

. 2.21. VBA-
Project Properties ( )

, Excel . ( ),
,
,
, (
).

Excel .
,
. .


, .
Excel 2010
. .
Excel. . 2.22 ,
.

2. Excel

71

-13

103,98

98,92

88,12

86,34

75,58

71,2

-09

212,74

218,7

202,18

198,56

190,12

181,74

-88

75,74

73,68

69,86

60,34

64,92

59,46

W-91

91,78

95,44

98,1

99,46

98,68

105,86

324,48

309,14

313,1

287,82

276,24

260,9

10
-13

103,98

98,92

88,12

86,34

75,58

71,2

212,74

218,7

202,18

198,56

190,12

181,74

69,86

60,34

64,92

59,46

14 W -91

................ !........
91,78

73,68
95,44

98,1

99,46

98,68

105,86

15 -03

324,48

309,14

313,1

287,82

276,24

12 -09
13 -88

_____
_____ '
mi

260,9

_____

16
17 /
18

19 -13

103,98

98,92

88,12

86,34

75,58

-71,2

20 -09

212,74

218,7

-202,18

198,56

190,12

181,74

21 -88

75,74

73,68

69,86

60,34

-64,92

22 W-91

91,78

95,44

98,1

99,46

98,68

59,46
105,86

23 -03

-324,48

309,14

313,1

287,82

276,24

260,9

24

. 2.22.

SmartArt
, ,
, , (,
), .
Excel
.
^^ (Insert^Illustrations^Shapes).
.
, ,
, .
Office 2007 SmartArt.
.
SmartArt . 2.23.



.
Excel
.
, , .
. ,
.
.
.

72

I. Excel

. 2.23. SmartArt



, .
Excel 2007
.
^ ^ (Insert^Tables^Table).
:
, , ,
. ,
, .
.
,
(. 2.24). ,
, .


1^
(Data^Get External Data). Excel 2010
.

Excel
Excel , .
,
HTML, -. ,
, (
).

2. Excel

73

---- ......................

Q 62 Q 4 Q 65

Q Q 7 Q

3 J |

___

30,336,00.

33,370,00.

36,707,00.

100,413,00.

40,377,00.

44,415,00.

48,856,

'!*

20,572,00.

22,629,00.

24,892,00.

68,093,00.

27,381,00.

30,119,00.

33,131, |

''ifc

0 ( )

0
I
; 0

0 *

0
j- 0
0
0
| |

15.

16

17
18

94,473,00.'' 103,920,00. 114,312,00.


126,739,00. 139,413,00. 153,354,00.

131,685,00. 144,854,00. 159,339,00.

_____________

11

435,878,00. 175,273,00. 192,800,00. 212,080,


312,705,00. 125,744,00. 138,318,00. 152,150, |
419,506,00. 168,690,00. 185,559,00. 204,414,

|403,805,00. 444,186,00. 488,604,00. 1,336,595,00. 537,465,00. 591,211,00. 650,631,(j |

,1............ ...^ d
0*1 '

10,341,00.

11,272,00.

12,286,00.

33,899,00.

13,392,00.

14,597,00.

15,911,

6,546,00.

7,135,00.

7,777,00.

21,458,00.

8,477,00.

9,240,00.

10,072,

65,843,00.

71,769,00.

78,228,00.

215,840,00.

85,269,00.

92,943,00. 101,308,

63,967,00.

69,724,00.

75,999,00.

209,690,00.

82,839,00.

90,295,00.

72,314,00.

78,822,00.

85,916,00.

237,052,00.

93,649,00. 102,077,00. 111,264,(

219,011,00. 238,722,00. 260,206,00.

98,421,0

717,939,00. 283,626,00. 309,152,00.

19

20

21,529,00.

23,036,00.

24,649,00.

69,214,00.

26,374,00.

28,220,00.

30,196,

21

15,946,00.

17,062,00.

18,257,00.

51,265,00.

19,535,00.

20,902,00.

22,365,

27,554,00.

29,483.00.

31,547,00.

88,584,00.

33,755,00.

36,118,00.

38,646,

22
]

J^ ctS

. 2.24. Excel

Excel HTML
. ,
HTML Excel,
. Excel 2007
. HTML
.

-, ,
.
. . 2.25.


, Excel (
).
, Excel .
.
(,
, ). Excel (,
), .
,
.
Analysis ToolPak ( ). Excel
Analysis ToolPak
,
. Excel 2007
, Excel
.

74

I. Excel

~3 1nyqs| 9

! I http://wvw^ftTm arlcetco^
0

[+1

USD

3 J Q .

, , ".

/
I

II


16.03.10
16.03.10
16.03,10
16.03.10
16.03.10
16.03.10
16.03.10
16.03.10
16.03.10
16.03.10
16.03.10

09:27
09:38
09:41
09:31
09:13
09:01
09:04
09:02
08:57
08:58
09:00

7.9900
8.0000
7.9910
7.9900
7.9900
7.9900
7.9900
7.9900
7.9900
7.9900
7.9900

8.0100
8.0100
8.0100
8.0100
8.0100
8.0100
8,0100
8.00
8,0100
8.0100
8,0100

044-5374827
044 5314142
044 3932563
044 3902586
044 4540185
064 2351835
032 2422131
062 9490965
048 7343721
-00 0000001
0552464941


-

-

.
.
.
.

.

.
.

16.03.10 08:56

7.9900

8.0100

056 7135720

16.03.10 09:03

7.9900

8.0100

037 2558293

16.03.10 09:38

7.9950

8.0100

16.03.10 09:26

7.9950

8,0080

16.03.10 09:37

7.9630

8.0070

16.03.10 08:45

7.9630

8.0130

044 2371920

044 2558104

056 7911845
.

044 2879586

16.03.10 09:39

7,9950

8.0100

044 2380921

16.03.10 09:23

7.9800

8,0100

044 2075515

. 2.25. -,

. Excel
. ,
. ,
, VBA.
,
, -,

. . 2.26.


17
VBA.

. Excel
(Solver),
,
.

w ffigp

Excel 2010 ,
.

2. Excel

75

.......D ................. ]

......

. 1 . 2 *( . 3 . 4
2667,6

4013,1

4836

6087,9

702

BER6S

312

BOLID

1170

ANTON

7
8

1170

10

ERNSH

1123,2

2607,15

11

G OD OS

280,8

12

HUNGC

62,4

13

PICCO

1560

936

14

RATTC

592,8

15

REGGC

741

16

SAVEA

3900

789,75

17

SEVES

877,5

18

WHITC

780

19

551,6

665

20

ANTON

560

21

SAVEA

554,4

140

22

THEBI

23

TO M SP

24

VAFFE

25

WHITC

179,2

105

196

372,4

. 2.26. Excel

, Excel
. ,
(Add-Ins) Excel (Excel Options).
, Excel, ,
- Microsoft (h t t p : / / o f f i c e . m i c r o s o f t . c o m ).
, ;
.
, 21.


Excel : XLM VBA.
XLM,
VBA. Excel 2010 XLM-,
. XLM-.
VB.


VBA III.


Excel
. Excel 97 Excel 2003
, .
Excel 2007 , Excel 2010.

76

I. Excel

, Microsoft ,
Excel. Excel
XLSX.
.
, Excel 2003 ,
Excel 2007, , .

4
Excel, 26,
.

Excel
Excel .
( <F1>),
Excel,
.

(Search)
.
(. 2.27).
: Excel

&

P
Excel 2010 Dwetoper Reference > Object 11*

S3
t

Office.com
Excel

Welcome to the Object Libr


This reference contarts conceptual ov
in developing solutions based on Micr<
We welcome your comments or quest

docthis@microsoft.com.

Publish date of this reference: March


This documentation is accessible from

Excel

2010

Excel

?rences to guide you

Excel

:to


Excel

From the product: To view the version of this reference that is induded with Office 2010, dkk
the Help button in any Office product, and then dick the Search drop-down arrow. Under
Content from this computer, dick Developer Reference.
From the MSDN Library: To view the most recent version your browse-, see the Object
Library Reference for Microsoft Office 2010 in the MSDN Library.
The documentation contains the following sections:

W hat's Hew: Provides fists of new objects, enumerations, and members.


Concepts: Provides important concepts for developing custom Office solutions.

How Do I: Provides a fist of how-to topics for developing custom Office solutions.

Reference: Provides reference materials for the Office object model.

Related Links
Microsoft Office Developer Center
AccessibilitY in Microsoft Products
Document Conventions in Office Developer Documentation
Object Library Reference for Microsoft Office 2010 Copyright Notice
Microsoft Online Privacy Statement

. 2.27. Excel

j ^



...





Excel



,
.
.


M icrosoft Excel 2010 (, 2011).


. ,
(
, ).
, :
+ () * ();
( );

I. Excel

78

(,

).

Excel 2010 8192 .


. ,
, .
.


, , , .
, ,
. ,
(Excel Calculations) (Automatic). ,
, . ,
, .

(,
), Excel
.

Excel
, ,
. , .

. ,
D12 Dl 1,
Dl 1 D12.
, Excel , ,
. , ,
,
. .
^ (Formulas^Calculation)
(Calculation Options).

, (Calculate).
.

<F9>
.

<Shift+F9>
.
.

<Ctrl+Shift+F9>
. ^.
, Excel -
,
, VB.

3.

79

<Ctrl+Alt+Shift+F9>
,
( , ).

Excel
.
, .


.
( ),
, . .
. .
,
(, 1).
. .
, (, $$1).
. .
, , ,
,
(, $1).
. .
,
, , ,
(, $1).
.
, .
-: ,
, <F4> ,
.


, - ,
(. 3.1). '
:
=$*$2


( ) ( 3).
, 7, , F7.
( 2,
, ),
.
,
, .

80

I. Excel

1
2
3
4
5

6
7
8
9
10

Z
S

>

2,5

1,0
1,5
2,0
2,5

1,5
1*5
2,3
3,0
3,8

2,0
2,0
3,0
4,0
5,0

2,5
2,5
3,8
5,0
6,3

3,0

3,0

4,5

6,0

7,5

1,0
1,5

____ 0

. 3.1.

R11
, Excel 1. ,
, , , ,
. , Excel R1C1.
( R row, .. , column, .. .)
1 R1C1, 2 R2C1 ..
R1C1, (Formulas)
Excel (Excel Options). R1C1
(R1C1 Reference Style). ,
. ,
.
. 3.1 ,
R1C1. , 1 (
R1C2).
3.1. ,

= 1 +1

R1C1

=$$1+1

=R1C1+1

=$1+1

=RC1+1

=$1+1

= R 1 C [ - 1 ] +1

=( 1 : 1 0 )

=(RC [ - 1 ]

=( $ $ 1 : $ $ 1 0 )

=( R 1 C 1 :R 1 0 C 1 )

= R C [ - 1 ] +1

:R [ 9 ] [ - 1 ]

R1C1 , ,
. ,
, .
.
, R [-5] [-3] ,
, .
, R [5] [3] ,
. ,

3.

81

. , R [5] ,
.
, R1C1 ,
. .
R1C1,
.
(, ). R1C1
. - , ,
, .
, V B A , , ,
R1C1.


, ,
, .
, ,
. ,
(2).
=2 ! 1 + 1

, ,
.
( ), .
= [ . x l s x ] 1 ! 1

, , ,
( ) .
= ' [ 2 0 1 0

. x l s x ] 1 ' !1

,
.
=' :\ \ E x c e l \[ 2 0 1 0

. x l s x ] 1 1 !1

.
. .
(
, ).

. ,
^ (File^Save As),
, (
). :
, .


Excel 2007 ,
( Excel
^^.
.

82

I. Excel

Excel
( , ).
. ,
.
.
, -,
, .
Excel ,
.
( !).

,
.
. ,
() .
.
= 1 [[#Totals], [ ] ]
=SUM( 1 [ ] )
= 1 [[#Totals], [ ] ]- 1 [[#Totals],
=SUM( 1 [ ] )- ( 1 [ ] )

[ ] ]

= (1 [ ] , " " , 1 [ ])
= [@ ]


.
, .


Excel
. ,
, , , . ,
Excel, ,
(. ).


Excel .

^ (Formulas1^
Named Cells^Name a Range)
(New Name).

3.

83

(Name Manager).
^ ^
(Formulas ^Defined Names Name Manager) <Ctrl+F3>.
, ,
(New)
(Name Manager) (New Name).
, (Name)
<Enter>. , ,
.
,
, (
) ^ ^
(Formulas=>Defined Names^Create from Selection).
, . 3.2 : ' ', 4:4 '' ..
:6 ' 2 ' , :6
12 ' .. , Excel ,
( ).
.............^ ...

... i

L [

_L
2 ...............................1!
3

t;

4
5
6

^ 1[

690

6858

8204

7S87 L

8168

7015

7387

6812

8SG9

71

9029

6649

775?

7408

7903

7
8

...........J

.......

9 _________________
10
j--------------------------
12
13
14
15

...*

___________1

,_________ ________

iTb :
- ........... 1 ............

awwej
F |

: qpaea

16
17

____
]
OK

;............... I................

18
19

ail

21
22
23
i > ! 1

...........

<;

> i\

. 3.2. Excel

VBA,
. ?
: ( ),
VBA, , VBA-
. , VBA- 4,
Range (" 4" ),
.
, ,
R ange( " I n t e r e s t R a t e " ).

84

I. Excel


, Excel
,
. , F10 :
= 1- 2

1 , 2 ,
:
= -

, .
, .
^ *=> (Formulas^Defined Names^Apply
Names). ,
, . ,
, .

Excel .
, ,
(Name Manager). ,
(Solver). .
, .
, .

VBA.
Sub D e le te H id d e n N a m e s ()
D im n As Name
D im C o u n t As I n t e g e r
F o r E ac h n I n A c tiv e W o r k b o o k .N a m e s
I f N o t n . V i s i b l e Then
n . D e le te
Count = C ount + 1
End I f
Next n
MsgBox C o u n t & " ."
End Sub

, . ,
,
. , ,
,
### #?.
Power Utility ,
, ,
.

3.

85


Excel .
,
. .
, .
. 3.2. :
=2

7015 2 .


Excel
. 1 :6.
, 2 ..
: 3,
4 ..
, ,
,
.
, ,
. , , ,
7, 1.



. , .
,
. ,
(, 1!).
, ,
. ,
, .
.
(Name Manager) ( ^
^ (Formulas^Defined Names^Name Manager))
(. 3.3).
. ,
(Scope),
.


Excel ,
( Excel ). , ,
, ,
(.. ).

I. Excel

86

,
.
(, ), . ,
:
= *

)
|

[
.. j

...

j j

<

{
509;8321;
90".

=!$$5:$$5

{7903"; *6968"; "77,..

= ' S?S6: SES6

<D2

{"909':,818':85...
858*:"7015*:*83...

= 3* SBS3: SBS6

=! $$3: $$6

{204":7387":,90...

=! $D3: $

<31)4

n 9 8 7 :"6812:"66.r

=! $$3: $$

f6 9 0 9 ;"6858*;*82...

=? $8$3: $$3

133 1

{""; "...

=/12! $$2: $D$8

<1)

f8168*;*7015,,;*73...

=<|8$4:$$4

I
1

J | =3|$8$3:$8$6

.........: r

~ : r : k

. 3.3.

(New
Name) (Refers ) (. 3.4).
^
(Formulas ^Defined Names^Define Name).
, .

, , .

JtlJd

__
:

=0,0725

. 3.4. Excel
,

3.

87

. ,

. =,
.


, ,
. , , ,
, .
(Refers ) (New Name).

.
, ,
( ).

. 3.5 (=1^1), (Refers )


(New Name). 1,
, ( ,
).
- = , , ,
, . , 10
3 4, D10
, 81 (3 4- ):
=

2
3
4

5
6

1!

-X? I| il l
:

---------

:
:

&

jJ i

7
8
9
10
11
12

13
14

. 3.5. ,


(Name Manager), , (Refers )
, . ,
D32, :
=1 ! 3 2 1 ! 32

I. Excel

88

, . ,
,
, .
, 1,
( ). .
=!1 !1
, , ,
. ,
. ,
.
-
-
. named formulas.xlsx.

(New Name) (Refers )


.
.
<F2> ,
.


Excel
. .
.
, , .
Excel ,
, .. , .
, Excel.
(New Name),
(Refers ) , (Name) .
, (Refers )
.
,
, .


,
, , , .
, VBA.
, ,
(Name), . ,
<Enter>.

3.

89

,
. <Enter>.

Excel
. ^^^ (Chart Tools^Layout^Properties^Chart Name).

Excel
, , , ,
. , ,
, .

, ,
. , ,
^ (Formulas1^ Formula Auditing).
. 3.2 ,
.
3.2. Excel

# / !

(
).
,
( ) ,
, .
, # / ,

, Excel.
,

,
( )
; ,
.
,
. Excel
, , 1-307, , 1+308
.
,
.
( ),
. , ,
VBA-,
:

# /

#?

#!

#!
#

#####

I. Excel

90


, .
,
.
, , (Excel
).
, 1x5 1x5,
, 1x5. ,
;
.
, .
1:5
1:5. .
{= 1 : 5 * 1 : 5 }

<Ctrl+Shift+
Enter>. , ,
, .
, .
.


Excel
, ,
.
, .
. 3.6 1:5.
, ,
, .
,
, ,
.
1
-

4.

j n
4

- (*

'

*]{=((1:5))}

.1 ,

.'-'. ...4

31
31
31
31

JL

. 3.6. 1 ,
,
1 :5.

3.

91

, ,
, . 3.6, .
1. 1:5.
2. :
=( 1 : 5 )

3. <Ctrl+Shift+Enter>.
.
, 1:5,
, 1:5 31 .
, 1:5
, . ,
(
<Ctrl+Shift+Enter>):
{= ( ( 1 : 5 ) ) }

( ) ,
, 1:5.

31.


. 3.7 .
, 42 .
, 5:10, .
(= ( ( ( () ;() ; 1) ) ( ( (3 ) ;
(); 1 ) - ( ( ( ( ); ( );1 )) - 1 ) +
{ 0 : 1 : 2 : 3 : 4 : 5 } * 7 + { 1 ; 2 ; 3 ; 4 ; 5 ; 6 ; 7 } - 1 ) ; " " ; ( ( ) ;
(); 1 ) - ( ( ( ( ); ( ) ; 1 ) ) .
1) + { 0 :1 : 2 : 3 : 4 : 5 } * 7 + { 1 ; 2 ; 3 ; 4 ; 5 ; 6 ; 7 } - 1 ) }

,
,
(d).

- , .
array examples .xlsx. , -
yearly calendar .xlsx,
.



:
;
;

92

I. Excel

, -
.

JL
2
3
4

10

, 2010

11

18

25

26

12

13

14

15

16

17

19

20

21

22

23

24

27

28

29

30

31

10
11

12
13
14
15

. 3.7.
,

, :

<Ctrl+
Shift+Enter>.


Excel ,
.
,
.
.

Excel 2007 ,
: (COUNTIFS) (SUMIFS).
: Excel 2007 ,
Excel.
. 3.8 ,
. :

2:10;

2:10;
2:10.

3.
D

93
F

100

200

2 =300

300

2 >300

150

8 <>100

250

350

3 , "

G
0

10

200

300

400

12

, 5

1 "" >200
1 "" ""

2 "" "" "

, 300 400

13

14
15

1,600 , 300

16

600 ""

17

1,350 " "

18
19

100

100 " ""

500

500 " ""

20

500

21

1,350

500 >=200 ""


1,350 , 300 400

. 3.8.

-
( )
- ( c o u n t i n g a n d summ ing e x a m p le s . x l s x ) .


. 3.3 , .
3.3.

= (R e g io n ; " " )

, R e g io n

""
= (S a le s

; 3 00 )

, S a le s

300
= (S a le s

; " >3 00 ")

, S a le s >
300

= (S a le s ; " < > 0 " )

, S a le s <>
100

= ( R e g io n ; " * * ")
,
( )
= (M o nth ;
, M onth = "" S a le s >
""; S a l e s ;" >200 ")
200 ( Excel 2007 )
{= ( (Month= " ") *
, (Sales>200) ) }
M onth = " " S a le s > 200
= (M o n th ;
, M onth = "" R e g io n =
""; R e g io n ;" ")
" ( Excel 2007 )

= (R e g io n ;" ? ? ? ? ? " )

I. Excel

94

. 3.3

{= ((M o n th = " ")


( R e g i o n = " C e B e p " )) }

,
M o n t h = " " R e g i o n = " "
, M o n t h =
" " R e g i o n = " " "" (
Excel 2007 )

=(M o n th ;
" " / R e g io n ; 11)+
(M o n th ;
" " ; R e g io n ; " ")
{ =( (M o n th = " ' ) *
( (R e g io n = " ")+
(R e g io n = " I0 r" ) ) ) }
=( S a le s ;
" > = 3 0 0 " ; S a l e s ; "< = 4 0 0 " )
{= (( S a l e s > = 3 0 0 ) *
( S a l e s < = 4 0 0 )) }

,
M o n th = " " R e g i o n = " " ""
, S a l e s
300 400 ( Excel 2007
)
, ,
S a l e s 300 400


. 3.4 ,
.
3.4.

, 200
=( M o n t h ; " " ; , M o n t h

=(S a l e s ; " 0 0 " )

S a le s )
=( M o n t h ; " ";
S a l e s ) +
(M o n th ;
" " ; S a l e s )
=(; ;
" " ; ; " ")

" "

, M o n t h = " "
" "
, M o n t h = " "
= " "

, M o n th =" " R e g i o n =
" " ( Excel 2007 )
{= ((M o n th = " " ) *
, ,
(R eg io n = "C e B ep ") * S a l e s ) }
KOTOpbixMonth = " " R e g i o n = " "
=( S a l e s ; M on th ;
, M o n th = " " R e g i o n <>
" " ; R e g i o n ; " " ) " " ( Excel 2007 )
{=(( M o n th = " " ) *
, ,
( R e g i o n o " C e B e p " ) * S a l e s ) } KOTOpbixMonth = " " R e g i o n <> " "
=( S a l e s ; M o n t h ;
, M o n th = " " S a l e s >=
" " ; S a l e s ;">=2 0 0 " )
200 ( Excel 2007 )
{= (( M o n th = " " ) *
, ,
( S a l e s > = 2 0 0 ) * ( S a l e s ) )}
KOTOpbixMonth = " " S a l e s >= 200
=(S a l e s ; S a l e s ;
, 300
" > = 3 0 0 " ; S a l e s ; "< =400")
400 ( Excel 2007 )
{= (( S a l e s > = 3 0 0 ) *
, ,
( S a l e s < = 4 0 0 ) * ( S a l e s ) )}
300 400

= ( S a l e s ; M o n t h ;
" " ; R e g i o n , " ")

3.

95



, :
( );
;
(DCOUNT) (DSUM);
. ^
.


Excel
. , Excel, 1 1900
. 1. 2 1900
2 ..
,
. , a Excel
. , 15 2010 , 1 5
2 0 1 0 ( ).
Excel
40405, .

,
Excel 2010. (
Excel) . ,
August 15, 2010.


, ,
. , Excel,
.
, , .
, Excel , ,
, , : ,
. , 15 2010 40405.
( ) 40405,5. ,
.
,
. ,
.
=2 - 1

I. Excel

96

, .
, 0 1900
( 0). ,
.
Excel ( #########).
? 1904 .
Excel (Excel Options), (Advanced)
1904 (Use 1904 Date System).
,
,
.


. ,
.
, , 24 .
24- Excel .

,
. , ,
24- .
[ ]:

1900
, 1 1900 . ,
Excel ,
, , 1 1900 . ,
, .
, Excel , 4 1776 .
, , , , .
, , ,
, , .
, VBA
. VBA,
1900 . . 3.9.
Excel VBA.


10.



, .. ,
, , - . ,

3.

97

,
, .
? (, ,
), .
, .

.....

1 VBA,
2

190 0 .

5
6

1732

22

22 , 1732

101,678

278

1735

10

30

30 , 1735

100,332

274

1743

13

13 , 1743

97,610

267

10

1751

16

16 , 1751

94,716

259

11

1758

28

28 , 1758

92,116

252

12

1767

11

11 , 1767

88,755

243

13

1767

15

15 , 1767

88,873

243

14

1782

5 , 1782

83,129

227

1773

12

15

9 ,1773

86,715

237

16

1790

29

29 , 1790

80,458

220

17

1795

11

2 , 1795

78,414

214

18

1784

11

24

24 , 1784

82,409

225

19

1800

76,887

210

20

1804

11

23

23 , 1804

75,106

205

21

1791

23

23 , 1791

80,068

219

22

1809

12

12 , 1809

73,564

201

23

1808

12

29

29 , 1808

73,609

201

24

1822

27

27 , 1822

68,742

188

7 , 1800

. 3.9.
1900

. ,
( ) . ,
.
. ,
Excel 1^ ^ (Data^Data Tools^
Convert Text to Table) .
. ,
.
. 3.10
, . 3.5.
, . -G,
.
D

G
6

3 .

10

10

10

10

13

13

6 .

7 .

#!

8 .

8
#!

8
4

1I

10
11

. 3.10.

43. 3107

98

I. Excel

3 .5. , B:G

= (2)
= ( 11 " , 2 , 1)
=(" " , 2, 2+1)

=((D2) , 2, D2)

F
G

=(2,2)
=(2, LEN(2) -2)
=F2&G2



.
#!
,



, .
: ,

, ( ). ,
.
, 2 , 2.
.
= ( (2 ) ,
(" " , ( 2 ) , 1 ) ) & ( ( 2 ) , (
( 2 )) - ( ( (" " , ( 2 ) ,
(" " , (2 ) , 1 ) + 1 ) ) , ("
" , ( 2 ) , 1 ) , (" " , ( 2 ) ,
(" " , (2) , 1 ) + 1 ) ) )

, ,
, .
, ,
, , .
, ,
. ( ,
).
VBA . :
=NOM IDDLE( 1 )

,
. .
F u n c t i o n N O M ID DLE(n) A s S t r i n g
D im F i r s t N a m e A s S t r i n g , L a s t N a m e A s S t r i n g
n = A p p lic a tio n .W o r k s h e e tF u n c tio n .T r im ( n )
F irstN a m e = L e f t ( n , I n S t r ( l , n, " "))
LastN am e = R ig h t ( n , L e n (n ) - I n S t r R e v ( n , " "))
N O M ID D LE = F i r s t N a m e & L a s t N a m e
End F u n c t io n

-
, ,
VBA- n o m i d d l e , -.
m e g a f o r m u l a . x l s m .

3.

99

,
. . ,
175000 . ,
. ,
(. 3.6).
3.6.

5,8
3,9

12,6
2,95

,
, .
VBA
5 . , VBA-
Excel.


Excel
...

Excel


Excel
OfficeUI
XLB

Excel

, Excel,
Excel?

Excel
Excel -
: , ,
(Start) ,
Excel.
e x c e l . .
Excel :
, Windows;
,
E x c e l . o f f i c e U I ;
/ * . x lb ;
(
(Add-Ins));

102

I. Excel

, X L S t a r t ;

,
( (Advanced)
Exce^Excel Options));

Excel (
);

,
X L S t a r t
.

Excel .
Excel , :
C : \P r o g r a m

F ile s \M ic r o s o f t

O ff ic e \O f fic e l4 \E X C E L .E X E

,
,
, .
. 4.1.
4.1. Excel

_
/ _
/ 1 _
/ _
/
/
/s


. _



(
)
Excel

,
,
Excel ,
, X L S t a r t


Microsoft Excel 4.0 ( )

,
1^ (Start^Run). ,
Excel, ,
. . 4.1.

, Excel. ,
c : \ x l f i l e s ,
Windows. / ,
.

4. Excel

103

, ,
, .

j
;

| "C:\Program Files\Mcrosoft O ffk e \O ffk e 14\EXCEL.EXEi



L jS L .J

j |

O 6jop...

. 4.1. Excel (Run)

Windows 7.

, Excel.
(Properties).
(Shortcut Properties), (Shortcut)
(Target) (. 4.2) :
"C:\Program F i le s \ M i c r o s o f t O ffic e \O ffic e l4 \E X C E L .E X E " / c : \ x l f i l e s

. 4.2. ,
Excel

, , e x c e l . ,
Excel.

104

I. Excel

,
Excel. Excel ,
.

Excel .

.
Excel .


Excel 2010 XLSX,
. ,
Excel 2010.

Excel 2007 Microsoft


Lotus Quattro Pro.

Excel
Excel 2007 ,
Excel 2010.
Excel ,
Excel.

, ,
^ Excel (File=>Excel Options)
(Save) Excel (Excel Options).
,
, .
. 4.2 , Excel 2010. ,
Excel .
,
, .

4.2. Excel

Excel

x ls x

Excel

xlsm

Excel 2010,
.

VBA XLM
Excel 2010,

4. Excel

105
. 4.2


Excel

x ls b

x ltx

x ltm

Excel

xlam

Excel 97Excel 2003

x ls

Excel 97-cel 2003

x lt

Excel 97Excel 2003

x la

Microsoft
Excel 5.0/95

x ls

XML-,
Excel 2003

xml

Excel 2010
(BIFF12).

XLS (BIFF8)
Excel 2010,

.
VBA XLM
Excel 2010,


Excel 2010,

.
VBA XLM
Excel
(BIFF8),
Excel 97 Excel 2003
Excel
(BIFF8),
Excel 97 Excel 2003
Excel
(BIFF8),
, Excel 97Excel 2003
Excel
(BIFF5), Excel 5.0
Excel 95
Microsoft XML
Spreadsheet 2003 (XMLSS)

Microsoft Office Office 2003 Microsoft


Office Compatibility Pack,
Office 2007 Office 2010.
- h t t p : / / o f f ic e . m ic r o s o f t . com.


Excel
(Text Import Wizard),
.

I. Excel

106

,
<Shift>.

. 4.3 , Excel 2010.


.
4.3.

CSV (,
)

csv

tx t

(Data
Interchange Format DIF)
(Sym
bolic Link SYLK)

d if

s lk


,
. Excel

Macintosh MS-DOS

,


,
. Excel

Macintosh, MSDOS Unicode
(Data
Interchange Format DIF)
(Symbo
lic Link SYLK)


. 4.4 , Excel 2010.
.
4.4.

Access


Ashton-Tate
=>
(Data^Get Exter
nal Data),
.

,

dBase

mdb, mde, accdb,


a c cd e
dbf

4. Excel

107


. 4.5 , Excel 2010.
4.5.


(Hypertext
Markup Language
HTML)

htm, htm l

-
(Single File Web
Page)

mht, mhtml


OpenDocument

ods


(Portable
Document Format PDF)
XML-
PDF (XML
Paper Specification PDF)

pdf

xps

Excel 2007

HTML-.
Excel,
,


- (Archived Web
Page). ,

,
Microsoft
Internet
Explorer Opera
,
Sun Microsystems
OASIS.

,
OpenOffice

Adobe
PDF ,
Microsoft


,
Excel. , ,
,
XLW-. , ,
XLW-, Excel .
^^
(View^Window^Save Workspace)
.
^ (F\\e^
Open) ( xlw )
(Files of Type).
, -
,
Excel. , -
, XLW
.

I. Excel

108


, 4, ,
. Excel ,
.
( XLTX). ,
. , ,
.
, , .
, ,
.


Excel 2010
. Excel ^ (File^New),
(Available Templates).
Office.com (Office Online Templates)
.
.
(Download). . 4.3 ,
(Invoices).
_1

t*'

3
>

1 - Microsoft Excel


* .

<2

Office.com

J i

*
| Office.] *

( ;
: 19
:

(5 6 )

. 4.3.

Microsoft Office Online ,


. ,

4. Excel

109

, .
. ,
.
/


Excel. VBA-:

MsgBox Application.TemplatesPath


Excel .
, .
.
1. x ltx .
, .
, .
1 .x ltx .
. ,
, ,
.

.
,

, .
, , ,
Calibri 11 ,
8,43 .. , .
Excel, ,
, .
.
1. .
2. ,
.
3. , ,
, , ,
(Advanced) Excel (Excel Options).
, ,
^^ (Home^Styles^Cell Styles),
(Normal). ,
, , .
4. , 1^
(Office^Save As).

I. Excel

110

5. (Save As) (Save


As ) Excel (Template (*.xltx)).
6. ^ . x l t x .
7. \XLStart ( ).
8. .

\XLStart
VBA-:

MsgBox Application.StartupPath


Excel . x l t x .

<Ctrl+N>.
, , . x l t x .

^ (File^New)
(New Workbook) (Blank Workbook),
. x l t x .

Excel
, .
, , ..
.
1. , ,
.
2. , ,
, ,
Excel (Excel Options).
3. ^ (File^Save As).
4. (Save As) (Save
As ) Excel (Template (*.xltx)).
5. . x l tx.
6. \XLStart ( ).
7. .
8. Excel.
,
(Insert Worksheet) (
),

4. Excel

111

. x l t x .
<Shift+Fll>.
/


.x l t x , x l t x , ,
, ,
, .
,
,
.
? ,
. ,
, ,
. ,
( ).
, ,
, .

,
. ,
(Save As)
,
.
(New From Existing),
(New Workbook).
,
, .

( )
, . ,
. x l t x
1 .x l s x .
, ,
(Save As). ,
.
, , ,
, Excel (,
). ,
. ,
, , .
%

,
(Excel Macro-Enabled Template)
XLTM.

Excel

112

I. Excel

Excel
Excel 2010 XML-,
, !. ZIP-.
.
Excel, Excel 2007,
. ,
. , XML-
.
, Office 2010.



Excel (XLSM). , s a m p le .x lsm ,
. 4.4. ,
VBA. , (
(Forms)), SmartArt, .

. 4.4.

-
s a m p le . x ls m -.

Excel 2010 Windows


ZIP . s a m p le . x lsm
sam p le .x ls m . z ip .
, .
, Windows 7.

4. Excel

113

,
. ^
(Tools^Folder Options) (View).
(File and Folders)
(Hide Extensions For Known
File Types).

, ,
. Windows
(Extract Files).

, ,
. . 4.5
.
.
/W

(G:) samplejdsm-

igii

>
>(*
>
*

-*j

4-f | : sampk.xtsm~

ii.re is

1507201011:50

customXmt
docProps

15.07.201011:50

1507201011:50

1507201011:50

[C ontent_Types}jcml

&


XML

>

>

i>

(G

PicsExcei2010
PicsHTML
J t Pics0ffice2010
|(, samplejtkm~

>|

. 4,5.

XML. , XML-,
Excel. . 4.6 ,
Firefox. , XML,
VBA- ( ).
XML- ;
. , _ r e l s .
XML-, .

114

I. Excel

- :
ijfei

file:/IfF:/sample. xism --/!/worksbee to/sh eet1. xml

_
................................:
2_ 43"

....

-ini xi
.

p\

1Me:///R/<3fflHe~sheets/riKetLxinl

X M L - .

- - worksbeet mc:Igaorabie="il4ac>
<sbeetPr codeName=*Sheetl7>
dim ension ref^T 2G 9 />
<sheetViews>
<sheetView showGr*dLiBes="0" tabSelected

1" workbookViewId-"0">

</sketViews>

<sbeetFormatPr defaeltRowHeigbt^" 15" xl4ac:dyDesceBt="0 257>


<cob>
<co! =" m ax = T widtb=l cmstoiWidtk=" 1"/>
<col ='6" mai="6e widtb="12" c*stora\Vidtb=" 17>
<col = =" widtfc=" 11.140625" cstomWidA="17>
</cols>

<sbeetData>
- <row r="2" spa*s="6 7 il4ac:dyDesceet="0.251>
<c r= T 2" s = T *=V>
<v > 7</y >

<t>

<c

r="G2" t= V >
<v>6</v>

<Jt>
</row>

- <row r="3" 5pams="6 7" rl4ac:dyDesce*t="0 25">


- < c r = T 3 " t= V >

<v>0</v>

. 4.6. XML- -

, s a m p le . xlsm .

_ r e l s . .

doc P ro p s. XML-,
.

x l. .
Office (x l, p p t, w ord ..). XML-,
.
VBA-, BIN.
(
).
c h a r t s . XML- ,
.
c h a r t s h e e t s . XML-,
.
d ia g ra m s . XML-,
( SmartArt) .
d ra w in g s . XML-,
. ,
.
m edia. , GIF- JPG-.

4. Excel

115

t a b l e s . XML-, .
them e. XML-, .
w o r k s h e e ts . XML- .

z i p Excel, , ,
Excel,
.
z i p . (Save
As) z i p ,
.^^ .


XML-, Microsoft Office 2007,
, .
Excel
, Excel. ,
, Excel,
Excel .
. ,
XML-, ,
.
,
( ).
XML- .
Excel , . 4.7.
,
. r e s . Excel .
, .

1. xlsm. zip* , .
? , "*.

. 4.7. Excel

, XML-
. ,

(, ).
, Excel
XML- . ,
,
Excel.
XML- .

I. Excel

116


22
.

OfficeUI
Excel.of ficeUI ,
. XML- :
: \U s e rs \< _ o o a e ;> \A p p D a ta \L lO c a l\M ic ro s o f t : \ O f f i c e


. , Excel.
, ,
.
E x c e l . o f f i c e U I XML, - Excel. .
1. E x c e l . o f f i c e U I .
2. XML ,
E x c e l . o f f i c e U I .xm l.
3. ^ (File^Open)
Excel.
4. , ; XML (As an XML Table).
. 4.8 E x c e l . o f f ic e U I (
).
( 4-6 12-13 ), ( 15-23 ).

. 4.8. E x c e l. o f f ic e U I Excel

Excel .OfficeUI
. , , ,
.
, Excel.
OfficeUI , . ,

4. Excel

117

i^oeepx Excel.Of ficeUI


, , .
Excel.Of ficeUI, ,
. .
Excel Excel.of ficeUI,
, Excel .
.

XLB
Excel
XLB. , Excel 2010
, , XLB -
. , ,
.
Excel
114 . x lb . () :
:\U s e r s \< > \ A p p D a t a \R o a m i n g \ M ic r o s o f t \E x c e l


, ,
.


Excel,
.
IsAddin . ,

(Add-Ins).
,
. ,
.
VBA, ,
Workbooks.

(Add-Ins)
^ Excel (File^Excel Options).
(Add-Ins), (Manage)
Excel (Excel Add-Ins) (Go).
Excel (Developer),
^^ (Developer^Add-lns^Addins)
, , <Alt+TI>,
Excel 2003.

I. Excel

118

Excel
Excel (Excel Options) ,
.
Excel Windows.
Windows, , Excel
.


Windows, ,
,
. Windows 95,
INI- Windows .


VBA-. 11.

(Registry Editor).
.
r e g e d i t . . ,
.... . 4.9 .
&

t> | i MobilePC
j- MPEG2Demultiplexer
MS Design Tools
MSDAIPP

>
>

MSNMessenger

- Multimedia
!~ Notepad
Office
12J0
fc 14.0
> j || Access
c> jg Clip Organizer
i.. S
|

( )

6632 00 00 010100 00 00 00 00 00 7a 00 03 00 00 00...

"lojCmdBarData

REG.BINARY

^jCustomBottom...

REG_DWORD

0x000a6fe0 (684000)

.Wi]CustomFooterM... REG.DWORD

0x00046500(288000)

CustomHeader...

REG.DWORD

0x00046500(288000)

?i*i CustomLeftMar... REG.DWORD

0*000956*0 (612000)

?<CustomRightMa... REG.DWORD

0*0009e340 (648000)

tfijCustomTopMar... REG.DWORD

0x000a6fe0 (684000)

DectmalSeparator REG.SZ

Common

JlSjLastUlLang

REG.DWORD

bcel
File MRU

Maximized

REG.DWORD

Clip OrganizerDB

j Options:
Place MRU
Recent Templates
Resiliency
t>
DocumentRecovery
t>
Security

-I

0x00000000(0)
0x00000000(0)
0x00000000(0)
0x00000002(2)
0x00000419 a 9 )
0x00000002(2)

, CLView

t>

;**) ( ) REG_SZ

MSpell Checker

$*j DefauttSheetR2L

REG.DWORD

ISjFirstRun

REG.DWORD

.tie] FormulaBarExpa... REG.DWORD


jrfjFormulaBarExpa... REG.DWORD

REG.SZ

4.100.21.143.24.5.1.359.0.7

^jOptionFormat

REG.BINARY

00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00...

$Optk>ns5

MRUFuncs

REG.DWORD

0x00000080 (128)

^jOptionsDlgSizeP... REG.BINARY

6 03 00 00 ad 02 00 00 72 00 00 00 25 00 00 00 00 0

JMlPrvotConnectio...

REG.BINARY

3b 0100 00 c8 00 00 00 56 02 00 00 55 0100 00 00 3~

pPos

REG.SZ

119.0.1116.640

^PosSideBySide

REG.SZ

659,3,1299,580,42,651,579,0

^jSlicerConnectio...

REG.BINARY

45 01 00 00 c8 00 00 00 fO 0100 00 48 0100 00 00 3c~

KoMnwoTep\HKEY_CURRENT_USER\Software\Microsoft\Office\14AExcefS.Options

. 4.9.

...
,
, r e g e d i t . . ,
, Windows .

4. Excel

119

^ (File*=>Export) .
ASCII- .
, ASCII-,
( ^ (File^lmport).
.

,
. :
HKEY_CLASSES_ROOT;
HKEY_CURRENT_USER;
Y_LOCAL_MACHINE;
HKEY_USERS;
HKEY CURRENT CONFIG.

Excel
, Excel 2010, :
H K E Y _ C U R R E N T _ U S E R \S o f tw a r e \M ic r o s o ft\O f fic e \1 4 . 0 \ E x c e l

, ,
Excel.
Excel.

, Excel Windows
. , Excel
. Excel (
), .
Excel, ,
, Excel
.

. 4.6 , Excel 2010.


, .
4.6. Excel

Add-in M anager

,
(Add-Ins). , Excel,
. -
,
()
, Excel
,

(
)
Converters

()
Error C h eckin g

( )
F ile mru ( (
(Recent Workbooks),
)
^ (File^ Recent))

120

I. Excel
. 4.6

O p tio n s

()

R e c e n t T e m p la te s

,
Excel

( )
R e s ilie n c y

()
,

S p e l l C h e c k e r ( ,
)
,
S ta tu s B a r (

)
U s e r ln f

(
)
S e c u r ity

()

Excel
(Excel Options), (
). ,
, .
.
1. HKEY_CURRENT_USER\Software\Microsoft\Office\14.0\Excel\0ptions.

2. 1^
DWORD (New^DWORD Value).
3. Opt ions 6.
4. Opt ions 6
(Modify).
5. DWORD (Edit DWORD Value)
(Decimal) 16 (. 4.10).
DWORD {32 )
:
Options6

161


0
#

1 0*

1 L

. 4.10.

Excel ( -,
). , Opt ions 6.

4. Excel

121

Excel,
. ,
:

HKEY_CURRENT_USER\Software\Microsoft\Office\14.0\Excel
Excel
. .

Excel
...
5

6


...



Excel

0

, , ,
, .
,
, .
,
.
.
, , ,
-.
(
).
. , ,
,
.

II. Excel

126

, ,
.

, .
, . ,
, .

( )
.

,
, .

,
, .

, ,
(
).

,
.

,
( Excel).

,
( , ,
,
, ).


.

.
, . ,
.
( ). (
) ,
.
,
.


.
, .
.

5.

127

,
.
. ,
.
, ,
.
, ,
. ,
, .
.
, .
( ) ,
.

, .
,
.
, . , ,
, ,
. ,
, ,
.

, :
;
, ;
;
, , ;
;

( );
;
;
, ;
;
.


6.

, (
Excel). , Microsoft,
,

II. Excel

128

.
Excel , , ,
, ,
. , ,
. ,
.


, ( -
, ), ( )
.
. ,
, . 5.1.
. ,
, (
).
,
, .
5.1.


/
/

,
, . ,
, , . ,
, . , , ,
.




,
. , ,
, .
. ,
.
.
, , , , .
, .

5.

129

, ; ,
. , ,
, , .. ,
.
, ,

, . ,
.
, , , ,
. ,
, . ,
,
( ), . , ,
, ,
, .

Excel
, ;

. ,
.
, , ,
Excel.
, .
.
(.. )
,
.

( ) . ,
.
, , , ,
.
( )
, .

Excel.
. ,
Excel,
-, .
.
, .
,
.

53. 3107

130

II. Excel

.
, Excel,
Access.

.
Excel,
, PageMaker.

. ,
,
, .

. , Excel
. (
) ,
Excel .

, , , .
,
. ,
. ,
,
.


,
. ,
. ,
.
. , ,
.
() :

-;

-;

5.

131


, .
.
, . .
,
. ,
. 12 ,
, .
, , ,
. ,
- .
.
.


, , ,
, .
, ,
. ,
, ,
, ..
, ,
( , ..)
.
, ,
, , .

( ).
: , ,
, ,
. , .
,
.


,
,
. , ,
- .
, (
).
.
, ,
.

132

II. Excel

,
,
1-. ,
, , ,
VBA- ..


Excel ( ).

-
-.
- ,
; ,
.
.
, . ,
, , .
.
, , ,
.
, -, ,
. , ,
.
, . ,
- :
, , .

-

. Excel,
.
. ,
. , Excel,
, , ,
( ) .
,
.

Power Utility / Excel.


, .
, Excel.
Power Utility - ( w w w . s p r e a d s h e e t p a g e . com).
.

5.

133

- .
, ,
, , ,
. - ,
Excel. , ,
, .
,
, .
- ;
. Excel
:
Excel, , .

,
. 16
Excel VBA.


Excel ,
.
, .
, VBA.
, .

10
, .


(
), .
, (,
), . ,
.
.
.
VisiCalc ( ).

, . ,
. ,
,
,
, ,
.

134

II. Excel


,
.

, ,
. ,
( ).
, , ,
, ?.. ,
. ,
.
,
,
.
, . ,
,
,

.



Excel
( ).
, ,
. ,
.
,
.
, ,
,
, Access.


.
Excel
, , .
, ,
(Executive Information System EIS).
, .

.
Excel,
, .

5.

135


.
,
. , ,
. ,
,
, .

.
,
. .


...

, , ,
, , Excel.


, ,
.
,
. , , ,
, . ,
, ( )
, .
,
:
;
, ;

II. Excel

138

, , ;


( );

, ;

.
,
.
. ,
.



.
,
.
.

. (,
, ),
, , .
?
,
.
, -,
, ,
.
, ,
.

, .
,
.

,
,
.

, ( )
. , , ,
. , ,
.

6.

139

, . ,
, , -
, .
, ,
. ,
, .
.
, ( ) Excel .
Microsoft ,
.
Microsoft Office
.
.
.
,
. .
. ,
. ,
,
. , ( )
.



,
, .. ,
. . ,
.
,
, ,
.
, ,
.
Excel! ,
.
Excel
, , , ,
.
, , Excel
.
, ,
,
.
( ) .

140

II. Excel

,
.

. , :
, .

. ,
. ,
.

VBA. , :
VBA?
.

.
,
.

Excel. 1-?
Excel 2010? Excel 2007? Excel 2000/2002?
Excel 97, Excel 95 Excel 5?
Macintosh? ,
Excel , .
,
, .

.
. ,
. ,
, ,
.

.
,
Excel, .
Excel, , .

.
,
, .

. Excel ,
.
, ,
, ,
.
, ,
.

Excel.
,
Excel.

6.

141

, ,
.
, .
, .
, .
, ,
. .
,
. , , , ,
.
, .

. Excel .
18 24 . ,
, ,
, .
Excel 5, VBA, Excel
.
, Excel,
XLM, Excel 2, 3 4. Excel 5
, .
Excel 97
. , Visual
Basic Editor (VBE) ,
. Excel 2000, 2002 2003 ,
, .
Excel 2007
,
.
VBA.
,
VBA. , . ,
: Excel 2007/2010, Excel 2003
.
VBA , ,
: .
VBA . , , ,
VBA , . , VBA
, .
VBA, , .
VBA .

,
. , ,
, .
.
.

II. Excel

142

.
,
DDE OLE. ,
.
.

, ,
.
.
Excel 2010 ( Excel 2007)
. , ,
. .
Excel ,
:

( );

(,
L is tB o x CommandButton).

,
.

Excel 2010 ,

.
,
Excel 2003.
Power Utility . .
Power Utility Excel 2010 (.
), ^
(Add-lns^Menu Commands),
^ (Add-lns^Custom Toolbars).
, ,
.
.
,
Excel 2010.
PUP,
Excel 2007 .

6.

-3]

jeUPve

FtxTnatSnQTools
Worksheet Tools

WorkfeookToote

1 ^

ft

Chart Graphic Tools

/ ^

Pnmng Tools

Bate & Time Toots

Auditing Tools

yBA ft Macro Tools

54*
*. % *

Chanced Shortcut Menus

* ci I &

|*4,;=

&>>|
EJ )
IB , &

X ^

* _ (9 >

M -l

-------- j.

"

-j

Sort Sheets...
SaveWitft^dap...

Create Workbook Contents Sheet...

Fiename Lister

Custom A New Workbook

-------- j-------- 1---------j-------- j

PUP Boolanartp

* Jd

* 111

\
- |

P
*

A
'!

! i- . J .... 1 ...|.....t.... L

m Insert He at Cursor...
m Interactive tfde / Ul*de...
1 100%

FomnJa Tools

7 1... 1

Adofee PDF

Sange Toots

143

Create PUP Toolbar...

Amusement?

PUPftjtions...

<
?

us

HHp
About Power Utikty Pak...

n ZJ

-- -

'

iVorksheet Tools
1 InsertFileA Conot
h*t &Gr*phKTooH
Q*t &T*k Tooh
&MacroTook

(3 SwUbMto...

% SHWhetkuB...

f>

E S.re< WorkbookConHnh Slwrt


* CuttMoa* AHrwftoritboot...

PUPflpttow...

41tw>


, Excel 2007,
.
.
Excel 2010 ,
.


22.

144

II. Excel


Excel 2010, , ,
VBA, . . 6.1
,
. ,
( ), .
" ------------- ------------- -------------- 1-----Calibri

-jll

- "

'

<9

...............................................: : : : : : : ..... .....

...
...
...

...
...
...

&

...

Toggle Page Break Display

Toggle Word Wrap

Change Case

Upper Case

Print Selection

Lowercase M l

Center Across Selection

Proper Case

Synchronize Sheets

PUP Date Picker

PUP InfoBox

..... ....... .... ...

.....

. 6.1.


23 VBA.


Excel . ,
<Ctrl> ( <Shift+Ctrl>).
.
, .
, .
, -.

6.

145

, , ,
. , Excel
<Ctrl+S>, .
, <Ctrl+S>.
, ,
<Ctrl+Shift+S>.


- Excel, , ,
. ,
.
. 6.2.
xj

Tra n sfo rm V ertica l R an ge

This utility transforms data stored in a single column, to a multjcdumn format.

line 2

Line 1
. Line 4
Line?
Line 10

Line 2
Line 5
[Line 8
Une 11

Line 4
Line 5.
Line 6

Line 3
Lme 6
Line 9
Line 12

Bata to be transformed {single column}:


j

1!$0$5:$0$22
Output range (smgte );

1!-$3

Rows per record

(~ Sank cell delimits records

|4rows per record

bne 10
Line 11
Line 12

. 6.2. ,
Excel

(UserForm)
, ,
.
Visual Basic (Visual Basic Editor VBE).
, , (
, , ..).
ActiveX.
, Excel.
, .
,
, (
, ).
, ,
, .
VBA-.

IV.

II. Excel

146

ActiveX

Excel ActiveX,
, (
, , ). . 6.3

. :
(C h e c k b o x ), ( S c r o l l B a r ) ,
(O pt io n B u t t o n s ) . ,
.

.F

2
4
5


565

3
:

$145

5,65

$5,000

6
7

, :

10%

30

15%

( 15

10

30

15

20%

$276 000

15

12
:

13
14
15

j J

$276 000

1J

5,65%

10%
15%

20%

20%

16
17

$2 277,18

18

19
20

.11
. 6.3. ,

-
- ( w
s h e e t

o r k

c o n t r o l s . x l s x ) .

, C om m andBut t o n . ,
.
,
.
ActiveX .
, ,
, .
^
^ (Developer^ControlsOInsert) (. 6.4). -

6.

147

,
, Excel.

39

<$

flis iid

, 2 \

. 6.4.

:
ActiveX.
.
, ActiveX .
. 6.1.
6.1.
ActiveX
ActiveX
Excel

97, 2000, 2002, 2003, 2007, 2010

5, 95, 97, 2000, 2002, 2003, 2007, 2010

CheckBox,
T extB o x,
Command- G r o u p B o x , B u t t o n , C h e c k B o x , O p t i
B u t t o n , O p t i o n B u t t o n , L i s t B o x , o n B u t t o n , L i s t B o x , DropD ow n (Combo
ComboBox, T o g g l e B u t t o n , S p i n - Box), S c r o l l B a r , S p i n n e r
B u t t o n , S c r o l l B a r , L a b e l , Im age

( )
VBA-



(, Command_
B u tto n l_ C lic k )


( ,

Excel 97)


Properties
C l i c k ()

C h a n g e ()


, ,
, ,

148

II. Excel

,
. , ,
, .
,
.
, , , ,
. .
, .


,
,
.


?
, ,
. ,
, .
, ,
Excel, .
, .
. ,
. , VBA
, ,
, .
.
.
: (1) ,
( ) , ; (2) ,
, . .
, ,

. , .
Excel (. ? Excel?).
? Excel?
, , , , Excel,
, ( ). ,
. Excel ,
. , .
, Excel,
Microsoft , , .
. ,
, , .
,

6.

149

. ,
.
, , .
.
Excel ,
.
, Excel.
, , , .
Excel
. , .
? ,
. , , , ,
, . ? ! ?
! ...

,
, .
,
. , ,
, ,
( ).
, .
, ,
. ,
,
. , ,
<Ctrl+F6> .
? ,
,
.
-?

.

. -.
,
.
Excel ,
, , , -.

, ,
, .
-

. ,
. - , ,
: , ,

II. Excel

150

.. -
, .
,
,
. , , ( )
.


.

. , ,
. ,
, , , .
, ,
( )
., Excel
.

.
, . (
(Protection) (Format Cells).)

(ReviewMChangesMProtect Sheet). (Protect
Sheet) , ,
(. 6.5).
-2i*i
.
W


, (Protection) w cra:
(Format Cells), :


. , W
"

, ~
"
"
~
(R eview M

"
ChangesMProtect Sheet).
"
JH
.
,
.

(ReviewM ChangesM
Protect Workbook).

. 6.5.
(Protect Sheet)
,

.
(Properties) (Size and Properties)
(, ),
.

6.

151

^
^ (Drawing Tools^Format^Size).
, ^^ (Review^Changes^Protect Sheet).
.
, , .
, , .
,
.
Excel ".
Excel ( ),
.
(General Options).
^ (File^Save As).
(Save As) (Tools)
(General Options).
.
.
(General Options).
^ (File^Save As).
(Save As) (Tools)
(General Options).
.
, ,
.
Excel
Microsoft Excel
.
Excel .
, .
Excel 2002 (
), .
Excel . , ,
, - ,
, , .



, ,
, ,
.
,
.

II. Excel

152


. ,
Excel. , , .
,
, .
, Excel 2007
.
,
. ,
, . , Excel 2010
,
.

,
. .
,
, . ,
.

. , , ,
Excel.
, , .

.
,
. , ,

.

.
, ,
, .
, , ,
M u lti ( ),
.

. ,
.

.
, , , .
,
,
.

, Excel 2007, 56
. , Excel 2010
16 .

6.

153


,
: .
Windows-. 1-

.
, , , . . 6.6
HTML-.

I Power U tility Pak v7

<3=*

' ;

| ]

El

El

Power v
The Ubkties
{si Cels and Ranges Group
Workbooks and Sheets Group
Charts and Graphics Group
E l Audfcng Group
PUP Bookmans Group

[J Ed Bookmarks
[|) Activate a Bookmark
Q j Power Utttty Pak Grou>
Q Technical Support

The Trial Verswn


j Additional Wormafeon

&

Create a PUP Bookmark


C re a tin g a bookm ark:
1.

Make sure the workbook that will be bookmarked has been saved.

2.

Activate the workbook, worksheet, and range for the bookmark. To create a bookmark for a
chart sheet, activate the chart sheet.

3.

Click C r e a t e a B ookm ark in the PUP v 7 - PUP Bookm arks group. The Create Bookmark
dialog box is displayed.

4.

Enter a meaningful name for the bookmark (to replace the generic name). To create a "hot
key" in the bookmark name, precede the character with an ampersand. The following
bookmark name appears with the letter A underlined. When the bookmark list is displayed,
press this key to quickly activate the bookmark.

Budget ^Assumptions
5.

Select the action to take when the bookmark is selected (see the list of options, below).

6.

Click OK, and the bookmark will be added to the list.

Option

Description

A c t iv a t e th e w o rkb oo k, a n d
g o to th e sp ecifie d s h e e t &
ra n g e

When the bookmark is selected, the workbook will be opened


(or activated), the sheet will be activated, and the range will be
selected.

A c t iv a t e th e w o rkb oo k, a n d
g o t o t h e sp ecifie d s h e e t

When the bookmark is selected, the workbook will be opened


(or activated), and the sheet will be activated. There will be no
change to the selected cell or range.

A c t iv a t e th e w o rkb oo k

When the bookmark is selected, the workbook will be opened


(or activated). There will be no change to the active sheet or to
the selected celt or range.

Activating a PUP Bookmark


Editing PUP Bookmarks
Tips

. 6.6. Excel

,
. ,
?
, , .
,
.


24
.

154

II. Excel

,
,
.
, .
,
. , .

.
, Excel, ,
, , ,
.
: ( )
( ).

?
. ,
. ,
, .
VBA, ( ,
, ). VBA
, , ,
.


.
?
. .

. , , ,
.
.
.
,
VBA.
Excel 2000 Microsoft Authenticode,
.
, , ,

. ,
.
( ,
).
- Microsoft.

6.

155


, ,
? ,
( ) . ,
.
, .
, .
,
, .
. , .
.
,
. , ... .
Excel
,
,
Excel. Excel . ,
, Microsoft
Excel? , ,
. , Excel
. ( .)
, Microsoft
Excel
.
: , -
. , ,

, .
... Microsoft
Excel. Excel
Excel. , .
-
Microsoft ( h t t p : / / o f f i c e . m ic r o s o f t . co m /dow nloads).


,
, , .
,
(, - ), ,
,
.

Excel,
Excel
. Excel 2010 ,

II. Excel

156

- Excel 2003
.
, , , , ,
Excel 2000, Excel. ,
Excel,
, .
, Excel.
Microsoft (SR),
(SP) ,
. Excel ,
.

26.

,
, ,
Excel. ,
.
.

, , 26.


,
. ,
, , .
,
. , ,
. , ,
,
. , ,
.

VBA, ,

. . (
.)

, .
1024x768,

6.

157

800x600.
.
, ,
.
, , ,
, .
, 1280x1024,
1024x768,
.
, , (.. )
.
, , ,
, VGA-.
,
, .
(
(Zoom), ),
. ,
, , ,
800x600.
10 ,
Windows API VBA.
(
).


Visual Basic for Applications
...
7
VBA
8
VBA
9
VBA
10

11
VBA


VBA
...

BASIC
VBA
VBA
Visual Basic
Project Explorer

VBE



Com m ent:

1 i a t i on
R ange

Visual Basic for Applications,


, Excel.

BASIC
BASIC
. (Beginners All-purpose Symbolic Instruction Code
) ,
. , BASIC 1960-

.
.
63. 3107

162

III. Visual Basic for Applications

BASIC . ,
.
, .
BASIC .
, .
BASIC 1991 , Microsoft
Visual Basic Windows.
Windows. Visual Basic BASIC,
VBA.

VBA
Excel 5 ,
Visual Basic for Applications (VBA). VBA
Microsoft
Office 2010 . ,
VBA Excel,
Microsoft ( ). ,
,
.


VBA
. , VBA
, (Excel, Word, Access, PowerPoint ..)
.
, .
, Excel
, , , , ,
, , .
VBA
. VBA Excel
. .
, ,
!
VBA
, Microsoft
VBA Office, .NET.
. , Microsoft
Office, VBA , Excel
Windows. , Microsoft ,
VBA Excel Macintosh. ,
VBA- Excel Macintosh.
VBA? ,
, VBA , .

7. VBA

163

VBA XLM
Excel 5 (
) XLM. Excel
XLM, Excel 97
XLM. XLM
( , , ),
VBA.

XLM XML (extensible Markup Language


). ,
, , .
XML ,
. XML
Office 2010.

VBA
,
,
. , .
VB .
. VBA VBA.
. ( ) VBA,
VBA. VBA .
. , ,
, . VBA
: Sub () F u n c tio n ().
Sub. Sub ,
. Sub
T e s t. ,
.
Sub T e s t ()
Sum = 1 + 1
MsgBox " " & Sum
End Sub

F u n c tio n . VBA F u n c tio n .


( )
VBA
. AddTwo.
F u n c tio n A d d T w o (a rg l, a rg 2 )
AddTwo = a r g l + a rg 2
End F u n c tio n

. VBA ,
( Excel). Excel
, , , -

164

III. Visual Basic for Applications

, .
, VBA.
.
. , Excel
A p p l i c a t i o n ; ,
W o r k b o o k C o m m a n d B a r . W o r k b o o k ,
W o r k s h e e t C h a r t . W o r k s h e e t ,
R a n g e , P i v o t T a b l e ..
Excel.

. . ,
.
C o m m a n d B a r s C o m m a n d B a r .
.

W o rksh e e ts

. , ,
. , 1 . x l s x :
A p p lic a t i o n .W o rkb o oks(" 1 . x l s x " )

1 . x l s x
Excel A p p l i
c a t i o n . , 1
1:

W o rkbo oks.

A p p lic a tio n .W o rk b o o k s (" 1 . x ls x " ) .W o rk sh e e ts(" 1 ")

:
A p p lic a tio n .W o r k b o o k s (" 1 . x l s x " ) .W o rk s h e e ts (" 1 ") .R an g e (" A l " )

. Excel
. 1 ,
:
W o r k s h e e t s ( " 1 " ) . R a n g e ( " 1 ")

,
: R a n g e ( " 1 " ).

1,

. .
. , V a l u e
N a m e . H a s T i t l e .
() VBA.
, , .
, 1 1 :
W o rk s h e e ts (" 1" ) . R a n g e ( " A l" ) .V a lu e

VBA. VBA .
,
. , 1 1
I n t e r e s t , VBA:
In te re st

= W o r k s h e e ts ( " ! " ) . R a n g e ( " A l " ) .V a lu e

7. VBA

165

. . ,
. , R a n g e
C l e a r C o n t e n t s . .
,
. , 1
: R a n g e ( " 111) . C l e a r C o n t e n t s .

. VBA
, , ..

. ,
VBA, .
, W ork b ook_O p en .
W o r k s h e e t_ C h a n g e .

, VBA .
,
.

, . ,
, VBA.
Excel .
Excel W o r k b o o k ( ).
. Excel
, W o r k b o o k s
(, W o r k b o o k ) . ,
,
R e s t a u r a n t s R e s t a u r a n t .
Excel , ,
, , VBA .. ,
. , W o r k s h e e t
R a n g e (), P i v o t T a b l e ( ), S h a p e () ..
( )
, K i t c h e n (), D i n i n g A r e a ( ) T a
b l e s (), .. . ,
R e s t a u r a n t . , T a b l e s ()
. .
, K i t c h e n () , s t o v e (),
V e n t i l a t i o n F a n (), C h e f (-), S i n k () ..
, . , .
Excel . , R a n g e ()
Value () Name (), S h a p e () w i d t h () H e i g h t
(). . ,
S t o v e () , T e m p e r a t u r e () N u m b e r o f B u m e r s ( ). V e n t i l a t i o n F a n ()
( T u m e d O n (), r p m ( ) ..).
, Excel , .
, C l e a r C o n t e n t s ( )

III. Visual Basic for Applications

166

(). . ,
s t o v e () C h a n g e T h e r m o s t a t (
), V e n t i l a t i o n F a n () S w i t c h O n ().

Range

Excel . ,
d e a r C o n t e n t s ( ), R a n g e
(), R a n g e V a l u e ( ).
C h a n g e T h e r m o s t a t ( ) s t o v e ()
T e m p e r a t u r e ().
VBA, ,
Excel.
. (
. ) , ?

Visual Basic
VBA Visual Basic (Visual
Basic Editor VBE). ,
Excel. ,
VBE, .
, , VBE ,
Excel.

VBA .
, VBE.


Excel (Developer) .
, VBA.
1.
(Customize the Ribbon).
(Customize Ribbon)
Excel (Excel Options).
2.
(Developer).
3. .
Excel
(. 7.1).
|;

' * ' j*

*! Microsoft

j !

PUPv7

|~
Jtk
[

#
g
2~i ~
qfi
uSSa g ^5

I

....


OShowi

. 7.1.

7. VBA

167

VBE
Excel VBE :
<Alt+Fl 1>;
^ Visual Basic (Developer^Code1^ Visual Basic).
, . (
VBA- ,
19.)
,
(View Code), .

(View Code).
.
Excel, .
VBE . 7.2. , VBE
. VBE
, , ,
, .

g\ ____ ____ ______

. ....... ......

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

. 7.2. Visual Basic

VBE
VBE .
Visual Basic.
. Excel ,
Visual Basic -
. VBE ,
. ,
VBE. ,
. , View^ Immediate Window
(^ ) <Ctrl+G>.

III. Visual Basic for Applications

168

VBE .
VBE, ,
.

. Standard,
.
, VBE ( ).
VBE , Excel:
, ,
.. VBE
View^Toolbars^Customize (1^ 1^ ).

Project Explorer. Project Explorer


Excel (
). .
Project Explorer .
Visual Basic Project Explorer , <Ctrl+R>.
, (
Hide ()
) Close () .

. ( Module) VBA.
.
, Project
Explorer. , 1,
1 Project Explorer. VBA-,
.

Project Explorer View Code ( )
Project Explorer.
(. ).

. (Immediate)
VBA, .
. ,
<Ctrl+G>. ,
(
Hide () ).

Project Explorer
Visual Basic Excel
.
, . ,
Project Explorer.
.
, , .

7. VBA

169

Project Explorer .
Toggle Folder ( )

.

. 7.3 Project Explorer, .


|Project VBAProject

EEJ

A cro b a tP D FM a k e r (PDFM aker-xia)


PU P 7 RIAL (p u p 7 .xiam )

SC M e nu s (sh ortcu t m enu&.pup 7 }

V B A P ro je ct ( 1 }

MockJes

Microsoft Excel Objects


j 1 ( 1)
2 ( 2)
()

. 7.3. Project Explorer


VBE
, Project Explorer.
, ,
Project Explorer.

Excel , Project Explorer


. , Project Explorer .
,
.

Microsoft Excel Objects.
( ),
(ThisWorkbook), A c t iv e W o r k b o o k .
VBA, M o d u le s ,
. F o rm s ,
U s e rF o rm ( ,
). , C la s s
M odules. , , R e f e r
ences ( ,
VBA-).

III. Visual Basic for Applications

170

VBA
VBA,
Project Explorer Inserts Module (1^ ).
Inserts Module
.
Excel VBA,
.

VBA
VBA ,
Project Explorer File1^ Remove (
). ,
Remove .
(
). ,
( ), (,
1).


, R e f e r e n c e s ,
.
. ,
. , (,
VBA U s e r F o r m ) .
, Project Explorer
File^Export File (^ ) ( <Ctrl+E>).
, . ,
( ).
U s e r F o r m , , U s e r F o r m .
, Project Explorer
File*=>Import File (^ ).
, . ,
File1^ Export File.

U serForm ,
, .
, ; Project Explorer
.


VBA, .
.
:

7. VBA

171

( Project Explorer);

(,
! Project Explorer);

VBA;

( ,
);

U s e r F o r m .


VBE ,
. Excel.
, , , ..
,
, ,
. ,
.
, .
, . ,
.
, . ,
(Close) ,
. ,
Project Explorer.
VBE .
Excel . (Immediate),
. ,
VBA ( ) <Enter>.
Workbooks ( "m y a d d in . x la m " ) . C lo se

C l o s e W o rk b o o k ,
. .

VBA
, .
Sub (). , .
F u n c tio n (). ,
( VBA Excel,
).
P r o p e r ty ( ). ,
.
. ,
VBA. , ,
.

172

III. Visual Basic for Applications

VBA ,
. VBA .
VBA VBA
.


VBA, .
,
. , ,
,
.
,
( 19) ( IV).

VBA
,
VBA . VBA .
VBA. ( )
VB .
VBA .

. .

.
Excel, VBA.

.
, .


.
, ..
. <> ,
(, I f End I f ) .
, ,
.
.
VBA .
, , .

, .
. Excel
. :
Sub () F u n c tio n ();
. .
Sub F u n c tio n ,
9 10.

7. VBA

173

V B A .
.
,
<Enter> . ,
VBA, .
M sgB ox " " & U C a s e ( S H O R T C U T M E N U F I L E ) _
& v b C r L f Sc v b C r L f & " " _
& T h isW o rk b o o k . P a th & v b C r L f & v b C r L f _
& " , B u d g e t M a n " , _
v b C r i t i c a l , A P PN A M E

,
. , ,
.

Excel, VBE .
, ,
Undo () ( <Ctrl+Z>),
.
Redo () ( <Ctrl+Y>),
, .
, .

: V BA
.
Sub S a y H e l l o O
Msg = " " & A p p l i c a t i o n . U s e r N a m e
Ans = M s g B o x (M s g , v b Y e s N o )
I f Ans = vbNo Then
M sgBox " ."

& "?"

E lse
M sgBox

" ,

!"

End I f
End Sub

. 7.4 , VBA.

, VBE
. ,
(=), VBE . ,
. , .

S a y H e llo ,
. .
1. <F5>.
2. Run^Run Sub/UserForm (^
/ ).
3. Run Sub/UserForm,
Standard.

174

III. Visual Basic for Applications


_____

\Et*

!<

l" rt

Ffirmat

bug

gun

IoolJ

AtkHm

yymdov.

jjep

18 6*1 * -.J ;"* * . &2

VBAProject (PfRSOMAlJCLSB)
Microsoft E*cei Objects
VBA/Project ()
-1 Microsoft Excel Objects

1{1)

Modules

Sub SayHelloO
Msg = " " & Application.UserName &
Ans = MsgBox(Msg, vbYesNo)
If Ans = vbNo Then
MsgBox " ."
Else
MsgBox ", !"
End If
End Sub

0 .

. 7.4. VBA-

, .

(. 7.5), ,

Excel (Excel Options). 7 5 - ,


, Excel. ; ,
. 7.4
.
Alex?

Excel.
, VBE.

VBA (
). , VBE
. , VBE, a Excel
, .
, .

( ):

( );

(Msg Ans);

( &);

VBA (MsgBox);

VBA (vbYesNo vbNo);

I f - Then - E ls e ;

( ).
, ?

7. VBA

175


VBA
Excel.
,
S a y H e llo . ,
.
.
, ,
. ,
.
1. ( ).
2. ^ ^ (Developer^Code*^
Record Macro). Excel
(Record Macro).
3. , , .
Excel VBA VBA .
Excel
VBA. , Excel
. .
4. ^ ^1^ (Page Layout^Page Setup^Orientation^Landscape).
5. ^1^ (Developer^Code1^
Stop Recording) ,
.
Excel .
, VBE ( <Alt+Fll>)
Project Explorer. M o d u le s ,
. M o d u le l, (
M o d u le l, M odu le2 ). , Excel,
. 7.6.
.
, ,
( ).
(Page Setup), Excel
, .
, , , .
, ,
, .
, .
.
Sub M a c r o l ()
W ith A c t i v e S h e e t . P a g e S e t u p
.O r ie n t a t io n = x lL a n d s c a p e
End W i t h
End Sub

III. Visual Basic for Applications

176

, - - Modole2 (Code)

HI"-1

^JdisJ
zi

Sub !()
!

Application.PrintConraunication False
With ActiveSheet.PageSetup
.PrintTitleRows ""
.PrintTitleColumns - ""
End With
Application.PrintConraunication = True
ActiveSheet.PageSetup.Prin tArea - "**
Application.PrintCommunication False
With ActiveSheet.PageSetup
.LeftHeader = ""
.CenterHeader * ""
.R ig h tH e a d e r -
.LeftFooter - ""
.CenterFooter =
.RightFooter
.LeftMargin = Application.InchesToPoints(0.7)
.RightMargin = Application.InchesToPoints(0.7)
.TopMargin Application.InchesToPoints(0.75)
.BottonMargin = Application.InchesToPoints{0.75)
.HeaderMargin = Application.InchesToPoints(0.3)
.FooterMargin * Application.InchesToPoints(0.3)
.PrintHeadings - False
.PrintGridlines False
.PrintCoraments = xlPrintNoCoMments
.PrintQuality - 1200
.CenterHorizontally - False
.CenterVertically False
.Orientation = xlLandscape
.Draft - False
.PaperSize = xlPaperA4
.FirstPageNuiaber xlAutomatic
.Order = xlDownThenOver
.BlackAndWhite * False
.Zoom 100
.PrintErrors = xlPrintErrorsDisplayed
.OddAndEvenPagesHeaderFooter - False
.DifferentFirstPageHeaderFooter False
.ScaleWithDocHeaderFooter - True
.AlignMarginsHeaderFooter = True
.EvenPage.LeftHeader.Text *"
.EvenPage.CenterHeader.Text = ""
.EvenPage.RightHeader.Text ""
.EvenPage.LeftFooter.Text = ""
.EvenPage.CenterFooter.Text "
.EvenPage.RightFooter.Text * ""
.FirstPage.LeftHeader.Text *
.FirstPage.CenterHeader.Text - ""
.FirstPage.RightHeader.Text = "
.FirstPage.LeftFooter.Text -
.FirstPage.CenterFooter.Text = ""

. 7.6. , Excel

, , O r i e n t a t i o n .
, W it h - E n d
W it h .
Sub 1()
A c t iv e S h e e t . P a g e S e tu p .O r ie n ta tio n
End Sub

= x lb a n d s c a p e

O r i e n t a t i o n P a g e S e t u p
. , x l b a n d s c a p e ,
. x l b a n d s c a p e
2, a x l P o r t r a i t 1. ,
1.
Sub 1 ()
A c t iv e S h e e t . P ag e S e tu p .O r ie n t a t io n
End Sub

= 2

7. VBA

177

,
. ,
.
VBA,
, , .
. ,
P a g e S e tu p O r i e n t a t i o n .

VBA.
, .
, ,
. ,
, ,
.

VBA

VBA. VBA
. ,
, .
, ,
,
VBA. ,
.
. -,
VB.
VB .

, ,
.

VBE
Excel ,
VBE. ,
.
VBE Tools^Options (^).
Options () : Editor (
), Editor Format ( ), General () Docking ().

. ,

178

III. Visual Basic for Applications

Excel (Excel Options) Excel, Excel


Excel (File1^ Excel Options).

Editor
. 7.7 , ,
Editor () Options ().
*1
Code Settings

~ Auto Syntax Chedc


- Require Variable Declaration

&

Auto List Members

P Auto Indent
Tab Width: [ 4

R Auto Quick Info

W Auto Data Tips


~ Window Settings

W Drag-and-Drop Text Editing


F

Default to R J Module View

P Procedure Separator

. 7.7. Editor Options

Auto Syntax Check


Auto Syntax Check ( ) ,
, VBE
VBA. .
, VBE ,
,
, .
Auto Syntax Check,
, . VBA,
.
Require Variable Declaration
Require Variable Declaration (
) VBE :
O p tio n

E x p lic it

,
. , ,
, , . ,
V a r ia n t ; ,
.
8.

7. VBA

179

Require Variable Declaration ,


.

Auto List Members


Auto List Members ( ), VBE
VBA,
. ,
.
, .
. 7.8 Auto List Members (
, VBA
). VBE A p p l i c a t i o n .
, (
).

. 7.8. Auto List Members

Auto Quick Info


Auto Quick Info ( ), VBE
, ,
. ,
. . 7.9 :
C e l ls .
Auto Data Tips
Auto Data Tips, VBE
, .
VBE, .
.

180

III. Visual Basic for Applications

lVBATe**
Sub VBATest()
Dim inputArea As Range
Set InputArea = cells(
End Sub

. 7.9. Auto Quick Info,


C e l l s

Auto Indent
Auto Indent ( ) ,
VBE ,
. , ,
.
( 4).

<>, , .
<> .
,
<Shift+Tab>.
.

Drag-And-Drop Text Editing


Drag-and-Drop Text Editing (
) ,
. , ,
,
.
Default Full Module View
Default to Full Module View (
) . ,
. ,
.
.

7. VBA

181

Procedure Separator
Procedure Separator ( ) ,
.
, .

Editor Format
. 7.10 Editor Format ( ),
Options ().
VBE.

. 7.10. Editor Format


Options

Code Colors ( ).
( ) ,
VBA. , ,
. ,
. .
Font (). ,
VBA.
(, Courier New).
,
, ; ,
.
Size (). VBA.
, , ,
. 10.
Margin Indicator ( ).
,
. ;
.

III. Visual Basic for Applications

182

General
. 7.11 , General ()
Options ().

*j|
Editor | Editor Format

General

JDocking |

Form Grtd Settings

- Edit and Continue

W Show Gnd

Grid Units: Points


Width:

Error Trapping

|6

Break on AS Errors

(*

Break in Class Modtie

Height: 1 6

Notify Before State Loss

Afegn Controls to Grtd

Break on Unhandled Errors

W Show ps
P Collapse Proj. Hides Windows

W On Demand
P

Background Compile

. 7.11. General,
Options

Form Grid Settings ( ).



; ,
U serForm .
,
, .

Show ToolTips ( ).
. .

Collapse Proj. Hides Windows (


).
Project.
.

Edit and Continue ( ).


, .
VBA ,
- .

Error Trapping ( ).
, .
, ,
Break on Unhandled Errors (
). Break on All Errors (
) ( ).
9.

Compile ().
.

7. VBA

183

.
, .

Docking
. 7.12 Docking () Options
(). VBE
, . ,
VBE.
, .
, ,
. , .

Editor | Editor Format | General

Docking

Dockable

R
R
R

Immediate WHdow

R
R

Project Explorer

Object Browser

Locals Window
Watch Window

Properties Window

OK

. 7.12. Docking Options

. ,
Project Explorer .
. ,
.

VBE
, ,
, .


,
Excel VB . .

, Excel
(Developer). ,
.

184

III. Visual Basic for Applications

,
.

Excel .

,
(.. ),
, , ..

S u b .
F u n c t i o n .

, .


Excel ,
, VBA.
, . .
1. .
2. , Excel . ,
.
3. <Alt+Fl 1> VBE.
. , .
, VBE Excel .
4. Excel VBE ,
. (
.)
5. Excel, ^1^
(Developer^Code1^Record Macro)
.
6. VBE.
7. Project Explorer M o d u le l
.
8 Project Explorer VBE .

, . 7.13.
. , VBA, Excel.
, Excel. ,
, VBA.
: , , .
, ,
.. , .

7. VBA

185

ActiveChart.ChartTitle.Text * " 1
Selection.Format.TextFrame2.TextRange.Character
With Selection.Format.TextFrame2.TextRange.char
TextDirection - maoTextDirect ionLeftToRigh
.Alignment - msoAlignCenter
End With
With Selection.Format.TextFrame2.TextRange.Char
BaselineOffset = 0
.Bold - msoTrae
.NameComplexScript - "+mn-cs"
.Fill.Visible - msoTrue
.Fill.ForeColor.RGB = RGB(0, 0,
.Fill.Transparency = 0
.Fill.solid
.size = 18
.Italic - msoFalse
Kerning = 12
Name = "+mn-lt"
.Underlinestyle - msoNOUnderline
.Strike - msoNoStrike
End With
Range("Bl").Select

. 7.13.


Excel
. , , Excel (
, ). ,
. .
1. .
2. 1.
3. 1 .
4. 1 .

5. , 1:G1
.
6. 1 .
7. VBE.
Excel .
Sub M a c r o l ()
R a n g e ( " B l" ) .S e le c t
A c t iv e C e ll. F o rm u la R lC l
R a n g e ( " C l" ) .S e le c t
A c t iv e C e ll. F o rm u la R lC l
R a n g e ( " D l" ) .S e le c t
A c t iv e C e ll. F o rm u la R lC l
R a n g e ( " E l" ) .S e le c t
A c t iv e C e ll. F o rm u la R lC l
R a n g e ( " F I " ) .S e le c t
A c t iv e C e ll. F o rm u la R lC l
R a n g e ( " G l" ) .S e le c t
A c t iv e C e ll. F o rm u la R lC l
R a n g e ( " B l" ).S e le c t

= ""
= " "
= "Map"
= "Anp"
= " "
= " "

End Sub

1^
(Developer1^ Code1^ Macros) <Alt+F8>,
! ( ) (Run).

186

III. Visual Basic for Applications

, .
, .
.
,
. ,
. .
^^ (Developer^Code^Use Relative References).
. ,
.
, .
, .
, ,
1:G1 .
1. 1.
2. ^^ (Developer^Code=>
Record Macro).
3. .
4. (Use Relative Reference)
. .
5. B1:G1 ,
.
6. 1.
7. .
, Excel .
S u b 2 ()
A c t i v e C e l l . F o r m u la R lC l = ""
A c t i v e C e l l . O f f s e t (0, 1 ) . R a n g e ( " 1 " ) . S e l e c t
A c t i v e C e l l . F o r m u l a R l C l = " "
A c t i v e C e l l . O f f s e t (0, 1 ) . R a n g e ( " A l " ) . S e l e c t
A c t i v e C e l l . F o r m u l a R l C l = "M a p "
A c t i v e C e l l . O f f s e t (0, 1 ) . R a n g e ( " A l " ) . S e l e c t
A c t i v e C e l l . F o r m u la R lC l = "Anp"
A c t i v e C e l l . O f f s e t (0, 1 ) . R a n g e ( " A l " ) . S e l e c t
A c t i v e C e l l . F o r m u l a R l C l = " "
A c t i v e C e l l . O f f s e t (0 , 1 ) . R a n g e ( " A l " ) . S e l e c t
A c t i v e C e l l . F o r m u l a R l C l = ""
A c t i v e C e l l . O f f s e t (0 , - 5 ) . R a n g e ( " A l " ) . S e l e c t
End Sub


=> (Developer^Code^Macros).
(Run).
(
).
, .
, .
. ( ,

7. VBA

187

.) S e l e c t
() ( O f f s e t ())
. ..
().
, .
, ,
,
.

,
1, , 1
. . (
O f f s e t .) ,
.

, , Excel, , ,
.
, ,
. ,
,
.
Sub ()
A c tiv e C e
A c tiv e C e
A c tiv e C e
A c tiv e C e
A c tiv e C e
A c tiv e C e
End Sub

ll.O
ll.O
ll.O
ll.O
ll.O
ll.O

ffse
ffse
ffse
ffse
ffse
ffse

t ( 0 , 0)
t ( 0 , 1)
t ( 0 , 2)
t ( 0 , 3)
t ( 0 , 4)
t (0 , 5)

=
=
=
=
=
=

""
""
"Map"
"Anp"
" "
" "

W it h - E n d
With.
Sub M a c r o 4 ()
W ith A c t i v e C e
. O f f s e t (0 ,
.0 ffse t(0 /
. O f f s e t (0 ,
. O f f s e t (0 ,
.0 ffse t(0 ,
. O f f s e t (0,
End W i t h
d Sub

ll
0)
1)
2)
3)
4)
5)

=
=
=
=
=
=

"
"
"M a p
"Anp
"
"

VBA ( ),
, .
Sub ()
A c t i v e C e l l . R e s i z e (, 6) = A r r a y ( " " , " " , " " , " " , " " , " " )
End Sub

188

III. Visual Basic for Applications


, VBA-,
(Record
Macro). .

(Macro Name).
. Excel 1, 2
.. .
, .

(Shortcut Key).
. , w ( ),
. <Ctrl+W>.
W( )
<Ctrl+Shift+W>. , ,
, ( ).
, <Ctrl+B>,
.
,
.

(Store Macro In). Excel,


, . Excel
.
(Excel ), .
( .)

Excel ,
, .

(Description). (Description)
.
.


(Personal
Macro Workbook). VBA,
. P e r s o n a l . x l s b X L S t a r t .
Excel,
. P e r s o n a l . x l s b ,
Excel .
P e r s o n a l . x l s b , .


, ,
( ^ ^ (Page Layout^Page
Setup^Orientation)) VBA.
, .

7. VBA

189

,
. , :
, Excel , (.. ),
S e l e c t i o n . ,
,
() ,
.
Range ( " A l : 5 " ) . S e l e c t
S e l e c t i o n . S t y l e = "Comma"
S e le c tio n . F o n t . B o ld = T ru e
S e le c tio n . F o n t . I t a l i c = T ru e

VBA ,
.
W ith-E nd W ith, .
Range ( " A l : 5 " ) . S e l e c t
With S e l e c t i o n
. S t y l e = "Comma"
.F o n t.B o ld = T rue
. F o n t . I t a lic = True
End W i t h

S e l e c t ,
.
With R a n g e ( " 1 : 5 " )
. S t y l e = "Comma" . F o n t . B o l d
. F o n t . I t a lic = True
End W i t h

= True

,
VBA,
.
, VBA,
. , VB
.

VBA,
.
.
, .
.
Range ( " A l " ) . V a l u e

, .
M s g B o x .
MsgBox R a n g e (" A l " ) . V a l u e

,
VBA .
Sub T e s t ()
'
End Sub

III. Visual Basic for Applications

190

<F5>
. , , .
, 1 , ,
1 .
.
VBE (Immediate).
. ,
<Ctrl+G>.
VBA <Enter>.
, ( ?)
P r i n t . , :
? R a n g e ( " A l" ) .V a lu e


VBA
VBA Visual Basic. ,
VBA ,
.
.
VBA,
Excel.
. A p p l i c a t i o n (
Excel). VBA, VBE Microsoft Word,
A p p l i c a t i o n Word.


A p p l i c a t io n ( Excel) .
, A p p lic a tio n :

W o r k b o o k s ( W o rk b o o k );

W in d o w s ( W in dow );

A d d in s ( A d d in ).

. , W orkbooks
W orkbook, W orkbook
. :

W o r k s h e e t s ( W o r k s h e e t );

C h a r t s ( C h a r t );

N am es ( Name ).

, , .
W o r k s h e e t s W o r k s h e e t W orkbook.
W o r k s h e e t , :

7. VBA

191

C hartO b j e c t s ( C hartO b j e c t );
Range ;
P a g e S e tu p ;
P iv o tT a b le s ( P iv o tT a b le ).
, ,
,
. Excel
.


VBA
. (
). , W orkbooks
W orkbook. W o r k s h e e ts ---- W ork
sheet, Workbook.
.
,
.
W orksheets( " 1 ")

1 ,
:
Worksheets (1)

W orkbook ,
W o rk s h e e ts (2) ..
S h e e ts ,
. 1
, :
S h e ets(1)


VBA,
,
(-). , Excel
1 ?
.
Workbooks( " 1 " ) .W o rk s h e e ts ( " 1 ")

Visual Basic 1
.
(, 1)
1 1,
:
Workbooks ( " 1 ") . W o rksh e e ts ( " 1 ") . Range ( " A l" )

Appl i c a t io n :

192

III. Visual Basic for Applications

A p p lic a tio n .Workbooks( "1") .W o rk sh eets("JIhctI " ) .Ra n g e ( "A l")


A p p l i c a t i o n
( ). 1
,
:
W o rk s h e e ts ( " 1 " ) . R ange( " A l ")

1 , :
R a n g e ("A l")

Excel .
Range, .

( ) .
, ,
.


: .
, .


. , R a n g e ()
V a l u e (). VBA,
V a l u e . ,
VBA M sg B o x ,
1 1 .
Sub S h ow V alue ()
Msgbox W o rk s h e e ts ( " 1 " ) . R a n g e ( " A l" ) .V a lu e
End Sub

VBA MsgBox
VBA. .

V a l u e
1 1 .
, 1,
.
, V a lu e ?
1 V a lu e .
Sub C h a n g e V a lu e ()
W o rk s h e e ts ( " 1 " ) .R a n g e ( " A l" ) .V a lu e = 1 23 .45
End Sub

Al 1
123 , 45.

7. VBA

193

, . Range
v a lu e . , .v a lu e
, .
, .

,
H asF o rm u la F o rm u la Range.
I f Range ( 11 1 ") . H asForm ula Then MsgBox Range ( "A 1 " ) . F o rm u la

I f - T h e n
: ,
Form ula. 1 , .
F o rm u la ,
VBA.
Range ("D 1 2 ") .F o rm u la = " =RAND1)* 1 0 0 "


, . ,
. C le a r
. 1:
1 , .
Sub ZapRange()
W o rk s h e e ts ( " 1 " ) . R ange( " 1 : " ) . C le a r
End Sub

, ,
C le a r C o n te n ts Range.
,
. , 1
1 Range.
( , ).
, (
). , .
Sub CopyOne ()
W o rk s h e e ts ( " 1 " ) . R an ge ( " 1 " ) . _
W o rk s h e e ts ( " 1 ") .R a n g e ( " B l " )
End Sub


VBA
.
,
.
.
,
. ,
, .
73. 3107

194

III. Visual Basic for Applications

P r o t e c t .
, P r o t e c t : ,
.
(Protect Workbook).
, M y B o o k .
x ls x , :
W o rk b o o k s ( "M yB ook.x l s x " ) . P r o t e c t

" x y z z y " , T r u e , F a ls e


( 1). ( 2),
( 3).
,
:
W o rkb o o k s(" M y B o o k .x ls x " ) . P r o t e c t

, T rue,

F a ls e

, , .
(
) .
.
W o rkb o o ks("M y B o o k .x ls x " ) .P r o t e c t

S t r u c t u r e : = T ru e , W in d o w s : = F a ls e

,
,
.
.
( ), ,
. , A d d r e s s R a n g e
. , .
M sgBox R a n g e ( " A l " ) .A d d re s s

F a ls e

'

:
MsgBox R a n g e ( " A l" ) . A d d r e s s ( F a ls e )

, .
M sgBox R a n g e ( " A l" ) . A d d r e s s ( r o w A b s o l u t e : = F a ls e )


VBA.

comment:
,
Comment. Excel
^^ (Review^Comments^New Com
ment). .
.

Comment

. . 7.14
Comment.

7. VBA

195

com m ent Type a Q u e s tio n ( ) VBE


( ). ,
.
Hi) : Excel

comment object

Exc^291GDetopa*fefw* E ^ O t^ M o 6 e lR e fw e ric e > C o ^ m e ^ O I ^

Excel Developer Reference

Comment Object
Represents a cell comment.

Remarks
The Com m ent object is a member of the Comments colection.

Example
Use the Com m ent property to return a Comment object. The fbflowtng example changes the text in the comment in cell E5.

Visual Basic for Applications

Worksheets(1).Range("E5").Comment.Text "reviewed on ** & Date


Use CommentsOrx&), where mdex\s the comment number, to return a single comment from the Comments collection. The following
example hides comment two on worksheet one.

Visual Basic for Appbcations

Worksheets(1).Comments(2).Visible = False
Use the AddComment method to add a comment to a range. The following example adds a comment to cell E5 on worksheet one.
Visual fo r A pp lica tio ns

With Worksheets(1).Range("e5").AddComment
.Visible = False
.Text "reviewed on * & Date
End With
@2010 Microsoft Corporation, Al rights reserved.

See Also

* Excel Object Model Reference


Comment Object Members

- ^ ! ^ &

.>

. 7.14. Comment


,
<F1>.
, ,
.

*]
Multiple instances of the selected word have been found. Please
select a topic and press Help.

1-xce*

Comment

Hdp

Cancel

III. Visual Basic for Applications

196

, , ,
, , ,
.
C om m ent <F1 >. Comment
, .
, Comment;
, , Com ment.

Comment
Comment . . 7.1
.
, VBA- ,
.
7 . 1 . Comment

A p p lic a tio n
Au tho r
C re a to r

Parent
Shape
V is ib le


, ,

(.. Excel)
,

, ,

(

Ra n g e )
S h a p e , ,

T r u e

Comment
. 7.2 , Comment.
, ,
.
7.2. Comment

D e le te


Comment,

Comment,

( )

Next
P re v io u s
Text

7. VBA

197

, , T e x t , .
:
,
. ,
.
, ,
.

Comments
.
Comments, Comment .
, .
, 1
.
W o rksh e e ts( " 1 " ) . Comments(1)

,
1:
MsgBox W o rk s h e e ts ( " 1 ") .C om m ents( 1 ) .T e x t

, Comment Name.
, , ,
Comment Range
.
Comments ,
. , Comments C ount,
, Comment
. , :
MsgBox A c t iv e S h e e t. Comments . C ount

, :
MsgBox A c t iv e S h e e t. Comments( 1 ) . P a re n t.A d d re s s

Comments (1) Comment


Comments. P a r e n t Comment ,
Range. A d d re s s
Range. , .
, ,
F o r E a c h -N e x t ( 8).

.
For Each cmt i n A c t iv e S h e e t . Comments
MsgBox c m t. T e x t
Next cmt

,
,
(Immediate).

III. Visual Basic for Applications

198
F o r Each cmt i n A c t iv e S h e e t. Comments
D ebug. P r i n t c m t. T e x t
N e xt cmt

Comment
Comment. ,
Range Comment. ,
Comment Comment. ,
Comment 1:
R ange( " A l " ) . Comment

, Comment
:
A c t iv e S h e e t. Comments(1)

1 , :
MsgBox R ange( " A l " ) . Comment. T e x t

Al , .

, ,
VBA.

, Comment
,
. ,
1 . Comment,
, . .
1. Shape Comment, Shape,
.
2. Fill Shape, Fill Format.
3. ForeColor Fill Format,
ColorFormat.

4. RGB ( SchemeColor) ColorFor


mat, .
, Comment
, . .
A p p l i c a t i o n (E x c e l)
W orkbook
W o rksh e e t
Comment
Shape
F illF o r m a t
C o lo rF o rm a t

7. VBA

199

!
VBA ,
.
W o rkshe ets( " 1 " ) .C om m ents( 1 ) . S hape. F i l l . F o re C o lo r _
.RGB = RGB(0, 255, 0)

Scheme l o r (
0 80).
W o rkshe ets( " 1 " ) .C om m ents( 1 ) . S hape. F i l l . F o re C o lo r _
.S chem eC olor = 12

,
. ,
, Excel
.
, , T e x t Frame
Comment, C h a r a c te r s , , ,
Font. C o lo r C o lo r ln d e x F ont.
, C o lo r ln d e x
5 .
W orksheets( " 1 ") .C om m ents(1) _
. Shape. T e x tF ra m e . C h a r a c te r s . F o n t. C o lo r ln d e x = 5


30 .


1 :
MsgBox Range (" 1 " ) . Comment. T e x t

1 ,
: O b je c t v a r i a b l e o r W ith b lo c k v a r i a b l e
not s e t (He With).
, , ,
, Comment, .. N o th in g (
VBA). T ru e, 1
:
MsgBox R a n g e ("A l").C o m m e n t I s N o th in g

, I s ,
.
,
,
( ).
.
I f Not R a n g e ("A l").C o m m e n t I s N o th in g Then _
MsgBox R ange( " A l " ) . Comment. T e x t

III. Visual Basic for Applications

200

N ot,
T ru e, , .
. ,
.

Comment
, , Comment
. , AddComment
Range. ()
1 :
R ange( " A l " ) . AddComment

, , AddComment
, . ,
.
R ange( " A l " ) .AddComment " JW ."

AddComment ,
.
.

-
Comment
(. -).
( C om m entobject .x ls m )
Comment VBA.
, VBA .


A p p lic a tio n
Excel .
, (
). VBA ,
. , ,
, . VBA
A p p l i c a t i o n . , A p p l i c a
t i o n A c t iv e C e l l, .
1 :
A c t iv e C e ll. V a lu e

= 1

, A p p l i c a t io n ,
. ,
, . , VBA
, , ,
.

7. VBA

201

,
. , (
).
Application Selection,
, . (),
ChartOb ject, TextBox, Shape.
. 7.3 Application,
.
7.3. A p p l i c a t i o n

A c tiv e C e ll
A ctive C ha rt



(ChartOb j e c t ). , N o th in g
( )


( Range, Shape, C h a rtO b je c t ..)
, VBA

ActiveSheet
ActiveWindow
Act iveW orkbook
S e lectio n
ThisWorkbook


, , ,
, .
VBA, , .
, ,
:
A c t iv e C e ll. C le a rC o n te n ts

, :
MsgBox A c tiv e S h e e t .Name

, :
MsgBox A c tiv e W o rk b o o k . FulIN am e

, ,
. Selection
Application Range, .
Value Range,
, .
S e le c tio n . V a lu e = 12

: (, ChartObject Shape), , ChartObject


Shape Value.
Range,
( ), 12.
, RangeSelection Window.
A ctive W in do w . R a n g e S e le c tio n . V a lu e = 12

III. Visual Basic for Applications

202

, ,
Count. .
MsgBox ActiveWindow.RangeSelection.Count

Range
, VBA,
,
. VBA
,
.
Range Worksheet
.
Range VBA:

Range Worksheet Range;

Cells Worksheet;

Offset Range.

Range
Range Range.
Range ,
.
.Range( 1)
.Range( 1 , 2 )


.
,
. , A1.D1 ,
D ( , ).
C o lu m n s( " : " ) . S e le c t

, . .
.
, ,
VBA. T ru e ,
(
- 10).
F u n c tio n C o n ta in s M e rg e d C e lls (rn g As Range)
im c e l l As Range
o n ta in s M e r g e d C e lls = F a ls e
F o r Each c e l l I n rn g
I f c e ll. M e r g e C e lls Then
C o n ta in s M e rg e d C e lls = T ru e
E x i t F u n c tio n
End I f

7. VBA

203

Next c e l l
End F u n c t i o n


.
, , (1, 1, 2 1),
.
Range ( " 1 : 2 " )
Range ( " A l ")

,
, VBA
. , ,
1:2 :
Range ( " 2 " ) . V a l u e

= 43

, Excel
. , 1:2 ,
T h i s o p e r a t i o n w i l l c a u s e som e m e r g e d c e l l s t o u n m e r g e . Do
you w i s h t o c o n t i n u e ? (
. ?).
Range( " 2 " ) . D e l e t e

? .
.

R a n g e : W o r k s h e e t
Range. 1 2 , Excel
( )
( ).
R a n g e .
, .
, : 1 2 ,3
1 1 .
W orksheets ( " 1 " ) .R a n g e ( " A l " ) . V a lu e

= 1 2 .3

R a n g e , .
, ,
:
W orksheets ( " 1 " ) .R a n g e ( " " ) . V a l u e

= 100


. ,
.
A c t iv e S h e e t . Range ("A l :B l 0") .V a lu e

= 2

, .
Range( " A l " ,

"B IO ")

= 2

, ,
. , ,
( R a n g e V a lu e ) .
R a n g e .

204

III. Visual Basic for Applications

,
.

Excel (). .
, 3 .
Range ( " C l:

6:6")

= 3

, 4 , ..
. .
R a n g e ( " A l , , 5 , 7 , 9 ")

= 4


Range W o rk sh e e t. Range
Range. , .
Range Range (
R ange ). R ange
. ,
2, 5. ,
Range. ,
5 , .
A c tiv e C e ll. R ange ( " 2 ") = 5

O f f s e t ( ).

C e lls
C e l ls .
Range, C e l l s W o rk sh e e t Range.
C e l ls .
. C e l l s ( _ , _ )
. C e l l s ( _ )
. C e l l s

C e l l s .
1 1 9.
, ( 1 1048576)
( 1 16384).
W o r k s h e e t s ( " " ) . C e l l s (1,

1)

=9

, 7 D3 (..
3 4) .
A c t i v e S h e e t . C e l l s (3,

4)

= 7

C e l l s Range. Range,
C e l l s ,
Range, . ? . .
5 . ,
1 .
A c t i v e C e l l . C e l l s (1 ,

1)

= 5

7. VBA

205


, ( 8).

, .

5 , ,
:
A c t i v e C e l l . C e l l s (2,

1)

= 5

: ,
1.
.
C e l l s ,
1 17179869184.
Excel 2010. , 1 ,
. 16384 XFD1, 16385 2.
SZ1 ( 520 ) 2.
A c t i v e S h e e t . C e l l s (520)

= 2

(XFD1048576)
:
MsgBox A c t i v e S h e e t . C e l l s ( 1 7 1 7 9 8 6 9 1 8 4 )

R a n g e .
R a n g e . ,
Range A1:D10 (40 ), C e l l s
1 40 R a n g e .
2000 2, 2 (
) .
Range ( " A 1 : D 1 0 " ) . C e l l s (5)

= 2000



VBA. , .
F o r m u l a , .
, .
F o r m u l a , ,
, F o r m u l a R l C l , F o r m u l a L o c a l F o r m u l a A r r a y . (
.)
v a l u e .
.
T e x t , .
, ,
. T e x t
.
V a l u e 2 V a l u e , D a t e
C u r r e n c y . V a l u e 2 D a t e C u r r e n c y

206

III. Visual Basic for Applications


V a r i a n t , . ,
12 / 6/ 2010, v a l u e D a t e ,
V a l u e 2 (, 4 0 5 1 8 ) .

C e l l s
1 40.
, , ,
. , , ,
, 1 :D10.
, 11:
R a n g e ( " A 1 : D 1 0 " ) . C e l l s (41)= 2000

C e l l s
. ,
, .
C l e a r C o n te n ts ,
C e l l s .
.
A c t iv e S h e e t .C e l l s .C le a rC o n te n ts

O f f s e t
O f f s e t ( Range C e lls )
Range. , O f f s e t
Range . .
. O f f s e t ( _ ,

_ )

O f f s e t
Range.
( ), ( ) .
12 , .
A c t i v e C e l l . O f f s e t ( 1 , 0 ) .V a lu e

= 12

15 :
A c t i v e C e l l . O f f s e t ( - 1 , 0 ) .V a lu e

= 15

1, O f f s e t
, Range.
O f f s e t (.
).
Excel
O f f s e t (..
). ,
. (
1), 1:, 1.
Sub M
A c
A c
A c

a c r o l ()
t i v e C e l l . F o r m u la R lC l = "1"
t i v e C e l l . O f f s e t (1, 0 ) . R a n g e ( " A l " ) . S e l e c t
t i v e C e l l . F o r m u la R lC l = "2"

7. VBA

207

A c t i v e C e l l . O f f s e t (1, 0 ) . R a n g e ( " A l " ) . S e l e c t


A c t i v e C e l l . F o r m u l a R l C l = "3"
A c t i v e C e l l .O f f s e t (-2, 0 ) . R a n g e ( " A l" ) .S e le c t
End S u b

F o r m u la R lC l. ,
V a lu e . F o rm u
la R lC l F o r m u la .
, 1.
, .
,
. R a n g e (" A l " ) ,
.
Sub M o d i f i e d M a c r o l O
A c t i v e C e l l . F o r m u l a R l C l = "1"
A c t i v e C e l l . O f f s e t (1, 0 ) . S e l e c t
A c t i v e C e l l . F o r m u l a R l C l = "2"
A c t i v e C e l l . O f f s e t (1, 0 ) . S e l e c t
A c t i v e C e l l . F o r m u l a R l C l = "3"
A c t i v e C e l l .O f f s e t (-2, 0 ) . S e le c t
End S u b

(, ,
), .
Sub M a c r o 1 ( )
A c tiv e C e ll = 1
A c t i v e C e l l . O f f s e t (1,
A c t i v e C e l l . O f f s e t (2,
End S u b

0)
0)

= 2
= 3


(
), . .


, ,
VBA.
VBA,
.
.
.
(, Nam e) (, D e l e t e ) .
.
Excel,
XLM. ,
, .
Excel . ,
.

III. Visual Basic for Applications

208

.
, ,
. , W orkbook Myf i l e
W orkbooks :
W o r k b o o k s ( " Myf i 1 . x l s x ")
, .

. ,
F o n t F o n t,
Range.
R a n g e ("A l " ) . F o n t .B o ld

= True

.
, S a l e s
. Summary.
.
W o r k b o o k s ( 11S a l e s . x l s x " ) . W o r k s h e e t s ( " S u m m a r y " )
W o r k b o o k s ( 1 ) . W o r k s h e e t s (1)
W o r k b o o k s ( 1 ) . S h e e t s (1)
A p p l i c a t i o n .A c t iv e W o r k b o o k .A c t iv e S h e e t
A c t iv e W o r k b o o k .A c t iv e S h e e t
A c tiv e S h e e t

,
. , ,
.
( ), .
,
, .


VBA,
, . ,
, .
, .
,
.

, .
.

, VB
, Excel.
, , .
, VBA,
.

7. VBA

209


, Ex
cel . .

Object Browser ( ) ,
. VBE Object
Browser :
<F2>;
View^Object Browser (^ );
Object Browser,
.
Object Browser . 7.15.

Object Browser
, :
Excel;
MSForms ( );
Office (, Microsoft Office);
Stdole ( OLE);
VBA;
( ,
).
, Classes (),
Classes
Members of ( ).

210

III. Visual Basic for Applications

,
, . ,
.
, , .
1. . ,
, <AII Libraries>.
2. Comment .
3. , .
Search Results ( ) ,
. ,
Classes. , (, ).
,
. <F1>,
.
Object Browser , , ,
.

,
(Immediate) VBE
VBA. ,
.

VBA
...

VBA

VBA,
.
, VBA.

VBA
,
. VBA ,
.
7 , .
. :

212

III. Visual Basic for Applications

VBA, ,
VBA.
VBA Sub.
VBA .
.
S u b V B A _ D e m o ()
'
VBA
D im T o t a l A s L o n g , i A s L o n g
T o ta l = 0
F o r i = 1 T o 100
T o ta l = T o ta l + i
Next i
MsgBox T o t a l
End Sub

,
:

(, );

(, Dim);

( T o t a l i) ;

( T o t a l

( F o r - N e x t ) ;

V B A (M sgB ox).

= 0 T o ta l

= T o ta l

+ i) ;

VBA . ,
.

VBA
VBA, VBA, .
. ;
, .
.
S u b O n e L i n e ()
= 1 : = 2
End Sub

Z=

M sgBox

, ,
.
S u b O n e L i n e ()
= 1
= 2
z = 3
MsgBox +
End Sub

+ z

; VBA ,
.
VBA: (_).

8. VBA
Sub L o n g L i n e ()
S u m m e d V a lu e = _
W o rk s h e e ts ( " 1 " ) .R a n g e ( " A l " ) .V a lu e
W o rk sh e e ts(" 2" ) . R a n g e ( " A l" ) .V a lu e
End Sub

213

+ _

Excel
.
VBA
.
. , Ans=i+2 (

), VBA :
Ans = 1 + 2

, .

Result=activesheet.range ( "al") .value=12, VBA :


R e s u lt

= A c t i v e S h e e t . R a n g e ( " a l " ) .V a lu e

= 12

, ( " a l " )
.
VBA
,
, ,
. ,

m y v a l u e ( ),
M y V a l u e ( ), VBA
M y V a l u e . ,
D im ;
.
VBA
. ,

.
Visual Basic Editor Tools^Options (^)
Options (),
( Editor Format ( )), ,
( Auto Syntax
Check ( ) Editor ()).

, . VBA
.
( ).

. . VBA
, , ,
. , ,
:
Msg = " "

III. Visual Basic for Applications

214

VBA .
Sub Comments()
1

= 0 '
1

MsgBox
End Sub

, ,
Rem.
Rem - -

Rem ( R em a rk ) ,
, BASIC; VBA
. , Rem ,
, .

,
. ,
, .
.


. , :

, ;

, ;

( ,
, );

,
Excel ;

, .

,
.

. VBA
( ) .
.
Edit () VBE
. ,
Comment Block ( ),
. Uncomment Block (
)
. ,
(Standard)
.

8. VBA

215

,
VBA .
, , .

. ,
, (T rue F a ls e )
(. ).
( ). ,
. ,
VBA , .
,
, .
VBA . ,
(, I n t e r e s t R a t e , i n t e r e s t r a t e ) .
.
,
(In te re st_ R a te ).

(#, $, %, & !)
.
254 ( ,
, ).

, .
.
, .
=1
I n te re s tR a te = 0 .0 7 5
LoanPayof f Am ount = 2 4 3 0 8 9 .8 7
D ataE ntered = F a ls e
x = x + 1
MyNum = Y o u r N u m * 1 . 2 5
UserName = " "
D a te S ta rte d = # 12/14/2006#

VBA , .. ,
.
, . ,
N ext
, :
Next = 132

,
. : C o m p ile
e rr o r : E x p e c te d V a r i a b l e ( : ).
,
, ,
VBA .

III. Visual Basic for Applications

216


VBA ,
.
. ,
, ..
.
, : ,
, . VBA ,

. , VBA
,
. ,
.
, VBA
, .
. 8.1 VBA (
).
8.1 . VBA

B yte

S in g le

1
2
2
4
4

D o u b le

C u rrency

8
12

B o o le a n
In te g e r
Long

D e c im a l

Date
O bj e c t
S trin g

8
4
10 +

0 -2 5 5
T r u e () F a l s e ()
-32768 - 32767
-2147483648 - 2147483647
-3.40282338 - - 1 .401298-45 (
); 1.401298-45 - 3.40282338 (
)
-1,79769313486232308 -4,94065645841247-324 ( );
4,94065645841247324 - 1,79769313486232308
( )
-922337203685477,5808 - 922337203685477,5807
+/-79228162514264337593543950335
; +/-7,9228162514264337593543950335
28
1 100 - 31 9999

0 - 2

1 - 65400

16


D o u b le .
Empty, E r r o r , N o t h i n g N u l l

(
)
S trin g

(
)
V a ria n t

()

8. VBA

217
. 8.1

Variant

22 +

0 - 2

()

D e c i m a l , .
V a r i a n t .
v a r i a n t VBA C D e c.

,
,
. VBA
,
VBA. , ,
VBA .
Excel
Double. VBA
.
I n t e g e r , , , ,
32767. L on g.
Excel L on g,
, I n t e g e r .

,
,
.
Sub T i m e T e s t ()
Dim A s L o n g , A s L o n g
Dim A A s D o u b l e , A s D o u b l e , A s D o u b l e
Dim i A s L o n g , j A s L o n g
Dim S t a r t T i m e A s D a t e , E n d T i m e A s D a t e
'
S t a r tT im e = T im e r
'
=
=
For i = 1 10000
=

+ 1

= + 1
For j
= 1 1 0 0 0 0
= + +
i
= - i
= / *
i
Next j
Next i
1

218

III. Visual Basic for Applications

EndTime = T im e r

MsgBox F orm at(E n dT im e - S ta r tT im e , " 0 . 0 " )
End Sub
'

Ha 7,7 (
). Dim,
. ,
Dim, .
VBA , , V a r ia n t .
.
: VBA- !
, , t im in g t e x t . x ls m .


, VBA,
Variant. Variant
:
, .
,
.
Sub V a ria n tD e m o ()
MyVar = "1 2 3 "
MyVar = MyVar / 2
MyVar = " : " & MyVar
MsgBox MyVar
End Sub

VariantDemo MyVar
. .
MyVar , MyVar
. MsgBox : : 61,5.
,
Variant, .
Sub V a ria n tD e m o 2 ()
MyVar = "1 2 3 "
MyVar = MyVar + MyVar
MyVar = " : " & MyVar
MsgBox MyVar
End Sub

:
123123. , , .
, Variant, +
.

VBA TypeName.
.
MyVar. ,

8. VBA

219

, D ouble
.
Sub V ariantD em o2 ()
MyVar = "1 2 3 "
MsgBox eName(MyVar)
MyVar = MyVar / 2
MsgBox TypeName(MyVar)
MyVar = " : " & MyVar
MsgBox TypeName(MyVar)
MsgBox MyVar
End Sub

VBA
.
, , ,
, .

.
. .
.
V a r i a n t , ,
, .
,
,
.
, ,
. , Op
t i o n E x p l i c i t , (.
). ,
C u r r e n tR a te .
C u re n tR a te = 0 .7 5 .
, , ,
.

,
VB :
Option E x p l i c i t

,
. VBA
(. 8.1); .
0 ,
VBA,
.
.
. ,
.
.

III. Visual Basic for Applications

220

TP
O p t io n E x p l i c i t

Sub MultiplyNumbers()

E K 198-5

= 203.5
MsgBox = x *
End Sub

urn___________________

_______________ J

. 8.1. VBA ,

O p tio n E x p l i c i t
VBA, Require Variable Declaration
( ) Editor ()
VBE Options ( Visual Basic).
Tools^Options (^).
,
.


,
. . . 8.2
.
8 .2.



Dim s t a t i c
Dim
P r iv a te

P u b lic

.

, .
, .

8. VBA

221

, Excel
. ,
S t a t i c (. S t a t i c ).

Dim Sub End Sub. Dim
Sub, .

Dim,
, Dimension .
BASIC
. VBA Dim
, .

,
Dim.
Sub MySub ()
Dim x As I n t e g e r
Dim F i r s t As Long
Dim I n t e r e s t R a t e As S in g le
Dim TodaysD ate As D ate
Dim UserName As S t r in g
Dim M yValue
1 - [ ]
End Sub

, Dim
, . V a r ia n t .
, ,
Dim.
Dim As I n t e g e r , As I n t e g e r , z As I n t e g e r
Dim F i r s t As Long, L a s t As D ou ble

, VBA
,
. , ,
in t e g e r :
Dim i ,

j,

k As I n t e g e r

VBA k in t e g e r ;
V a r ia n t . i , j in t e g e r
:
Dim i As I n t e g e r ,

j As I n t e g e r ,

As I n t e g e r

,
,
.
, , VBA
, , .

III. Visual Basic for Applications

222


BASIC, VBA
, . ,
MyVar , %.
Dim M yVar%


VBA.
.

In te g e r
Long
S in g le
Double
C urren cy
S t r in g

%
&
i
#
@
$

BASIC;
, .
,
.


, .
(
).
D im .
, P r o c e d u r e l P ro c e d u re 2 , C u r r e n tV a lu e .
Dim C u rre n tV a lu e as I n t e g e r
Sub P r o c e d u r e l()
'

End Sub
Sub P ro c e d u re 2 ()
'

End Sub


( E n d Sub E nd F u n c t io n ) .
End.
VBA End, .
P u b l i c
VBA
, (
) P u b l i c , Dim .
P u b lic C u rre n tR a te as Long

P u b l i c C u r r e n t R a t e
, ,
. . ,

8. VBA

223

VBA,
.
s t a t ic
S t a t i c .
.
End,
.

S ta tic .
Sub MySub ()
S t a t ic C o u n te r as I n t e g e r
' - [ ]
End Sub


,
. .

. , ,
, bWasSaved.
B o o le a n .
.

Boolean
Integer
Long
Single
Double
Currency
Date/Time
String
Object
Variant

b
i
1
s
d

dt
s tr
o bj


(
, ).
, , .

. ,
, ,
,
. ,

, .

224

III. Visual Basic for Applications


C o n s t.
.
C onst N um Q uarters as I n t e g e r = 4
C onst R ate = .0 7 2 5 , P e r io d = 12
C onst ModName as S t r i n g = "B u d g e t M a cro s"
P u b lic C onst AppName as S t r in g = "B u d g e t A p p lic a t io n "

. , VBA
. Rate D o u b le ,
P e r i o d I n t e g e r . ,
.
, . ,
, Sub
F u n c t i o n .
, .
, P u b lic
.
P u b lic C onst I n t e r e s t R a t e As D ou ble = 0 .0 7 2 5

VBA
( ).
, .


Excel VBA ,
.
. , .

(x l L a n d s c a p e ).
Sub S e tT o L a n d s c a p e ()
A c t iv e S h e e t. P a g e S e tu p . O r ie n t a t io n = x lL a n d s c a p e
End Sub

x lL a n d s c a p e
. , AutoList Members (
), (. 8.2).
VBA ,
.
x lL a n d s c a p e 2.
x l P o r t r a i t 1.
, .

Object Browser, 7,
Excel VBA. Object Browser VBE,
<F2>.

8. VBA

225

. 8.2. VBA ,


Excel, VBA , ().
VBA .

. 65535 .
2 .
1 ,
.
Dim , (
),
( ).
.
MyString
50 . YourString ,
.
Dim M y S t r i n g A s S t r i n g * 50
Dim Y o u r S t r i n g A s S t r i n g


, ,
. Date
.
, Date, 8
1 100 31 9999 . 10000
!
8 . 3107

III. Visual Basic for Applications

226

D a te . VBA
, # (. ).

, VBA,
Excel, 1 1900 .
, ,
Excel.
Date.


10 VBA,
,
1900 .
Dim Today As D ate
Dim S ta r tT im e As D ate
C onst F ir s tD a y As D ate = # 1 /1 /2 0 0 7 #
C onst Noon = # 1 2 :0 0 :0 0 #

// ,
(, /
/ ).

,
, .
(12- 24-).

Windows.
Excel
Excel ( ) , .
, 1900 . Excel
29 1900 , .
= D a te (1 9 0 0 / 2 / 29)

VBA . Excel VBA


D a te S e r ia l. ()
1 1900 .
D a t e S e r ia l(1 9 0 0 ,2 ,2 9 )

, Excel
VBA.
1 1900 28 1900 .


VBA,
.
Excel , ,

8. VBA

227

. , .
, .
. ,
VBA, ( ) . ,
Excel,
VBA. Excel .
, VBA
.
VBA (=).
(
),
= 1
X= X + 1
= ( * 2) / (z * 2)
FileOpen = T ru e
FileOpen = N o t F ile O p e n
Range ( "T h e Y e a r") .V a lu e = 2 010

.
,
( ).

.
VBA, Excel , VBA.
VBA .
VBA .
, (+), (*),
(/), (-), () (&).
( \) ( )
Mod ( ). Mod
. , 2:
17 Mod 3

VBA , Excel:
(=), (>), (<), (>=), (<=)
(<>).

( ) Excel VBA . Excel 25.


=-5*2

VBA -25.
= -5 2

, VBA
, .
2 5.
= (-5 )

III. Visual Basic for Applications

228


VBA Excel (. 8.3).
, .
8.3.

* /

+ &

= , < , > , < =,

>=,

10,
, .
= 4 + 3 * 2
:
= 4 + (3 *2 )

VBA ,
. 8.4. ( )
VBA.
8.4. VBA

Not

And
Or
Xor
Eqv
Imp

N o t

. D i s p l a y G r i d L i n e s T r u e F a l s e .
, N o t T r u e F a l s e , a F a l s e T r u e .
A c tiv e W in d o w . D is p la y G r id lin e s = _
N ot A c tiv e W in d o w . D is p la y G r id lin e s
And.
M sg B o x T r u e , 1
1. , M sgB ox
F a l s e .
MsgBox A c tiv e S h e e t.N a m e = " 1 " And A c t i v e C e l l . Row = 1

Or. M sgB ox
T r u e , 1 2.
MsgBox A c tiv e S h e e t.N a m e = " 1 " _
Or A c tiv e S h e e t.N a m e = " 2 "

8. VBA

229

, ;
, . ,
12 ,
. M on thN a m e s,
M on thN a m e s ( 0 ) , M on thN a m e s (1 )
MonthNames ( 1 1 ) .


, , D im P u b
l i c . , :
,
. , , 100 ,
:
Dim M y A r ra y (l 100) As I n t e g e r


; VBA 0. ,
.
Dim M y A rra y (0 t o 100) As I n t e g e r
Dim M yA rra y(lO O ) As I n t e g e r

101 .

VBA .
, ,
:
Option Base 1


.
VBA 60 ,
( ).
100- .
Dim M y A r ra y (l 10,

1 10) As I n t e g e r

10x10.
, .
, .
(3 , 4)

= 125

, 1000 , .
Dim (1 10,

1 10,

1 10) As I n t e g e r

, .
(4,

8, 2)

= 0

230

III. Visual Basic for Applications


.
.
Dim M y A rra y () As I n t e g e r

,
, ReDim, VBA,
. ,
, . ,
, :
ReDim M yA rra y

(1 t o )

R eD im ,
.
. , ReDim
P re s e rv e .
ReDim P re s e rv e M yA rra y

(1 t o y)


, ,
.
:

.
, ,
D im P u b l i c . , I n p u t A r e a
R ange:
Dim In p u tA r e a As Range

S e t:
S e t In p u tA r e a = R ange( "C 1 6 : E16")

, ,
, .
Sub N oO bjV a rO
W o rk s h e e ts ( " 1 " ) .R a n g e ( " A l" ) .V a lu e = 124
W o rk s h e e ts ( " 1 ") .R a n g e ( " A l " ) . F o n t.B o ld =
W o rk s h e e ts ( " 1 ") . R a n g e ( " A l " ) . F o n t . I t a l i c
W o rk s h e e ts ( " 1 ") . R ange( " A l " ) . F o n t. S iz e =
W o rk s h e e ts ( " 1 ") .R a n g e ( " A l " ) . Font.N am e =
End Sub

T ru e
= T ru e
14
"C a m b ria "

1 1 ,
, .
. ,
.
Sub O b jV a rO
Dim M y C e ll As Range

8. VBA

231

Set M y C e ll = W o rksh e e ts ( 11 1 " ) . Range ( " A l " )


M y C e ll.V a lu e = 124
M y C e ll. F o n t. B o ld = T ru e
M y C e ll. F o n t. I t a l i c = T ru e
M y C e ll. F o n t. S iz e = 14
M y C e ll. Font.N am e = C am bria
End Sub

M y C e ll R ange S e t
.
M y C e ll W o r k s h e e ts ( 1 " ) . R ange ( " A l " ).

VBA
, . ,
, .
. , VBA
, s h e e ts (1) .Range ( 11A l " ) ,
.
, .
w ith End w ith , .
.


VBA , , (
).
. ,
,
C u s to m e r ln f .
Type C u s to m e rln fo
Company As S t r i n g
C o n ta ct As S t r i n g
RegionCode As Long
Sales As D ou ble
End Type

,
Dim.
.
Dim Custom ers (1 100) As C u s to m e rln fo

232

III. Visual Basic for Applications

Bee 100 (
C u s to m e r ln f ).
.
C u s to m e rs ( 1 ) . Company = "Acme T o o ls "
C u s to m e rs ( 1 ) . C o n ta c t = "T im R o b e rts o n "
C u s to m e rs ( 1 ) . RegionCode = 3
C u s to m e rs ( 1 ) . S a le s = 1 50 67 4.98


. , C u s to m e r s (1 ) C u s to m e r s (2 ) ,
:
C u s to m e rs (2)

= C u s to m e rs (1)

.
C u s to m e rs ( 2 ) . Company = C u s to m e rs ( 1 ) . Company
C u s to m e rs ( 2 ) . C o n ta c t = C u s to m e rs ( 1 ) . C o n ta c t
C u s to m e rs ( 2 ) . RegionCode = C u s to m e rs ( 1 ) .R egionC ode
C u s to m e rs ( 2 ) . S a le s = C u s to m e rs ( 1 ) . S a le s


, VBA
, .
, - .
VBA ( ) Excel. , VBA UCase,
, Excel .

VBA,
. VBA.

VBA , VBA .
VBE VBA ,
(. 8.3). .
, , Auto List
Members ( ).
Tools^Options (^) Editor ().

VBA , Excel
. , VBA.
,
S q r VBA,
.
Sub S how R oot()
Dim M yValue As D o u b le
Dim S q ua reR oo t As D ou ble
M yValue = 25
S q ua reR oo t = S q r(M yV a lu e )
MsgBox S q uareR oot
End Sub

8. VBA

233

S q r VBA Excel.
( ) Excel VBA. W ork
sheet F u n c tio n , A p p l i c a t i o n ,
, VBA.
Excel VBA,
:
A p p lic a t io n . W o rk s h e e tF u n c tio n

M s g B o x
MsgBox VBA.
.
. ,
,
MsgBox,
.
, ,
. MsgBox ,
, . ,
MsgBox,
. MsgBox ,
, .
MsgBox
( ).
MsgBox ( [,

] [,

] [,

_ ,

] )

( ) ,

III. Visual Basic for Applications

234

( ) , ,

( ) .
(, vbYesNo).

( ) ,

. Microsoft Excel.

_ ( ) ,
.

( )
. .
, _ .


.
Ans.
Ans = M sgBox( " ?" , vbYesNo + v b Q u e s tio n ,
I f Ans = vbNo Then E x i t Sub

"")

,
(vbY esN o+ vbQ uestion). vbYesNo
: Yes, No.
v b Q u e s tio n
. , Ans
, vbYes vbNo.
No.
MsgBox 12.

, Excel
VBA. VBA Roman
.
Sub ShowRoman()
Dim D ecV alue As Long
Dim RomanValue As S t r i n g
D ecV alue = 193 9
RomanValue = A p p l i c a t i o n . W o r k s h e e tF u n c tio n . Rom an(DecValue)
MsgBox RomanValue
End Sub

M sgB ox MCMXXXIX.
, , Excel
, .
, Excel, VBA
. , VBA
Excel (SQRT), VBA
: S qr. , :
MsgBox A p p lic a t io n . W o r k s h e e t F u n c t io n . S q r t (123)

'


10, VBA
,
Excel.

8. VBA

235


, .

. VBA ,
:

W it h

E n d W ith ;

F o r E a c h -

N e x t.

With - End With


W ith - E nd W ith
. , , ,
(,
R ange).
Sub C hangeFont1 ()
S e le c tio n .F o n t.N a m e = "C a m b ria "
S e le c t io n . F o n t . B o ld = T ru e
S e le c t io n . F o n t . I t a l i c = T ru e
S e le c t io n . F o n t. S iz e = 12
S e le c t io n . F o n t.U n d e r lin e = x lU n d e r lin e S t y le S in g le
S e le c t io n . F o n t . Them eC olor = x lT h e m e C o lo rA c c e n tl
End Sub

W ith , , , .

End

W ith.

Sub C hangeFont2 ()
W ith S e l e c t i o n . F o n t
.Name = "C a m b ria "
.B o ld = T ru e
. I t a l i c = T ru e
.S iz e = 12
.U n d e r lin e = x lU n d e r lin e S t y le S in g le
.T hem eC olor = x lT h e m e C o lo rA c c e n tl
End W ith
End Sub

, . ,
.
, ,
W ith - End W ith,
,
.

VBA Excel w ith - End w ith


.
,
^
^ (Page Layout^Page Setup^Orientation).

236

III. Visual Basic for Applications

For Each - Next


, , . ,
W orkbooks () W orkbook.
, .
,

. F or
E ach - N ext.
F o r E ach - N ext .
F o r Each I n
[ ]
[ E x it F o r]
[ ]
N e xt [ ]

, , F o r E ach - N ext
W o rk s h e e ts .
MsgBox Name . (
, MsgBox .)
Sub C o u n tS h e e ts ()
Dim Ite m as W o rksh e e t
F o r Each Ite m I n A c tiv e W o rk b o o k .W o rk s h e e ts
MsgBox Item .N am e
N e x t Ite m
End Sub

ite m (,
W o rkshe et). ite m ;
.

F o r E ach - N ext
Windows,
.
Sub H idd en W ind o w s()
Dim C nt As I n t e g e r
Dim Win As Window
C nt = 0
F o r Each Win I n Windows
I f N o t W in . V is ib le Then
C nt = C nt + 1
N e x t W in
MsgBox C nt St " . "
End Sub

C nt .
Cnt.
, .
I f - T h e n
W orkbooks.

8. VBA

237

Sub C lo s e ln a c t iv e ()
Dim Book as W orkbook
For Each Book I n W orkbooks
I f Book.Name <> A ctive W o rkb o o k.N a m e Then B o o k .C lo s e
N ext Book
End Sub

F o r E ach - N ext
. F o r E ach - N ext
, . S e
l e c t i o n , Range,
Range.
, VBA UCase
. (
.)
Sub M akeUpperCase()
Dim C e ll as Range
For Each C e ll I n S e le c t io n
C e ll. V a lu e = U C a s e (C e ll.V a lu e )
Next C e ll
End Sub

VBA F o r-N e x t ,
. E x i t For.
.
Sub S e le c tN e g a tiv e ()
Dim C e ll As Range
For Each C e ll I n R ange( " 1 : 1 " )
I f C e ll. V a lu e < 0 Then
C e l l . S e le c t
E x it For
End I f
Next C e ll
End Sub

I f - T h e n
. , ,
E x i t For.


VBA .
(,
, ).
, ,
,
.
F o r E a c h -N e x t,
.
, VBA:
GoTo;
I f - Then;

238

III. Visual Basic for Applications

S e l e c t C ase;

F o r - N e x t ;

Do W h ile ;

Do U n t i l .

Go t o


GoTo.
, ( ,
, , , ).
VBA , GoTo
.
VBA I n p u t B o x
. ,
W rongNam e, .
. E x i t Sub
.
Sub GoToDemo()
UserName = In p u tB o x ( " :")
I f UserName <> " " Then GoTo WrongName
MsgBox (" , . .." )
1 - [ ] E x i t Sub
WrongName:
MsgBox " , ."
End Sub

, GoTo, , ,
.
, GoTo VBA ,
(. 9).

!

I -Then
, I f - T h e n
VBA.
.
. Excel, ,
.
I f - T h e n :
If

Then _

[E ls e _ ]

I f - T h e n
. E ls e .
.

8. VBA

239

I f - T h e n E ls e .
. VBA
, Excel.
, 0 .5 . VBA Time ,
.
, .
0 . 5, , .
Sub G re e tM e lO
I f Time < 0 .5 Then MsgBox " "
End Sub

, ,
.
Sub G re e tM e la O
I f Time < 0 .5 Then
MsgBox " "
End I f
End Sub

, I f End I f .
, T ru e.
I f End I f .
, ,
I f - Then, .
Sub GreetMe2 ()
I f Time < 0 .5 Then MsgBox " "
I f Time >= 0 .5 Then MsgBox " "
End Sub

, I f - T h e n >=
( ). ,
12.00.
E ls e I f- T h e n .
Sub G reetM e3()
I f Time < 0 .5 Then MsgBox " " E ls e _
MsgBox " "
End Sub

, ; I f - T h e n Else .
,
.
Sub G reetM e3a()
I f Time < 0 .5 Then
MsgBox " "
'
' E lse
MsgBox " "
1
End I f
End Sub

240

III. Visual Basic for Applications

(,
, ), I f - T h e n ,
I f - T h e n -E ls e . .
Sub G re e tM e 4 ()
I f Time < 0 .5 Then MsgBox " "
I f Time >= 0 .5 And Time < 0 .7 5 Then MsgBox " "
I f Time >= 0 .7 5 Then MsgBox " "
End Sub

0 . 75 18:00 ,
.
.
, ,
. , , ,
, . ,
,
, .
.
If

Then
[ _ ]

[ E l s e I f - Then
[ _ ] ]

[E ls e
[ _ _ ] ]

End I f

G reetM e5.
Sub G re e tM e 5 ()
I f Time < 0 .5 Then
MsgBox " "
E l s e l f Time >= 0 .5 And Time < 0 .7 5 Then
MsgBox " "
E ls e
MsgBox " "
End I f
End Sub

,
, I f - T h e n . ,
.
, .
.
I f - T h e n - E l s e ( E l s e l f ) .
, . , I f
End I f .
Sub G re e tM e 6 ()
I f Tim e < 0 .5 Then
MsgBox " "
E ls e
I f Time >= 0 .5 And Time < 0 .7 5 Then
MsgBox " "
E ls e
I f Time >= 0 .7 5 Then
MsgBox " "

8. VBA

241

End I f
End I f
End I f
End Sub

,
I f - T h e n . Q u a n
t i t y . I n p u t B o x
, Q u a n t i t y
, . ,
(,
).
Sub D is c o u n tlO
Dim Q u a n tity As V a r ia n t
Dim D is c o u n t As D o u b le
Q u a n tity = In p u tB o x ( " : ")
I f Q u a n tity = " " Then E x i t Sub
I f Q u a n tity
>=
0 Then D is c o u n t = 0 .1
I f Q u a n tity
>=
25
Then
D is c o u n t
I f Q u a n tity
>=
50
Then
D is c o u n t
I f Q u a n tity
>=
75
Then
D is c o u n t
MsgBox " : " & D is c o u n t
End Sub

=0 .1 5
=0 .2
=0 .2 5

, I f - T h e n
, D i s c o u n t .
.
,
. T ru e .
Sub D is c o u n t2 ()
Dim Q u a n tity As V a r ia n t
Dim D is c o u n t As D o u b le
Q u a n tity = In p u tB o x ( " :
I f Q u a n tity = " " Then E x i t Sub
I f Q u a n tity >= 0 And Q u a n t it y < 25 Then
D is c o u n t = 0 .1
E ls e lf Q u a n t it y < 50 Then
D is c o u n t = 0 .1 5
E ls e lf Q u a n tity < 75 Then
D is c o u n t = 0 .2
Else
D is c o u n t = 0 .2 5
End I f
MsgBox " : " & D is c o u n t
End Sub

11)

I f - T h e n .
.
,
S e le c t C ase, .

242

III. Visual Basic for Applications

VBA I I
VBA if- T h e n : I l f .
Excel .
:
I l f ( , _ , 4 a c T b _ F a l s e )

( ) ,

_ ( ) ,
, T ru e

4 a c T b _ F a l s e ( ) ,
, F a ls e

i i f .
, 1 , He- ,
1 .
MsgBox I l f ( R a n g e ( " A l " )

= 0,

" ",

" - ")

, ( 4 a c T b _ F a ls e ) ,
( _ ) . ,
, .
MsgBox I l f ( n

=0,

0,

1 / n)

Select Case
S e l e c t C ase
.
I f - T h e n - E ls e . S e l e c t C ase .
S e le c t Case _
[Case -n
[ - n ] ]

[Case E ls e
[ _ _ ] ]

End S e le c t

S e l e c t C ase,
G re e tM e , .
Sub G re e tM e ()
Dim Msg As S t r in g
S e le c t Case Time
Case I s < 0 .5
Msg = " "
Case 0 .5 To 0 .7 5
Msg = " "
Case E ls e
Msg = " "
End S e le c t
MsgBox Msg
End Sub

D is c o u n t ,
S e l e c t C ase. , Q u a n t i t y
. ,
.

8. VBA
Sub D is c o u n t3 ( )
Dim Q u a n tity As V a r ia n t
Dim D is c o u n t As D ou ble
Q u a n tity = In p u tB o x ( " :
S e le c t Case Q u a n tity
Case " "
E x i t Sub
Case 0 To 24
D is c o u n t = 0 .1
Case 25 To 4 9
D is c o u n t = 0 .1 5
Case 50 To 74
D is c o u n t = 0 .2
Case I s >= 75
D is c o u n t = 0 .2 5
End S e le c t
MsgBox " : " & D is c o u n t
End Sub

243

")

C ase ,
. VBA WeekDay,
,
( W eekday 1 7).
.
Sub G re e tU s e rl ()
S e le c t Case Weekday(Now)
Case 1, 7
MsgBox " "
Case E ls e
MsgBox " "
End S e le c t
End Sub


.
Sub G ree tU ser2 ()
S e le c t Case Weekday(Now)
Case 2 , 3, 4, 5, 6
MsgBox " "
Case E ls e
MsgBox " "
End S e le c t
End Sub

C ase ,
C ase, T ru e.
C ase ( ),
, C ase (
VB ).
.
Sub D is c o u n t3 ()
Dim Q u a n tity As V a r ia n t
Dim D is c o u n t As D ou ble
Q u a n tity = In p u tB o x ( " :
S e le c t Case Q u a n tity
Case " " : E x i t Sub

")

244

III. Visual Basic for Applications

Case 0 To 24: D is c o u n t = 0 .1
Case 25 To 49 D is c o u n t =
15
Case 50 To 74 D is c o u n t =
2
25
Case I s >= 75 D is c o u n t =
End S e le c t
MsgBox " :
& D is c o u n t
End Sub

VBA S e le c t Case,
T ru e . ,
, ,
.

S e l e c t C ase . ,
VBA TypeName ,
( , - ). ,
S e l e c t C ase,
. ,
. ,
.
Sub S e le c tio n T y p e ()
S e le c t Case T y p e N a m e (S e le c tio n )
Case " "
S e le c t Case S e l e c t i o n . C ount
Case 1
MsgBox " "
Case E ls e
MsgBox S e le c tio n .R o w s . C ount & " "
End S e le c t
Case " "
MsgBox " "
Case E ls e
MsgBox " , "
End S e le c t
End Sub

S e l e c t C ase , ,
S e l e c t Case End S e le c t.
, ,
. , , .
Sub S e le c tio n T y p e ()
S e le c t Case T y p e N a m e (S e le c tio n )
Case " "
S e le c t Case S e l e c t i o n . C ount
Case 1
MsgBox " "
Case E ls e
MsgBox S e l e c t i o n . Rows. C ount & " "
End S e le c t
Case " "
MsgBox " "
Case E ls e
MsgBox " , "

8. VBA

245

End S e le c t
End Sub


. , ,
,
.
, ,
, .
( S t a r t V a l ) ,
( N u m T o F ill) .
GoTo. C n t, ,
, , ,
, D o A n o th e r .
Sub BadLoop ()
Dim S t a r t V a l As I n t e g e r
Dim N u m T o F ill As I n t e g e r
Dim Cnt As I n t e g e r
S ta r tV a l = 1
N um T oF ill = 100
A c t iv e C e ll.V a lu e = S t a r t V a l
Cnt = 1
poAnother:
'A c tiv e C e ll. Of f s e t ( C n t, 0) .V a lu e = S t a r t V a l + C nt
Cnt = C nt + 1
I f Cnt < N u m T o F ill Then GoTo D o A n o th e r E ls e E x i t Sub
End Sub

.
? GoTo,
. GoTo
(. ).
,
. ,
.

( ) .
VBA ,
GoTo.

,
. , ,
.
VBA?
, ( )
. ,
,

III. Visual Basic for Applications

246

.
G o t o .
, ( ,
).
, .
, .
VBA . ,
If- T h e n - E ls e S e le c t Case, F o r-N e x t, Do U n t i l Do W hile.
, VBA .
,
.

F o r - N e x t
F o r-N e x t (
). .
F o r =
[ ]
[ E x it F o r]

[S te p ]

[ ]
[ ]

N e xt

F o r-N e x t,
S te p E x i t F or.
Sum = Sum + S q r (C ount) 100
100 .
Sub S um S quareR oots()
Dim Sum As D ou ble
Dim C ount As I n t e g e r
Sum = 0
F o r C ount = 1 To 100
Sum = Sum + S q r(C o u n t)
N e x t C ount
MsgBox Sum
End Sub

C ount (- ) 1
1 . Sum
C ount.

F o r-N e x t, ,
, .
,
F o r N ext. ,
.
, ,
.

S te p ,
. , ,
1 100.

8. VBA

247

Sub Sum OddSquareRoots()


Dim Sum As D ou ble
Dim C ount As I n t e g e r
Sum = 0
For C ount = 1 To 100 S te p 2
Sum = Sum + S q r (C o u n t)
N ext C ount
MsgBox Sum
End Sub

C ount 1,
3, 5, 7 .. C ount, , 99.
, C ount 101.
S te p F o r-N e x t .
2, 4, 6, 8 10 .
Sub D ele teR o w sO
Dim RowNum As Long
For RowNum = 10 To 2 S te p -2
R ow s(R ow N um ).D elete
Next RowNum
End Sub

,
S te p D eleteR ow s.
S te p , , .
, , ,
. , 2- , 3- 2.
S te p .
Sub D e le te R o w s2 ()
Dim RowNum As Long
For RowNum = 2 To 10 S te p 2
R ow s(R ow N um ).D elete
Next RowNum
End Sub

, BadLoop,
.
GoTo,
, F o r-N e x t.
Sub GoodLoop()
Dim S t a r t V a l As I n t e g e r
Dim N u m T o F ill As I n t e g e r
Dim Cnt As I n t e g e r
S ta r tV a l = 1
N um T oF ill = 100
For Cnt = 0 To N u m T o F ill - 1
A c t iv e C e l l . O f f s e t ( C n t , 0 ) .V a lu e = S t a r t V a l + C nt
Next Cnt
End Sub

F o r-N e x t E x i t For.
, ,
. ,
.

III. Visual Basic for Applications

248

Sub E x itF o rD e m o ()
Dim M axVal As D ou ble
Dim Row As Long
M axVal = A p p lic a tio n .W o rk s h e e tF u n c tio n .M a x (R a n g e ( " A :A " ))
F o r Row = 1 To 1048576
I f C e lls (R o w , 1 ) .V a lu e = M axVal Then
E x it For
End I f
N e x t Row
MsgBox " " & Row
C e lls (R o w , 1 ) . A c t iv a t e
End Sub

Excel .
MaxVal. F o r-N e x t
. MaxVal, E x i t F o r
.
.

E xitF o rD e m o
F o r-N e x t.
.
.
R ange( " : " ) . F in d ( A p p lic a tio n .W o r k s h e e tF u n c tio n .M a x _
(R ange( " A :A " ) ) ) . A c t iv a t e

.
F o r-N e x t
F o r-N e x t. ,
F o r-N e x t 10x10x10 -1 .
1000 -1.
Sub N e s te d L o o p s ()
Dim (1 t o 10, 1 t o 10, 1 t o 10)
Dim i As I n t e g e r , j As I n t e g e r , k As I n t e g e r
F o r i = 1 To 10
F o r j = 1 To 10
F o r k = 1 To 10
M y A r r a y ( i, j , k) = -1
N e xt k
N e xt j
N ext i
End Sub

Do W h ile
Do W h ile ,
VBA. F o r-N e x t, Do W h ile ,
. Do W h ile
.
Do [W h ile ]
[ ]
[ E x it Do]

8. VBA

249

[ ]

Loop

Do
[ ]

[ E x it Do]
[ ]

Loop [W h ile ]

, VBA W h ile .
,
. .
( ).
.
, ,
.
VBA, :
D ate ;
M onth , ;
D a t e S e r i a l , ,
.
Do W hile,
: E n t e r D a t e s l
, .
Sub E n te rD a te s l ()
' Do W h ile ,
Dim TheDate As D ate
TheDate = D a t e S e r ia l( Y e a r ( D a t e ) , M o n th (D a te ), 1)
Do W hile M o n th (T h e D a te ) = M o n th (D a te )
A c t iv e C e ll = TheD ate
TheDate = TheD ate + 1
A c t i v e C e l l . O f f s e t (1 , 0 ) . A c t iv a t e
Loop
End Sub

T heD ate, ,
.
. T heD ate
, ,
. , ,
T heD ate, .
,
E n t e r D a t e s l ,
Do W hile, .
Sub E n te rD a te s 2 ()
' Do W h ile ,
Dim TheDate As D ate
TheDate = D a t e S e r ia l( Y e a r ( D a t e ) , M o n th (D a te ),
Do
A c t iv e C e ll = TheD ate

1)

III. Visual Basic for Applications

250
TheD ate = TheD ate + 1
A c t i v e C e l l . O f f s e t (1, 0 ) . A c t iv a t e
Loop W h ile M on th (T h e D a te ) = M o n th (D a te )
End Sub

Do W h ile . ,
.
, 1
. VBA EOF,
T ru e . .
Sub D o W h ile D e m o l()
Dim L in e C t As Long
Dim L in e O fT e x t As S t r in g
Open " c : \ d a t a \ t e x t f i l e . t x t " F o r In p u t As #1
L in e C t = 0
Do W h ile N o t E O F (l)
L in e In p u t #1, L in e O fT e x t
R ange( " A l " ) . O f f s e t ( L i n e C t , 0) = U C a s e (L in e O fT e x t)
L in e C t = L in e C t + 1
Loop
C lo s e #1
End Sub



VBA 27.

Do W h ile E x i t Do.
E x i t Do , ,
L o o p .
Do U n t i l
Do U n t i l Do W h ile .
, . Do W h ile
, . Do U n t i l
, .
Do U n t i 1 .
Do [ U n t i l ]
[ ]
[ E x it Do]
[ ]

Loop

Do
[ ]
[ E x it Do]
[ ]
Loop [ U n t i l ]

, ,
Do W h ile .
( ).

8. VBA

251

Sub E n te rD a te s 3 ()
1 Do U n t i l ,
Dim TheD ate As D ate
TheDate = D a t e S e r ia l( Y e a r ( D a t e ) , M o n th ( D a te ) , 1)
Do U n t i l M o n th (T h e D a te ) <> M o n th (D a te )
A c t iv e C e ll = TheD ate
T heD ate = TheD ate + 1
A c t i v e C e l l . O f f s e t (1, 0 ) . A c t iv a t e
Loop
End Sub
Sub E n te rD a te s 4 ()
1 Do U n t i l ,
Dim TheD ate As D ate
TheDate = D a t e S e r ia l( Y e a r ( D a t e ) , M o n th (D a te ), 1)
Do
A c t iv e C e ll = TheD ate
TheD ate = T heD ate + 1
A c t i v e C e l l . O f f s e t (1, 0 ) . A c t iv a t e
Loop U n t i l M o n th (T h e D a te ) <> M o n th (D a te )
End Sub

Do W hile,
U nt i 1. ,
Do. ,
S te p , Do W hile.
Sub D o U n tilD e m o l ()
Dim L in e C t As Long
Dim L in e O fT e x t As S t r i n g
Open " c : \ d a t a \ t e x t f i l e . t x t " F o r In p u t As #1
Lin e C t = 0
Do U n t i l EOF(1)
L in e In p u t #1, L in e O fT e x t
R ange( " A l " ) . O f f s e t ( L in e C t , 0) = U C a s e (L in e O fT e x t)
L in e C t = L in e C t + 1
Loop
Close #1
End Sub

VBA , w h ile Wend.



. ,
W h ile Wend.
Sub E n te r D a te s 5 ()
Dim TheD ate As D ate
TheD ate = D a t e S e r ia l( Y e a r ( D a t e ) , M o n th (D a te ),
W h ile M o n th (T h e D a te ) = M o n th (D a te )
A c t iv e C e ll = TheD ate
TheD ate = TheD ate + 1
A c t i v e C e l l . O f f s e t (1, 0 ) . A c t iv a t e
Wend
End Sub

1)



VBA
...

VBA, .
VBA .
(Sub), , .

VBA,
VBA, VBE.
.
, , .
( ).

,
, .
, ,
, ,
.
.

III. Visual Basic for Applications

254

. ,
.
, Excel.
,
.


VBA - (Function),
10. 11
, Sub, F u n c tio n ,
.

Sub
Sub
.
[ P r iv a t e | P u b lic ] [ S t a t i c ]
[ ]
[ E x it Sub]

Sub { [ _ ] )

[ ]

End Sub

P r i v a t e ( ). ,
.

P u b l ic ( ). ,
.
, O p tio n P r i v a t e M odule,
.

S t a t i c ( ). ,
.

Sub ( ). .

_ . ,
, .
. ,
.

E x i t Sub ( ).
.

End Sub ( ). .

(). VBA.


.
, .
, .
, (, P rocessD ate, P rin tR e p o rt,

9. VBA

255

Sort A r r a y C heckFilenam e). D o lt, Up


date F ix .

,
, (, W r ite R e p o r tT o T e x tF ile
, G e t_ P r in t_ O p tio n s _ a n d _ P r in t_ R e p o r t
).

, VBA, ,
.
, ,
,
(, O p tio n E x p l i c i t ) .


,
, .
, .
Public
P u b lic , ..
.
Public , .
P u b lic .
Sub F ir s t ()

'

... [ ]

End Sub
Public Sub Second ()

'

... [ ]

End Sub

P rivate
P r i v a t e
, .

(Macro)
P u b lic . , ,
,
P r iv a t e .
(Macro).

P r i v a t e MySub.
Private Sub MySub ()

'

... [ ]

End Sub

256

III. Visual Basic for Applications

P r iv a t e ,
P u b lic .
:
O p tio n P r iv a t e M odule

, P r i
v a te .

Excel 1, 2 .. P u b lic .


, , VBA.

Run^Run Sub/UserForm (^
/ ) ( VBE). <F5>
Run Sub/UserForm Standard
().

(Macro) Excel.

<Ctrl> (
).

.
.

. Sub F u n c tio n
.

, .
,
.

.
, , ,
, .

(Immediate) VBE. ,
<Enter>.
.

,
. ,
,
( ).
, ,
.

9. VBA

257


Run Sub/UserForm
Run^Run Sub/UserForm (=> /
) VBE
.
Visual Basic, . Run=>Run Sub/UserForm
( <F5>) VBE, (
, , ).
Run^Run Sub/UserForm
, VBE (Macro),
.


Excel 1
^ (Developer^Code1^
Macros) (Macro), . 9.1. (
<Alt+F8>.) (Macros
In) , (,
, ).

. 9.1.

(Macro) :
Sub, P r i v a t e ;
Sub, ;
Sub, .

93ak. 3107

, ,
(Macro), ,
. (Macro Name),
(Macro),
(Run).

III. Visual Basic for Applications

258


, , <Ctrl+
>. , U p d a te C u s to m e r L is t <Ctrl+U>, <Ctrl+U>
.

, .
. (
), .
1. Excel ^1^ (Developer1^
Code ^Macros).
Jjxj
2. ,

CapyMiiepteSdectJon
(Macro).
:
+
3. (Options)
;
(Macro Options) (. 9.2).
4. Ctrl+.
. ,
Ctrl+,
. s . 9.2.
( ), (Macro Options)
<Ctrl+S>.
()
S ( ),
<Ctrl+Shift+S>.
5. (). ,
(Macro) .
6.
(Close) (Macro).


Excel,
. , <Ctrl+S>
Excel.
, <Ctrl+S>
.

Excel 2010 <Ctrl+


>: , J, Q. Excel
<\+\^+>, ,
F, L, N, , P n W .

9. VBA

259


, ,
XML, ( )
, . ,
Excel VBA.

Excel 2010 ,
Excel.
, .


22
.



.
Excel.

23.



. :
(
) ;
C a ll,
( ), ;
Run A p p l i c a t i o n .
VBA XLM. Run ,
, .
Run .
. MySub
( ), Up
date S h e e t .
Sub M ySub ()
' . . . [ ]
U p d a te S h e e t
' . . . [ ]
End Sub

260

III. Visual Basic for Applications

S u b U p d a t e S h e e t ()
'
. . . [ ]
End Sub

. Call Update,
;
. .
S u b M y S u b ()
M o n th N u m = I n p u t B o x ( " :
C a l l U p d a te S h e e t(M o n th N u m )
'
...
[ ]
End Sub

")

Sub U p d a te S h e e t(M o n th S e q )
'
. . . [ ]
End Sub

C a l l ,
, .

Run, Up
dateSheet MonthNum .
S u b M y S u b ()
M o n th N u m = I n p u t B o x ( " :
A p p l i c a t i o n . R u n " U p d a t e S h e e t " , M o n th N iim
'
. . . []
End Sub

")

Sub U p d a te S h e e t(M o n th S e q )
'
. . . []
End Sub

, Run
.
(. ). Main VBA
WeekDay ( 1 7, ).
SubToCall , .
Run (WeekEnd Daily).
S u b M a i n ()
D im S u b T o C a ll A s S t r i n g
S e l e c t C a s e W e e k D a y (N o w )
C a s e 1 , 7 : S u b T o C a l l = "W e e k E n d "
C a s e E ls e : S u b T o C a ll = " D a ily "
End S e le c t
A p p l i c a t i o n . R u n S u b T o C a ll
End Sub
S u b W e e k E n d ()
M s g B o x " "
'
,
End Sub
S u b D a i l y ()
M s g B o x " "

9. VBA

261

1 ,
End S u b

VBA ,
P u b l ic .
P r i v a t e
.
,
,
. VBA , ..
, .
. , MySub
: M odulel Module2. , MySub Module2
MySub M odulel, .
M o d u le l. M y S u b
C a ll M o d u l e l . M y S u b

,
: A m biguous Name D e t e c t e d (
).

, ,
. :
Run .
, VBE Tooted
References (=>). References (),
. 9.3,
. , ,
, .
,
, .
, ,
. Browse ()
References, .

,
VBE. V B A P r o j e c t . ,
.
, Properties ()
VBE. Project ()
Tools^ Properties (** ),
. Project Properties (
), General () ,
Project Name ( ).

262

III. Visual Basic for Applications

*J

R e fe ren ce s - V BA Project
Available References:
Vj Visual Baste For Applications
0 Microsoft Excel 14.0 Object Library
H o l e Automation

AcrobatPDFMaker

AdobePDFMakerX
Microsoft Forms 2.0 Object Library
PUP7TRIAL
SGHenus
IAS Helper COM Component 1,0 Type Ubrary
IAS RADIUS Protocol 1.0 Type Library
Acrobat
Acrobat Access 2.0 Type Library

< r batDiS* '

Priority

Help

*1

jJf?

- Microsoft Office 14.0 Object Ubrary

*1

---------- :------------:------------------- ------- :

Location:

C: 'Program FSesVCommon FtesV^KTOsoft Shared YDFFICE 14\M

Language:

Standard

. 9.3. References

, R e fe re n ce s,
ActiveX,
. Excel 2010
:

Visual Basic for Applications;

Microsoft Excel 14.0 Object Library;

OLE Automation;

Microsoft Office 14.0 Object Library;

Microsoft Forms 2.0 Object Library (; ,


(UserForm)).

, ,
Project Explorer VBE.
References.

,
Y ourSub, YourSub.
Y o u rS u b
C a ll Y o u rS u b

,
, , :
M y P r o j e c t . M y M o d u le . M y S u b

C a ll.

C a l l M y P r o j e c t . M y M o d u le . M y S u b


, . :

9. VBA

263

,
?
. ,
. .
,
. .
Sub M a in ()
C a l l G e t U s e r O p t io n s
C a ll P ro c e s s D a ta
C a l l C le a n u p
C a l l C lo s e lt D o w n
End Sub

.
, .
, ,
, .
, .
, ,
. ,
.

.
, ,
.


Run Application. ,
.
Consol idat, budget macros .xlsm:
A p p lic a t io n . Run

" 'b u d g e t

m a c ro s .x ls m '! C o n s o lid a t e "


Excel ,
. .
:
ActiveX;
;
(, SmartArt, WordArt,
).

, ^
(Developer^ Controls^ lnsert),
, :
ActiveX.
ActiveX ,
(UserForm).
Excel 5 Excel 95,

III. Visual Basic for Applications

264

( ).
, ActiveX
.
. ,
ActiveX ()
C o m m a n d B u tto n i, c o m m a n d B u tt o n i c i i c k , ,
.
13.

B u tto n (),
(Form), .
1. ^ ^ (Developer^
Controls ^Insert)
(Form Controls).
2. .
, ,
.
Excel (Assign Macro)
(. 9.4). ,
.
3. , ,
.

. 9.4.


(Assign Macro).
, SmartArt, Word Art,

(Assign Macro).

9. VBA

265


, ()
. ,
, , CommandButton
. , , - ,
.
:
, ,
; , ,
, W orkbook_Open;
.

19.


, (Immediate)
VBE. , <Ctrl+G>.
VBA, .
,
<Enter>.
,
,
. .
Sub C h a n g e C a s e ()
Dim M y S t r i n g A s S t r i n g
M y S t r in g = " "
M y S t r in g = U C a s e ( M y S t r in g )
D ebug. P r i n t M y S t r in g
End Sub

. 9.5 ChangeCase .
Debug.Print .


, .
:
;
;
;
.

III. Visual Basic for Applications

266

'
A *. & *) * iJ j ftg & J ar -
fit*

Jftew |mert

ai ^

Farmat

Qfbug

Run

Jools

Window

j(General)5

TP

|ChangeCase

Sub C h a n g e C a s e ()
Dim M y S tr in g A s S t r i n g
M y S tr in g = " "
M y S tr in g = U C a s e (M y S tr in g )
D e b u g .P r in t M y S tr in g
End Sub

()

El Modules
$ Modulel

____j

J 1

ch an gecase

J 2J1*L___ 1

. 9.5.

, Excel :

.
, Excel, (,
). (, ) .
(, ) 255 .
Excel . ,
( ).
, ,
: Sub,
. , .
, , . Main
ProcessFile ( Call For-Next).
ProcessFile .
.
ProcessFile ( TheFile). ,
Sub. ProcessFile
, Call.
S u b M a i n ()
D im F i l e ( l T o 3) A s S t r i n g
D im i a s I n t e g e r
F i l e ( l ) = " d e p t l. x ls x "
F i l e (2) = " d e p t 2 . x l s x "

9. VBA

267

F ile ( 3 ) = " d e p t 3 . x ls x "


F o r i = 1 To 3
C a ll P r o c e s s F ile ( F ile ( i ) )
N ext i
End S ub
Sub P r o c e s s F i l e ( T h e F i l e )
W o r k b o o k s . O p e n F i l e N a m e : = T h e F ile
'
. . . [ ]
End Sub

, ( ).
Sub M a in ()
C a ll P r o c e s s F ile ( " b u d g e t.x l s x " )
End Sub

.
. (,
) , .

.
.
. ,
.
.
Process ( ). Main
MyValue 10, Process
MyValue . Process
( YourValue) 10. Process
Main, MsgBox MyValue : 100.
Sub M a in ()
Dim M y V a lu e A s I n t e g e r
M y V a lu e = 1 0
C a l l P r o c e s s ( M y V a lu e )
M sgB ox M y V a lu e
End Sub
Sub P r o c e s s ( Y o u r V a lu e )
Y o u r V a lu e = Y o u r V a lu e
End Sub

* 10

, ,
, ,
, .
ByVal. ,
. , , ,
YourValue Process, MyValue
Main. MsgBox 10, 100.
Sub P r o c e s s ( B y V a l Y o u r V a lu e )
Y o u r V a lu e = Y o u r V a lu e * 10
End Sub

268

III. Visual Basic for Applications

, ,
. ,
,
, .
,
. , ByVal,
, .


, .
.

P u b l i c
8 , P u b l i c (
) .
P u b l i c ,
.
, M o n t h v a l
P ro c e s s M o n th .
S u b M y S u b ()
D im M o n t h V a l a s I n t e g e r
. . . [ ]
M o n th V a l = 4
C a l l P r o c e s s M o n t h ( M o n t h V a l)
'
. . . [ ]
End Sub

.
P u b lic

M o n th V a l a s

In te g e r

S u b M y S u b ()
'
. . . [ ]
M o n th V a l = 4
C a l l P ro c e s s M o n th 2
1
. . . []
E n d Sub

, - M o n t h v a l
P u b l i c , P r o c e s s M o n t h 2 ,
.


, Variant.
. Sub
, .
Integer, String.
Sub P r o c e s s ( I t e r a t io n s

As

In te g e r,

T h e F ile

As

S t r in g )

, ,
, . ,

9. VBA

269

Process String
ByRef argument type mismatch.

, .
.
10,
, .


, , , VBA
: ( ,
) ( ).
.

Break on All Errors (


). V B E
Tools^Options (=>) General
() Options (). Break on All
Errors , VBA .
Break on Unhandled Errors (
).

, VBA,
,
.
, ,
.

, VBA.


VBA .


. , ,
On Error. .
VBA
. Err, ,
, .
,
.
.

270

III. Visual Basic for Applications

,
:
On E r r o r

R e su m e N e x t

, .
, .
Err . Err.Number
( Err), Error. ,
,
Visual Basic ( ).
M sgB ox

"

" & E rr

&

" & E rro r(E rr.N u m b e r)

. 9.6 VBA, . 9.7


, , Excel. ,
, .

-
S ub C h a n g e S h e e t N a m e ()
W o r k s h e e t s ( " 2 " ) .Nam e
End Sub

Change SheetHame

"

Run-time error *9':


Subscnpt out of range

. 9.6. VBA

E r r N u m b e r E r r .
, .
M sgB ox E r r
M sgB ox E rr.N u m b e r

On Error ,
. ,
.
On E r r o r G o T o E r r o r H a n d l e r


, .
S p e c ia l C el I s , .

9. VBA

271

~3

Change SheetName

S ub C h a n g e S h e e t N a m e ()
On E r r o r R esu m e N e x t
W o r k s h e e t s ( " 2 " ) .N am e =
I f E r r .N u m b e r <> 0 T h en
M sgB ox " " & E r r
E x i t Sub
End I f
End S ub

I
' "
& E r r o r ( E r r .N u m b e r )

*1
9: Subscript out of range

. 9.7.

S p e c i a l C e l l s , ^^ 1^ ( ^
Editing^Find & S ele ct^ G o Special).
(Go Special)
. , ,
( ).
S p e c i a l C e l l s
, , .
, VBA (. 9.8).
M icro soft Visual Bask:
Run-time error '1004':

He ,
.

Debug

Help

. 9.8. S p e c i a l C e l l s
,

Sub S e l e c t F o r m u l a s ()
S e le c t io n . S p e c ia lC e ll s ( x lF o r m u la s , x lN u m b e r s ) . S e le c t
' . . . []
End Sub

272

III. Visual Basic for Applications

, On Error Resume Next


.
S u b S e l e c t F o r m u l a s 2 ()
On E r r o r R e su m e N e x t
S e l e c t i o n . S p e c ia lC e lls ( x lF o r m u la s , x lN u m b e r s ) . S e le c t
On E r r o r G o T o 0
1
. . . [ ]
End Sub

, On Error GoTo 0
.

: .
S u b S e l e c t F o r m u l a s 2 ()
On E r r o r R e su m e N e x t
S e le c t io n . S p e c ia lC e lls ( x lF o r m u la s , x lN u m b e r s ) . S e le c t
I f E r r . N u m b e r = 1 0 0 4 T h e n M s g B o x "H e _
."
On E r r o r G o T o 0
' . . . []
End Sub

Number Err 0, .
If , Err.Number 1004, , ,
.
. ,
:
If

E rr.N u m b e r

0 T hen M sgB ox

" ."

.
S u b E r r o r D e m o ()
On E r r o r G o T o H a n d l e r
S e l e c t i o n . V a l u e = 123
E x i t Sub
H a n d le r :
M sg B o x "
End Sub

."


. (,
), . On Error
Handler . ,
Exit Sub. , .

, .
.
, .
.
S u b C h e c k F o r F i l e l ()
D im F ile N a m e A s S t r i n g
D im F i l e E x i s t s A s B o o l e a n
D im b o o k A s W o r k b o o k
F ile N a m e = " B U D G E T . X L S X "
F i l e E x i s t s = F a ls e

9. VBA

F o r E a c h b o o k I n W o rkb o o k s
I f U C a s e ( b o o k .N a m e ) = F ile N a m e T h e n F i l e E x i s t s
N ext book
'
I f F ile E x is t s Then
M s g B o x F ile N a m e & " . "
E ls e
M s g B o x F ile N a m e & " . "
End I f
End S u b

273

= T ru e

For Each-Next
Workbooks. , FileExists
True. , ,
.
,
. On
Error Resume Next VBA .
, (
Set). , . If-ThenElse Err .
Sub C h e c k F o r F i l e ()
D im F ile N a m e A s S t r i n g
D im x A s W o r k b o o k
F ile N a m e = "B U D G E T . X L S X "
On E r r o r R e su m e N e x t
S e t x = W o r k b o o k s ( F ile N a m e )
I f E r r = 0 Then
M s g B o x F ile N a m e & " . "
E ls e
M s g B o x F ile N a m e & " . "
End I f
On E r r o r G o T o 0
End S u b


11 ,
.


. ,
.
. ,
.
,
( , 5).
, VBA.
, : ,
.
, , .

274

III. Visual Basic for Applications

-
-.

,
, (
Excel ).
, , .
, .


? .
.
.
1. (.. )
.
2. .
3. . ,
.
4.
.
5. VBA.


, .
Excel,
.

Excel . ,
.

, .
.
, , .

Excel (Move
or ),
/ (Move or ).
,
, ?

, .
VBA.

( VBA).

9. VBA

275

Excel , .
. ,
. , , VBA ,
.

(Macro Options)
.

, .
. ,
, .
. ,
.
, VBA
.
. ...

, ,
, :
1) ;
2) ;
3) ;
4) ( );
5) .


.
, :
;
;
;
;
.

,
.
, .
,
, .
.

III. Visual Basic for Applications

276


, ,

VBA. , .
, .
.
Excel .
S u b M a c r o l ()
S h e e t s ( " " ) . S e le c t
S h e e t s ( " " ) .M o v e B e f o r e : = S h e e t s (1)
End Sub

Move ( ,
). ,
. , .
.
C ount , .
(Immediate) VBE :
? A c t iv e W o r k b o o k . C o u n t

! , .
? A c t iv e W o r k b o o k . S h e e t s . C o u n t

. . 9.9 .

. 9.9. VBE

? .
(Immediate) :
? A c t i v e W o r k b o o k . S h e e t s ( 1 ) .Nam e

(
). , .
For Each-Next
. ,
.
S u b T e s t ()
F o r E a c h S h t I n A c t iv e W o r k b o o k . S h e e ts
M s g B o x S h t . Name
N ext Sht
End Sub

! ,
.
, .
, Sort Range.
.

9. VBA

277

. ,
,
VBA.


,
.
. , .
1. :
2, , 4 5.

1,

2. , .
3. T e s t . xlsm .
4. VBE P e r s o n a l .x l s b Project ().
P e r s o n a l . x l s b Project, ,

. Excel ,
() ,
.
5. VBA ( Inserts Module (1^
)).
6. S o r t S h e e ts (. 9.10).
.
. ,
.

.9.10. ,

III. Visual Basic for Applications

278

7. Excel. ^1
^ (Develo
per1^ Code ^Macros) (Macro).
8. (Macro) Sort Sheets
(Options),

. <Ctrl+Shift+S>.


.
. ,
, Dim
. , ReDim
.
, SheetNames. ,
MsgBox, ,
.
Sub S o r t S h e e t s O
'

D im S h e e t N a m e s () a s S t r i n g
D im i a s L o n g
D im S h e e t C o u n t a s L o n g
S h e e tC o u n t = A c t iv e W o r k b o o k . S h e e t s . C o u n t
R e D im S h e e t N a m e s (1 T o S h e e t C o u n t )
F o r i = 1 To S h e e tC o u n t
S h e e t N a m e s ( i) = A c t i v e W o r k b o o k . S h e e t s ( i ) . N a m e
M s g B o x S h e e t N a m e s ( i)
N ext i
End Sub

, Test.xlsm
<Ctrl+Shift+S>.
.
. ,
, MsgBox (
).

M s g B o x ,
P r i n t D e b u g ,
. M s g B o x :
D e b u g .P r in t

S h e e tN a m e s (i)


M s g B o x .
.

Sort Sheets
. :
SheetNames
.

9. VBA

279


SheetN am es.
S o r tS h e e t s , ,
(
).
, .
: ,
. ,
.
.
( , ).
.
F o r-N e x t,
. , ,
.
(.. - 1 ).


11 ,
.

(
-, ).
Sub B u b b l e S o r t ( L i s t () A s S t r i n g )
Dim F i r s t A s L o n g , L a s t A s L o n g
Dim i A s L o n g , j A s L o n g
Dim Temp A s S t r i n g
F i r s t = L B o u n d ( L is t )

Last = UBound(List)
For i = F i r s t To L a s t - 1
F o r j = i + 1 To L a s t
I f L is t ( i)
> L i s t (j ) T h e n
Tem p = L i s t ( j )
L is t ( j) = L is t ( i)
L i s t ( i ) = Tem p
End I f
N ext j
N ext i
End Sub

: L i s t . ,
, .
F i r s t L a s t Lbound
UBound .
,
B u b b le S o r t.
Sub S o r t T e s t e r O
Dim ( 1 T o 5) A s
Dim i A s L o n g
x ( l) = " "
x (2 ) = " "

S t r in g

280

III. Visual Basic for Applications


x(3 )

= " "
= " "
x (5 ) = " "
C a l l B u b b le S o r t ( x )
F o r i = 1 To 5
D e b u g .P r in t i , x ( i )
N ext i
End Sub
X (4)

S o r t T e s t e r , Bub
b l e S o r t (Immediate).
, .
, , S o r t S h e e t s
B u b b le S o r t, S heetN am es
. , .
S u b S o r t S h e e t s ()
D im S h e e t N a m e s () A s S t r i n g
D im S h e e t C o u n t a s L o n g
D im i a s L o n g
S h e e tC o u n t = A c t iv e W o r k b o o k . S h e e t s . C o u n t
R e D im S h e e t N a m e s (1 T o S h e e t C o u n t )
F o r i = 1 To S h e e tC o u n t
S h e e t N a m e s ( i) = A c t i v e W o r k b o o k . S h e e t s ( i ) . N a m e
N ext i
C a l l B u b b le S o r t ( S h e e t N a m e s )
End Sub
S u b B u b b l e S o r t ( L i s t () A s S t r i n
'
L i s t
D im F i r s t A s L o n g , L a s t A s
D im i A s L o n g , j A s L o n g
D im Temp A s S t r i n g
F i r s t = L B o u n d ( L is t )
L a s t = U B o u n d ( L is t )
F o r i = F i r s t To L a s t - 1
F o r j = i + 1 To L a s t
I f L is t ( i)
> L is t ( j)
Tem p = L i s t ( j )
L is t ( j) = L is t ( i)
L i s t ( i ) = Tem p
End I f
N ext j
N ext i
End Sub

g)

Long

Then

S o r t S h e e t s ,
. ,
, S o r t
S h e e ts ( , <Ctrl+G>).
For

i = 1 S h e e tC o u n t
D e b u g . P r i n t S h e e t N a m e s ( i)
N ext i

.

SheetN am es.

9. VBA

281

, , . ,
.
S h e e t s ( " " ) . M o v e B e f o r e : = S h e e t s (1)

F o r-N e x t,
, SheetN am es.
For i = 1 S h e e t C o u n t
S h e e t s ( S h e e t N a m e s ( i) ) .M o v e B e f o r e : = S h e e t s ( i )
Next i

, (i) 1.
SheetNames ( ) 1. ,
Move .
S h e e ts ( " 1 " ) .M o v e B e f o r e : =

S h e e t s ( l)

.
S h e e ts ( " 2 " ) .M o v e B e f o r e := S h e e t s (2)

S o r t S h e e ts .
Sub S o r t S h e e t s O
Dim S h e e t N a m e s () A s S t r i n g
Dim S h e e t C o u n t a s L o n g
Dim i a s L o n g
S h e e tC o u n t = A c t iv e W o r k b o o k . S h e e t s . C o u n t
ReDim S h e e t N a m e s (1 T o S h e e t C o u n t )
For i = 1 To S h e e tC o u n t
S h e e t N a m e s ( i) = A c t i v e W o r k b o o k . S h e e t s ( i ) . N a m e
Next i
C a l l B u b b le S o r t ( S h e e t N a m e s )
For i = 1 To S h e e tC o u n t
A c t i v e W o r k b o o k . S h e e t s ( S h e e t N a m e s ( i ) ) .M o v e _
B e f o r e : = A c t iv e W o r k b o o k . S h e e t s (i )
N ext i
End Sub

,
Test .x lsm .
. ,
, , ,
. S o r t S h e e t s
.
Sub S o r t S h e e t s O
1
1 .
1 < C t r l + S h if t + S >
Dim S h e e t N a m e s () A s S t r i n g
Dim S h e e t C o u n t A s L o n g
Dim i A s L o n g
1 R e D im
S h e e tC o u n t = A c t iv e W o r k b o o k . S h e e t s . C o u n t
ReDim S h e e t N a m e s (1 T o S h e e t C o u n t )
'


For i = 1 S h e e tC o u n t

282

III. Visual Basic for Applications

SheetNames(i) = ActiveWorkbook.Sheets(i).Name
Next i
1

Call BubbleSort(SheetNames)
'

For i = 1 To SheetCount
ActiveWorkbook.Sheets(SheetNames(i)).Move _
Before:= ActiveWorkbook.Sheets(i)
Next i
End Sub

, . ,
Test .xlsm .
!


, , . ,
Test.xlsm, ,
. ,
. , (
, ). .

,
.

. ,
SUMMARY ( ) Sheet 1.
BubbleSort ( U
, h ).

, <Ctrl+Shift+S>
.

, Move .

.
; ,
, .

<Ctrl+Break> VBA
.

(
(Undo)). <Ctrl+Shift+S>,
,
.



SortSheets :
Application.ScreenUpdating = False

9. VBA

283

Excel .
,
. ,
.
BubbleSort.
UCase, .
, .
:
If U C a s e ( L is t ( i) )

> U C a s e ( L i s t ( j ))

Then


:
O p t io n

C o m p a re T e x t

VBA
. , , .

, ,
, .
, . On Error Resume Next,
, Err. Err , ,
. , .
.
On E r r o r R e su m e N e x t
S h e e tC o u n t = A c t i v e W o r k b o o k . S h e e t s . C o u n t
I f E r r <> 0 T h e n E x i t S u b 1

On Error Resume Next.


, ,
. SortSheets.
I f A c t iv e W o r k b o o k

Is

N o t h in g

Then E x it

Sub

.
; ,
.
ProtectStructure WorkBook True,
. .
1
I f A c t iv e W o r k b o o k . P r o t e c t S t r u c t u r e T h e n
M s g B o x A c t iv e W o r k b o o k . N a m e & " ." , _
v b C r i t i c a l , " ."
E x it Sub
End I f

, ,
. 9.11.
,
(OldActiveSheet),
. ,
.
Set O l d A c t i v e

= A c t iv e S h e e t

284

III. Visual Basic for Applications

, :
O ld A c t iv e . A c t iv a t e

<Ctrl+Break>
, VBA .
,
. , A p p l i c a t i o n
E n a b le Cane e l Key,
<Ctrl+Break>. :
A p p l i c a t i o n . E n a b le C a n c e lK e y

= x lD is a b le d

, ,
<Ctrl+Break>.
, .
, .

, - ,
<Ctrl+Break> .
If

M sg B o x ( " ? " ,
v b Q u e s t io n + v b Y e sN o )
v b Y e s T hen E x it Sub

S o r t S h e e t s
, . 9.12.
M icro so ft Excel

. 9.11. ,

. 9.12.

S o r t S h e e t s
.
O p t io n E x p l i c i t
Sub S o r t S h e e t s O
'

1 .
'
< C t r l + S h if t + S >
D im S h e e t N a m e s () A s S t r i n g
D im i A s L o n g
D im S h e e t C o u n t A s L o n g
D im O l d A c t i v e S h e e t A s O b j e c t
I f A c t iv e W o r k b o o k I s N o t h in g T h e n E x i t S u b
S h e e tC o u n t = A c t iv e W o r k b o o k . S h e e t s . C o u n t
1

'


I f A c t iv e W o r k b o o k . P r o t e c t S t r u c t u r e T hen
M s g B o x A c t iv e W o r k b o o k . N a m e & " ." ,

9. VBA

285

v b C r i t i c a l , " . "
E x it Sub
End I f
1
I f M sg B o x ( " ? " ,
v b Q u e s t io n + v b Y e sN o )
v b Y e s Then E x it Sub
1 < C t r l+ B r e a k >
A p p lic a t io n . E n a b le C a n c e lK e y = x lD is a b le d
'


S h e e tC o u n t = A c t iv e W o r k b o o k . S h e e t s . C o u n t

'


ReD im S h e e t N a m e s (1 T o S h e e t C o u n t )

S et O ld A c t iv e S h e e t = A c t iv e S h e e t

'

'


For i = 1 S h e e tC o u n t
S h e e t N a m e s ( i) = A c t i v e W o r k b o o k . S h e e t s ( i ) . N a m e
N ext i

'


C a l l B u b b le S o r t ( S h e e t N a m e s )

1
A p p lic a t io n . S c r e e n U p d a t in g = F a ls e
1
For i = 1 S h e e tC o u n t
A c t i v e W o r k b o o k . S h e e t s ( S h e e t N a m e s ( i ) ) .M o v e _
B e f o r e : = A c t iv e W o r k b o o k . S h e e t s (i )
N ext i
1
O ld A c t iv e S h e e t . A c t iv a t e
End Sub

S o r t S h e e t s ,
Excel.
(Macro)
<Alt+F8> <Ctrl+Shift+S>.
.
.
1.
(Customize the Ribbon).
2. (Customize Ribbon)
Excel (Excel Options) (Choose Commands From)
(Macros).
3. PERSONAL. XLSB! S o r tS h e e t s .
4.

. ( .)

III. Visual Basic for Applications

286

(Worksheets) (View) ,
, (Short Sheets) (. 9.13).

~3


17

PERSOMALXLSBiSortSheets
PERSONAL.XLSBIMaKpod




17
[ 7

| 7
[7

()

17
17
17

Cfepoc ^

... ;

- |

. 9.13.


, . :
, ,
, ( )
VBA.

:
. ,
2 .
2 .
,
.



...





Windows API

,
, VB.


VBA,
. Visual Basic for Applications (VBA)
.
,
. , F u n c t io n
( ) Excel
VBA. , F u n c t io n
.

288

III. Visual Basic for Applications

Function :

VBA;

, .
Function Excel
VBA.
VBA .

11
. .


, Excel. ,
,
. Excel 2010 400 .
, VBA.
, Excel VBA,
.
.
VBA.
, ,
. .
, , ,
, .
,
.
, ,
. , ,
.
.
, , ,
.
,
. , ,
(Insert Function) Excel.
, .
,
.


, VB.
, VBA. Remove Vowels
. .
F u n c t i o n R e m o v e V o w e ls ( T x t ) A s S t r i n g
'

10.

289

Dim i A s L o n g
R e m o v e V o w e ls = " "
For i = 1 To le n ( T x t )
I f N o t U C a s e ( m id ( T x t , i , 1 ) ) L i k e " [ ] " T h e n
R e m o v e V o w e I s = R e m o v e V o w e ls & m i d ( T x t , i , 1)
End I f
N ext i
End F u n c t io n

, ,
, .
.

, , , VBA.
(Sheet),
(UserForm) (ThisWorkbook),
.


, RemoveVowels, Excel
.
:
=Rem oveVowels ( A l)

. 10.1.
, .
, .

1
2
3
4
5
6
7
8

Microsoft Excel
abcdijklmnoprst
.
.

.
.
.

Mcrsftxd
bcdjklmnprst
.
.

. 10.1.

.
, ^
^ (Formulas ^Function Library Insert Function)
.
(Insert Function),
( (User Defined)).

. ,
R e m o v e V o w e l s Excel (Upper).
( ).
=0 (R e m o v e V o w e ls ( A l) )
103ak. 3107

290

III. Visual Basic for Applications

VBA
,
VBA. VBA, ,
RemoveVowels,
. VBA MsgBox
, , RemoveVowels
(. 10.2). .
S u b Z a p T h e V o w e ls ()
D im U s e r l n p u t a s S t r i n g
U s e r ln p u t = I n p u t B o x ( " : " )
M sg B o x R e m o v e V o w e ls ( U s e r ln p u t ) , , U s e r ln p u t
End Sub

, . 10.2, InputBox
VBA Excel.
MsgBox .
VBA Excel

*1

VB xd

|~

. 10.2.
VBA


, VBA, ,
. , ,
. ,
. .
,
. , ,
.
, . ,
. : ,
.
, .
VBA,
.
F u n c t i o n M o d if y C o m m e n t ( C e l l A s R a n g e ,
C e l l . C o m m e n t . T e x t Cm t
End F u n c t io n

Cm t A s

S t r in g )

.
1 . , 1
.
= M o d if y C o m m e n t ( A l, " " )

10.

291


, . ,
, .

.
.
F u n c t io n R e m o v e V o w e ls ( T x t ) A s S t r i n g
'
Dim i A s L o n g
R e m o v e V o w e ls = " "
Fo r i = 1 To L e n ( T x t)
I f N o t U C a s e ( M id ( T x t , i , 1 ) ) L i k e
" [ ] " T h e n
R e m o v e V o w e ls = R e m o v e V o w e ls & M i d ( T x t , i , 1)
End I f
Next i
End F u n c t i o n

, F u n c tio n , Sub,
(RemoveVowels).
(Txt), .
As S t r i n g , . (Excel
V a r i a n t , .)
(),
. Dim,
(i), . Long.

,
. ,
, .

F o r-N e x t.
, .
VBA Mid,
, .
Excel L ik e .
, I f T ru e,
, , I, , U, , , , , , , , .
RemoveVowels.
.
, RemoveVowels.
End Func t i on.
,
. , ,
, .
F u n c tio n R e m o v e V o w e ls ( t x t ) A s S t r i n g
1
Dim i A s L o n g
Dim T e m p S t r in g A s S t r i n g

(T x t)

292

III. Visual Basic for Applications

T e m p S t r in g = " "
F o r i = 1 To L e n ( tx t)
S e le c t C a se u c a s e ( M id ( t x t , i , 1 ))
C ase "A ",
"E ", " I " ,
"0 ",
"U " ,
"A ",
" ", " ",
" " # " " , " ",
" "
'


C a se E ls e
T e m p S t r in g = T e m p S t r in g & M i d ( t x t , i ,
End S e le c t
N ext i
R e m o v e V o w e ls = T e m p S t r in g
E n d F u n c t io n

"E ",

" ",

1)

(TempString),
( ). ,
, TempString
. Select Case
If-Then.
-

- re m o v e v o w e l s . x ls m .


Sub. (
Sub 9.)
.
[ P u b lic

| P r iv a t e ] [ S t a t ic ]

F u n c t io n

( [ _ ] ) [A s

[ ]
[ = ]
[ E x it F u n c t io n ]
[ ]
[ = ]
E n d F u n c t io n

.
Public ( ). ,

VBA.
Private ( ). ,

.
Static ( ). , ,

, .
Function ( ). ,

( ).
. ,
.
.

10.

293

_ ().
, , .
. .

E x it

(). , .
(). VBA.

F u n c t i o n (). ,
.

E n d F u n c t i o n (). , .

, VBA, :
, ,
, .
VBA (
). F u n c tio n ,
( ) .
, ,
As ( , ). VBA,
, ,
, ,
. End F u n c tio n .
, .
, ,
. , J21,
: = ' J 2 1 ' (1).
, ,
. ,
Excel.
Excel .


9 ( P u b lic
Private). : ,
.
,
.
,
P u b lic .

, P r i v a t e ,
(Insert Function). , ,
VBA,
P r i v a t e , .
VBA ,
, ,
VBE Tools'^ References (^).

294

III. Visual Basic for Applications


(Sub)
, (Function) :

VBE (Immediate).

,
. , SumArray
, .
T o ta l

= S u m A r r a y ( )

SumArray ,
Total.
, Run Application.
.
T o ta l

= A p p lic a t i o n . Run

("S u m A rra y ",

" ")

R u n .
() . Run
( ), .


, . ,
Excel .
, .
, Excel, .
.

. ,
CountNames,
Myf unc .xlsm, :
= M y f u n c s . x ls m ! C o u n t N a m e s ( A l: A 1 0 0 0 )

(Insert Function),
.
.
VBE T ools^R eferences (^).
, ,
. ,
(Insert Function) ,
( ).
. ,
, ,
. .
21.

10.

295

, (Macro)
1^ (Developer^Code^Macros).
, VBE Run=>Sub/UserForm (^/ ) ( <F5>),
(
, ).

. ,
. ,
.

,
(.. (True) (False)).
, , .
, ,
VBA. , VBA,
,
, .
F u n ctio n C E LLH A S F O R M U LA ( c e l l ) A s B o o l e a n
CELLHASFORMULA = c e l l . H a s F o r m u la
End F u n c t io n

VBA
, ,
.
1. , .
, A1:G20.
2. ^^ ^
(HornedStyles^Conditional Formatting^New Rule).
3. (New Formatting Rule)
'
(Use a Formula to Determine Which Cells to Format).
4. , , ,
, , ,
. 1.
=C E L L H A S F O R M U L A (A l )

5. (Format) ,
.
6.
.
, ,
. . 10.3
, .

296

III. Visual Basic for Applications

. 10.3. VBA

VBE

VBE
(Immediate). . . 10.4
.
' Microsoft Visual Basic for Applications

fit*

id

ew

jnsert

Fgrmat

.1

>ebug

Run

Tools

a J |

Add-Ins

[Modulel (Code)]

Window

Help

Project - VSAProject

j^
]
^

L-j ^

J* ar

_ ff x

1-

R em oveV ow els

F u n c t io n R e m o v e V o w e ls(T x t) A s S t r i n g
'

Dim i A s Long
R em oveV ow els = ""
F or i = 1 To L e n (T x t)
I f N o t U C a s e (M id (T x t, i , 1 ) ) L ik e " [I ]
R em oveV ow els = R em oveV ow els & M id (T x t, i , 1 )
End I f
N ext i
End F u n c t io n

A<-obdtl1HMdl<fr (PDF Maker


PUP/TRIAL (pup 7.xlam)
SC Menus (shortcut .
VBAProject (PtRSONAl.XlSB)
Q Microsoft Exori Objects
| Modules
Modulel
Module 2
VBAProject ( nacHi
Microsoft Excel Objects
1 3 * (crl)
2 (?)
~ ()

Mockiel

If
? r e m o v e v o w e ls (" )

. 10.4.

Excel
) U p C a s e .
F u n c t io n U p C a s e (I n S t r i n g A s S t r in g ) A s S t r in g
'
.
D im S t r i n g L e n g t h A s I n t e g e r

10.

297

Dim i A s I n t e g e r
Dim A S C I I V a l A s I n t e g e r
Dim C h a r V a l A s I n t e g e r
S t r in g L e n g t h = L e n (I n S t r i n g )
U p C a se = I n S t r i n g
Fo r i = 1 To S t r in g L e n g t h
A S C I I V a l = A s c ( M id ( I n S t r in g , i , 1 ))
C h a rV a l = 0
I f A S C I I V a l >= 97 A n d A S C I I V a l <= 122 T h e n
C h a r V a l = -3 2
M id ( U p C a s e , i , 1) = C h r ( A S C I I V a l + C h a r V a l)
End I f
N ext i
End F u n c t io n

. , ,
- u p p e r c a s e . x ls m .
, ,
VBA U C a s e .
, ,
, , 20
. 20 .
Excel u p p e r .
. , U p C a s e
, ,
Excel .

.


-:
( ),
, ;
;

( 1 60);
, .


# !, .

(. ).


,
. (Sub).

298

III. Visual Basic for Applications


,
. , Excel , ,
. .
, .
-
, ,
-. n o a r
g u m e n t . x ls m .

, .
UserName Application.
Excel E x ce l (Excel Options),
(General), Windows.
F u n c t i o n U s e r ()
'

U s e r = A p p lic a t io n .U s e r N a m e
E n d F u n c t io n


(, ).
= U s e r ()


. ,
VBA, ,
.

,
, .
User
MsgBox , . (&)
User.
S u b S h o w U s e r ()
M s g B o x "
End Sub

" & U s e r ()

, , VBA.
-, .
F u n c t io n E x c e lD ir O A s S t r in g
'
,
E x c e lD ir = A p p lic a t io n . P a th
En d F u n c t io n

Excel

F u n c t i o n S h e e t C o u n t ()
'

S h e e tC o u n t = A p p lic a t io n . C a l l e r . P a r e n t . P a r e n t . S h e e t s . C o u n t
E n d F u n c t io n

10.

299

F u n c t io n S h e e tN a m e ()
'
S h e e tN a m e = A p p l i c a t i o n . C a l l e r . P a r e n t . N a m e
End F u n c t i o n


, ,
.
Excel.
, , ..
.
. ,
.
.
A p p lic a t io n . V o la t ile

T ru e

V o l a t i l e A p p l i c a t i o n ( T r u e F a ls e ) .
v o l a t i l e (), ,
.
, s t a t i c R a n d
v o l a t i l e , Excel
.
F u n c tio n N o n S t a t ic R a n d ()
1 ,
1
A p p lic a t io n . V o la t ile T ru e
N o n S t a t ic R a n d = R n d ()
End F u n c t io n

F a l s e v o l a t i l e
, . (
, .)
,
, <Ctrl+Alt+F9>. , ,
s t a t i c R a n d .

.
Excel .
, .
.
, ,
. VBA Rnd,
0 1.
.
F u n c tio n S t a t i c R a n d ()
1 ,
'
S t a t ic R a n d = R n d ( )
End F u n c t io n

300

III. Visual Basic for Applications

0 1000,
:
= I N T ( S t a t ic R a n d ()* 1 0 0 0 )

, , .

<Ctrl+Alt+F9>.


,
. .
($)

(%)

0-9999
10000-19999
20000-39999
40000

8,0
10,5
12,0
14,0

,
. , ,
.

, Excel. ,
, .
= ( ( 1 > = 0 / 1 < = 9 9 9 9 .9 9 ) , 1 * 0 . 0 8 ,
( ( 1 > = 1 0 0 0 0 , 1 < = 1 9 9 9 9 . 9 9 ) , 1 * 0 .1 0 5 ,
( ( 1 > = 2 0 0 0 0 , 1 < = 3 9 9 9 9 . 9 9 ) , 1 * 0 . 1 2 ,
( 1 > = 4 0 0 0 0 , 1 * 0 . 1 4 , 0 ) ) ) )

. -,
, . -, , -
.
(
VBA):
(VLOOKUP). ,
T a b le ,
, 1.
= ( A l , T a b l e ,2 ) *1

( )
, .
F u n c t i o n C o m m i s s io n ( S a le s )
C o n s t T i e r l = 0 .0 8
C o n s t T ie r 2 = 0 .1 0 5
C o n s t T ie r 3 = 0 .1 2
C o n s t T ie r 4 = 0 .1 4
'

S e le c t C a se S a le s
C a s e 0 T o 9 9 9 9 . 9 9 : C o m m is s io n = S a l e s * T i e r l
C a s e 1 0 0 0 T o 1 9 9 9 9 . 9 9 : C o m m is s io n = S a l e s * T i e r 2
C a s e 2 0 0 0 0 T o 3 9 9 9 9 . 9 9 : C o m m is s io n = S a l e s * T i e r 3

10.
C ase I s
End S e l e c t
End F u n c t i o n

>= 4 0 0 0 0 :

301
C o m m is s io n

= S a le s

* T ie r 4

VBA
VBA.
3000 (
25000 12%).
= C o m m issio n ( 2 5 0 0 0 )

,
VBA. ,
VBA ,
VBA. ,
C om m ission
.
Sub C a lc C o m m O
Dim S a l e s a s L o n g
S a le s = I n p u t B o x ( " : " )
M sgB ox " " & C o m m i s s io n ( S a le s )
End Sub

CalcComm
.
.
, .
,
,
(. 10.5).
Sub C alcC om m ()
Dim S a l e s A s L o n g
Dim M sg A s S t r i n g ,

Ans As

:
:

S t r in g

$24 500,
$2 940,00

'

S a le s = V a l ( I n p u t B o x ( "
: " , _
"
1


Msg = " : " & v b T a b
& F o r m a t ( S a l e s , " $ # , # # 0 .0 0 " )
Msg = M sg & v b C r L f & " : "
Msg = M sg & F o r m a t ( C o m m i s s i o n ( S a l e s ) ,
Msg = M sg & v b C r L f & v b C r L f & "

"))

. 10.5.



& vbTab
" $ # , # # 0 .0 0 " )
?"

'


Ans = M s g B o x ( M s g , v b Y e s N o , " " )
I f A n s = v b Y e s T h e n C a lc C o m m
End Sub

VBA: vbTab
( ), a vbCrLf (
). VBA Format
( ,
).

III. Visual Basic for Applications

302

C om m ission
; Excel , ,
.
,

. ,
1 , 2.
F u n c t io n D o u b le C e llO
D o u b le C e ll = R a n g e ( " A l" )
E n d F u n c t io n

* 2

,
. , Excel ,
.
.
D o u b l e C e l l , 1.
F u n c t io n D o u b l e C e ll ( c e l l )
D o u b le C e ll = c e l l * 2
E n d F u n c t io n


, , , ,
: ,
, 1% ,
.
Commission (
) , . ,
. Commission2.
F u n c t io n C o m m is s io n 2 ( S a le s , Y e a r s )
1
'

C o n s t T i e r l = 0 .0 8
C o n s t T ie r 2 = 0 .1 0 5
C o n s t T ie r 3 = 0 .1 2
C o n s t T ie r 4 = 0 .1 4
S e le c t C a se S a le s
C a s e 0 T o 9 9 9 9 . 9 9 : C o m m is s io n 2 = S a l e s * T i e r l
C a s e 1 0 0 0 T o 1 9 9 9 9 . 9 9 : C o m m is s io n 2 = S a l e s * T i e r 2
C a s e 2 0 0 0 0 T o 3 9 9 9 9 . 9 9 : C o m m is s io n 2
= S a le s * T ie r 3
C a s e I s >= 4 0 0 0 0 : C o m m is s io n 2
=S a l e s
* T ie r 4
End S e le c t
C o m m is s io n 2 = C o m m is s io n 2 + ( C o m m is s io n 2 * Y e a r s / 1 0 0 )
En d F u n c t io n

, ? (Years) Function
, .

(, 1, ,
, 1).
= C o m m is s io n 2 ( 1 , 1 )

303

10.

-

-, c o m i s s i o n f u n c t i o n s . x ls m .


,
() .
, ,
.
F u n c tio n S u m A r r a y ( L i s t ) A s D o u b le
Dim I te m A s V a r i a n t
S u m A rra y = 0
For E a ch Ite m I n L i s t
I f W o r k s h e e t F u n c t io n . Is N u m b e r(Ite m )
S u m A rra y = S u m A rra y + Ite m
N e xt I te m
End F u n c t io n

Then _

Excel (IsNumber) , ,
.

.
, .
MakeList 100-
. MsgBox
SumArray.
Sub M a k e L is t ()
Dim N u m s ( l T o 10 0) A s D o u b le
Dim i a s I n t e g e r
F o r i = 1 T o 1 00
N u m s( i ) = R n d * 1 0 0 0
N e xt i
MsgBox S u m A r r a y ( N u m s )
End Sub

SumArray (
Variant), . ,
1:10.
=SumArray (1 : 1 0 )

, , SumArray
Excel . , Su
mArray . ,
. SumArray
Excel .
-

array argument.xlsm
-.

304

III. Visual Basic for Applications


Excel .
, .
:
( ,

_ )

, .
, Excel 1. , , ,
.
= (A l ,1 )
= (1)

, VBA,
. ,
Optional.
.
.
F u n c t io n U s e r ( O p t io n a l U p p e r c a s e A s V a r ia n t )
I f I s M is s in g ( U p p e r c a s e ) T h e n U p p e r c a s e = F a ls e
U s e r = A p p lic a t io n .U s e r N a m e
I f U p p e rc a se Then U s e r = U C a se (U se r)
En d F u n c t io n

False ,
- . True,
( VBA- Ucase).
VBA- IsMissing,
. ,
Uppercase False ( ).
,
.
= U s e r ()
= U s e r ( F a ls e )
= U se r(T ru e )

,
, V a r i a n t .
I s M i s s i n g , .

'
.
. True,
.
False ( ), ,
, .
F u n c t i o n D ra w O n e ( R n g A s V a r i a n t , O p t i o n a l R e c a l c A s V a r i a n t = F a l s e )
1 ;
'
, R e c a lc T ru e
A p p l i c a t i o n . V o l a t i l e R e c a lc
1

305

10.
D ra w O n e = R n g ( I n t ( ( R n g . C o u n t )
End F u n c t i o n

* R nd + 1 ))

, Draw
O p tio n al, , .
,
.
=DrawOne (A l : A l 0 0)
=DrawOne ( A l : A 1 0 0 , F a l s e )
=DrawOne (A l :A l 0 0 , T r u e )

,
..
-
d r a w . x ls m .

VBA,
VBA A rray .
V a r ia n t , (.. ).
Excel, ray VBA. <Ctrl+Shift+Enter>. Excel
, , .


3.

, , A r r a y ,
, V a r i a n t .
, V a r i a n t
V a r i a n t .

MonthNames, ,
Array .
F u n c tio n M o n th N a m e s ()
M onthN am es = A r r a y ( " " , " " , " " , " " , _
" ", " " , " ", " " , " " , " " , _
" ", " " )
End F u n c t io n

MonthNames .
, M onth
Names. , , VBA .
( 12
), <Ctrl+Shift+Enter>.
{=MonthNames () }

III. Visual Basic for Applications

306

,
, <Ctrl+Shift+Enter>.
{ = ( M o n th N a m e s ( ) ) }

Excel
.
MonthNames.
F u n c t i o n M o n t h N a m e s ( O p t io n a l M ln d e x )
D im A llN a m e s A s V a r i a n t
D im M o n t h V a l A s L o n g
A llN a m e s = A r r a y ( " " , " " , " M a p " , " A n p " , _
" " , " " , " ", " " , " " , " " , _
" ", " ")
I f I s M is s in g ( M ln d e x ) T h e n
M o n th N a m e s = A llN a m e s
E ls e
S e l e c t C a s e M in d e x
C a s e I s >= 1
1 ( , 13= 1)
M o n t h V a l = ( ( M ln d e x - 1) M od 12)
M o n th N a m e s = A llN a m e s ( M o n t h V a l )
C a s e I s <= 0 1
M o n th N a m e s = A p p l i c a t i o n . T r a n s p o s e ( A llN a m e s )
End S e le c t
End I f
E n d F u n c t io n

,
VBA I s M is s in g .
,
. I s M is s in g ,
V a r ia n t .
,
.

,
.

0,
. Excel
(Transpose).

1, ,
.

M od
.
. , A llN a m e s
, 0 11.
. , 13 0 (),
24 11 ().

, . 10.6.

307

10.

A
1

2
3

10

11

12

10

13

11

14

12

15

. 10.6.

A1:L1 , .
A1:L1, <Ctrl+Shift+Enter>.
{=MonthNames () }

:14 1 12.
, 11 , .
=MonthNames ()

D3:D14 , .
{=MonthNames ( -1) }

F3 ( ):
=MonthNames (3)

,
<Ctrl+Shift+Enter> ( ).

, A r r a y ,
, O p t i o n B a s e
. O p t i o n B a s e ,
0.

-
(m o n th

n a m e s . x s lm ) , M o n t h -

N am es , -.

,
,
. R e m o v e V o w e l s , .
F u n c tio n R e m o v e V o w e ls ( T x t ) A s S t r i n g
1
Dim i A s L o n g
R e m o v e v o w e ls = " 11
For i = 1 To L e n ( T x t)
I f N o t U C a s e ( M id ( T x t , i , 1) ) L i k e " [ ] " T h e n

308

III. Visual Basic for Applications

R e m o v e V o w e ls
End I f
N ext i
E n d F u n c t io n

= R e m o v e V o w e ls

& M id ( T x t ,

i,

1)


, .
, .
(#/).
, ,
Excel.
R e m o v e V o w e ls

= "# / "

,
, .
, Cover,
.
, VBA ,
.
Excel, VBA.
:
xlErrDivO ( #/ 0 !);
xlErrNA ( #/);
xlErrName ( #?);
xlErrNull ( # !);
xlErrNum ( # !);
xlErrRef ( # !);

xlErrValue ( # !).

#/ ,
:
R e m o v e V o w e ls

= C V E r r ( x lE r r N A )

RemoveVowels. If-Then
,
. Excel (IsText),
, . ,
. ( ),
#/: ( ),
#/.
F u n c t i o n R e m o v e V o w e ls ( T x t ) A s V a r i a n t
'
;
'
# !,
D im i A s L o n g
R e m o v e V o w e ls = " "
I f A p p lic a t io n . W o r k s h e e t F u n c t io n . I s T e x t ( T x t ) Then
F o r i = 1 To L e n ( T x t)
I f N o t U C a s e ( M id ( T x t , i , 1 ) ) L i k e " [ ] " t h e n
R e m o v e V o w e ls = R e m o v e V o w e ls & M i d ( T x t , i , 1)
End I f

309

10.
N ext i
E ls e
R e m o v e V o w e ls
End I f
End F u n c t i o n

= C V E r r ( x lE r r N A )

,
. - ,
, V a r i a n t .


Excel .
, :
(1/ 2 . . . )

. , 254
. .
= ( A l : 5 , 1 : 5 , 1 : 5 , G l : G 5 )

. ,
: ,
, .
=(1:5, 1 2 , 2 4 * 3 )

,
. :
( ) P aram A rray.

P a r a m A r r a y

. V a r i a n t
( O p t i o n a l ).

,
( -).
.
F u n ctio n S im p le S u m ( P a r a m A r r a y a r g l i s t O
For E a ch a r g I n a r g l i s t
S im p le S u m = S im p le S u m + a r g
Next a r g
End F u n c t io n

A s V a r ia n t )

A s D o u b le


, .
F u n ctio n S im p le S u m ( P a r a m A r r a y a r g l i s t O
Dim c e l l A s R a n g e
For E a ch a r g I n a r g l i s t
For Each c e l l In a rg
S im p le S u m = S im p le S u m + c e l l
N ext c e l l

A s V a r ia n t )

A s D o u b le

310

III. Visual Basic for Applications

Next arg
End Function

SimpleSum , Excel .
, ,
, ,
, .


MySum.
SimpleSum, , MySum
Excel .
MySum Excel .
. 255
( ),
, , , ,
. :
=( 1 , 5 , " 6 " , , , ( 4 ) , A l : 5 , D : D , 2 * )

,
:

, ;

, ;

.
MySum ( 10.1) .
-
, MySum,
- ( mysum function.xlsm).

10.1. MySum
Function MySum(ParamArray args() As Variant) As Variant
1 Excel
'

Dim i As Variant
Dim TempRange As Range, cell As Range
Dim ECode As String
Dim m, n
MySum = 0
'

For i = 0 To UBound(args)
'

If Not IsMissing(args(i)) Then

10.

311

?
S e le c t C a se T y p e N a m e ( a r g s ( i) )
C a se "R an g e"
'
/
S e t Tem pRange = _
I n t e r s e c t ( a r g s ( i) . P a re n t.U s e d R a n g e , _
a r g s ( i) )
F o r E a c h c e l l I n Tem pR ange
I f I s E r r o r ( c e ll) Then
M ySum = c e l l '
E x i t F u n c t io n
End I f
I f c e l l = T ru e O r c e l l = F a ls e Then
M ySum = M ySum + 0
E ls e
I f I s N u m e r ic ( c e ll) O r I s D a t e ( c e ll) _
t h e n M ySum = M ySum + c e l l
End I f
N ext c e ll
C ase " V a r ia n t ()"
n = a r g s ( i)
F o r m = L B o u n d (n ) To U B o u n d (n )
M ySum = M yS um (M yS um , n ( m ) )
'
N ext m
C ase " N u ll" '
C a s e " E r r o r " 1
M ySum = a r g s ( i )
E x i t F u n c t io n
C a s e " B o o le a n "
'

I f a r g s ( i ) = " T r u e " T h e n M ySum = M ySum + 1
C a se "D a te "
M ySum = M ySum + a r g s ( i )
C a se E ls e
M ySum = M ySum + a r g s ( i )
End S e le c t
En d I f
N ext i
End F u n c t io n

. 10.7 ,
MySum. , .

#!

3,708333

31 #/0! #!

3,708333

3 /

0 1.11.18 5:00

100 11,48913

31 /01

#/

0 1.11.18 5:00

100 11,48913

"2"

5:00
04.

#/
3

05.

5 ->
6

MYSUM ~>

8
. 10.7.

M yS um

, ,
.
(. ). ,

312

III. Visual Basic for Applications

.
MySum .

( I s M is s in g )
.

(Range, Error ..)


VBA TypeName.
.

-
.

V a r ia n t , ,
.

(, #! /0 ), MySum
Excel .

Excel , 0,
(.. ,
). , MySum
, (
VBA IsN u m eric).

- I n t e r s e c t
,
. ,
, .

, Sum. , MySum ,
. ,
, ,
MySum 8 .
MySum ,
. ,
. , ,
, ,
Excel.


Excel
1900 . ,
, Excel
. - 1900 ,
.
, VBA
. , VBA, 1 100 .

10.

313

. 1752
. , ,
.

VBA .

XDATE (y ,m , d , f m t ) . ,

, .
.

XDATEADD ( x d a t e l , d a y s , f m t ) . .
.

XDATEDIF ( x d a t e l , x d a t e 2 ). .

XDATEYEARDIF ( x d a t e l , x d a t e 2 ) .
( ).

XDATEYEAR ( x d a t e l ). .
XDATEMONTH ( x d a t e l ). .
XDATEDAY ( x d a t e l ) . .

XDATEDOW( x d a t e l ) . (
1 7).
. 10.8 ,
.
I

. .'

. F

'

5
6

1732

1735

1743

XDATE

XDATEDIF

XDATEYEARDIF XDATEDOW

22

22,1732

101706

278

10

30

30,1735

100 360

274

13

13,1743

97 638

267

10

1751

16

16,1751

94 744

259

1758

28

28,1758

92144

252

12

1767

11

11,1767

88 783

243

13

1767

15

15,1767

88901

243

14

1782

12

5,1782

83157

227

237

15

16

1773

9,1773

86 743

1790

29

29,1790

80486

220

17

1795

11

2,1795

78442

214

18

1784

11

24

24, 1784

82437

225

19

1800

7,1800

76915

210

20

1804

11

23

23,1804

75134

205

21

1791

23

23,1791

80 096

219

22

1809

12,1809

73 592

201

1808

12

12

23

29

29,1808

73 637

201

24 .

1822

27

27, 1822

68 770

188

25 .

1822

10

4,1822

68 610

187

26 .

1831

11

19

19,1831

65 277

178

27 .

1829

10

5,1829

66052

180

. 10.8. VBA,

, ,
.
Excel.
VB, .

314

III. Visual Basic for Applications

.
X D A T E .
F u n c t i o n X D A T E ( , m, d , O p t i o n a l f m t A s S t r i n g )
I f I s M is s in g ( f m t ) T h e n fm t = " S h o r t D a te "
XD A T E = F o r m a t ( D a t e S e r i a l ( y , m, d) , f m t)
E n d F u n c t io n

As

S t r in g

X D A T E :

, 0100 9999;

m (112);

d (1-31);

fm t () .

fm t ,
, ( Windows).
m d ,
. , 13,
.
-
VBA
- e x t e n d e d d a t e f u n c t i o n . x l s m .

e x te n d e d

d a te

f u n c t io n s

h e lp .d o c x .




. (#!). ,
,
.

M sgBox,
. ,
- ,
. ,
,
( ).

, ,
. ,
( ), .

.
.
, ,
, Debug^Toggle Breakpoint
(^ ) ( <F9>).

10.

315

D ebu gs
Print (^), Immediate
VBA. ,
, .
F u n c t io n V o w e lC o u n t () A s L o n g
D im C o u n t A s L o n g
D im i A s L o n g
D im C h A s S t r i n g * 1
Count = 0
F o r i = 1 To L e n ( r)
Ch = U C a s e ( M i d ( r , i , 1 ) )
I f C h L i k e " [ ] " T h e n
Count = Count + 1
D e b u g . P r in t Ch, i
End I f
N ext i
V o w e lC o u n t = C o u n t
En d F u n c t i o n

, Ch i, (Immediate)
, D e b u g s Print. . 10.9
, so n A rizo n a.

i Microsoft Visual Basic fo r Applications - PERSONAL.XLSB - [M odule4 {Code}]

'4m

Run

loots

*L

Add-Ins

J* **

Window

Help

* * ?

j (General)

g T AcrobatPDFMaker (PDFMaket
PUP7TRIA1 (pup/.xlam )
^ SCMenus (shortcut memis.pu
E
VBAProject {PERSONALJCLSB)
da Microsoft Excel Objects
E l-S i Modules
Modulel
3 Module2
Module3

41

^ VBAProject (2)

Mkrosoft Excel Objects


j 1 (TfcCTI)
C l 2 ( 2)
()

-g-

F u n c t io n V o w e lC o u n t(r ) As Long
Dim C ou n t A s Long
Dim i As Long
Dim Ch A s S t r i n g * 1
C ou n t = 0
F or i = 1 To L e n (r )
Ch = u ca s e (M id (r, i , 1))
I f Ch L ik e "[]" T hen
C ou n t = C ou n t + 1
D e b u g .P r in t Ch# i
End If
N ext i
V o w e lC o u n t = C oun t
End F u n c t io n
Sub
Dim
x =
End

T est()
x A s Long
V o w e lC o u n t(" T u s c o n A r iz o n a " )
Sub

Hj__ i

if*
2
5
7
9
11

21
. 10.9.


Excel (Insert Function)
.
. ,

316

III. Visual Basic for Applications

.
(Function Arguments),
. . 10.10 .
JJ2SI

,
, '*

1
:j

JJ-!
31

........

{ ;_)
,
.

__________

,
^
.

. 4>w%m

. 10.10. ,


.
(User Defined).
(Function Arguments) .
.
, VBA .

,
Private, (Insert Function).

VBA, P r i v a t e .
,
.

MacroOptions
M a c ro O p tio n s A p p l i c a t i o n ,
Excel .
:

10.

317

, M a cro O p tio n s
.
Sub D e s c r i b e F u n c t i o n ()
Dim F u n cN a m e A s S t r i n g
Dim F u n c D e s c A s S t r i n g
Dim F u n c C a t A s L o n g
Dim A r g l D e s c A s S t r i n g ,

A rg 2 D e sc A s

S t r in g

FuncNam e = " D ra w "


F u n cD e sc = " "
Fu n cC a t = 5 '
A r g lD e s c = " , "
A r g 2 D e s c = " ( ) F a l s e , _
"
A rg 2 D e sc = A rg 2 D e s c & " . T r u e , "
A rg 2 D e sc = A rg 2 D e s c & " ."
A p p lic a t io n . M a c r o O p t io n s _
M a c r o : = FuncN am e, _
D e s c r ip t io n : = F u n c D e s c , _
C a t e g o r y : = F u n c C a t, _
A r g u m e n t D e s c r ip t io n s : = A r r a y ( A r g lD e s c ,

A rg 2 D e sc)

End Sub


MacroOptions. 5 (
). ,
MacroOptions.

Excel 2010.
Excel,
.

. 10.11
.
DescribeFunction .
, , .
. , ,
ArgumentDescript ions.

,
, 24.


MacroOptions,

(User Defined) (Insert Function).
.
^ ^ (Formulas^Function Library).

318

III. Visual Basic for Applications

|1 ,
, '
; j i '..^.
:

....................................

O ra w ( Rnq;Recak.)
.

.21
Rng | : ;

^....?1...

{#! :2; 3:4:5:6:7:8:9:10}

.
R ng , .

: 8
? ^

. 10.11.

. 10.1 ,
C a te g o ry M a cro O p tio n s. ,
( 10 13)
(Insert Function).
, .
10.1.

0
1
2
3
4
5
6
7
8
9
12
13
14
15
16
17

()
(Financial)
(Date & Time)
(Math & Trig)
(Statistical)
(Lookup & Reference)
(Database)
(Text)
(Logical)
(Information)
(Macro Control)
/ (DDE/External)
(User Defined)
(Enhineering)
(Cube)
(Compatibility)*

* Excel 2010.

10.

319

.
C a te g o ry M a c ro O p tio n s
. VBA
Com m ission.
A p p lic a t io n . M a c r o O p t io n s

M a c r o := " C o m m is s io n " , C a t e g o r y := " V B A "


M a cro O p tio n s
(Macro).

,
(Insert Function) :
(No help available).

.
1. VBE.
2. Excel, ,
.
3. 1
^ (Developer^Code^Macros)
<Alt+F8>.
,
.
4. (Macro Name).
5. (Options)
(Macro Options).
6. (Description) (. 10.9).
(Shortcut Key) .
7. (Cancel).

J jx j
(Insert Func
PERSONAL.XLSB!SortSheets
tion) ,
:
. 6 ( ).
CW+|
;
.
,

.

. ,
- . 10.12.
.

320

III. Visual Basic for Applications




. :
.
, Z ap S p aces;
M y fu n c s. xlsm .
( Myf u n c s . xlsm ), :
= M y fu n c s . x ls m ! Z a p S p a c e s (A l: C12)

Myf u n c s . x lsm
Excel, ,
:
= Z a p S p a c e s (A l: 12)


21.

, -
,
.
, ,
.

Windows API
VBA ,
Excel VB, DLL (Dynamic Link Library
), Windows .
VBA ,
.
Windows API (Application Programming Interface
) ,
Windows. Windows VBA Windows API.
Windows, Windows,
DLL, ,
, .
API- 64- Excel
VBA 64-
Excel 2010. 32-
( Excel 2007) 64- Excel 2010, API-
( ,
).

10.

321

, 32-
Excel, 64-
Excel 2010.
D e clare F u n c t i o n G e tW in d o w s D ir e c to r y A L i b " k e r n e l 3 2 " _
(B y V a l l p B u f f e r As S t r i n g , B y V a l n S iz e As L o n g ) As Long

64-
Excel P tr S a f
D e c l a r e . 32-
Excel 2010, 64- Excel 2010.
D eclare P t r S a f F u n c t i o n G e tW in d o w s D ir e c to r y A L i b " k e r n e l 3 2 "
(B y V a l l p B u f f e r As S t r i n g , B y V a l n S iz e As L o n g ) As Long

Excel 2007 ( )
, P trS a f .
26 API 32- Excel 64- Excel 2010.

Windows API
Windows API,
. VBA
(.. U s e rF o rm , ), API-
P r i v a t e .
API-
. VBA :
API- ;
API-;
API-.
API- VBA.

Windows
API-,
Windows ( VBA
). Excel 2007.
API-.
D eclare F u n c t io n G e t W in d o w s D ir e c to r y A L i b " k e r n e l 3 2 " _
(B yVal l p B u f f e r As S t r i n g , B y V a l n S iz e As L o n g ) As Lon g

, , ,
Windows ( VBA
). Windows
l p B u f f e r , n S iz e .
D e c la r e
G e tW in d o w s D ire c to ry A .
.
Sub Show W indow sD ir ()
Dim W in P a th As S t r i n g
Dim W in D ir As S t r i n g
11 3ak. 3107

255

322

III. Visual Basic for Applications

W in P a th = S p a c e (2 5 5 )
W in D ir = L e f t ( W i n P a t h , G e t W in d o w s D ir e c t o r y A _
(W in P a th , L e n ( W i n P a t h ) ) )
MsgBox W in D i r , v b l n f o r m a t i o n , " W indow s"
End Sub

ShowW indowsDir
Windows.
(wrapper) API-. ,
, API-.
API-.
VBA.
F u n c t i o n W in d o w s D ir O As S t r i n g
'
W indow s
D im W in P a th As S t r i n g * 2 5 5
W in P a th = S p a c e (2 5 5 )
W in d o w s D ir = L e f t ( W i n P a t h , G e t W in d o w s D ir e c to r y A _
(W in P a th , L e n ( W i n P a t h ) ) )
End F u n c t i o n

.
MsgBox W in d o w s D ir ()

.
= W in d o w s D ir ()

-
w in d o w s
-.

d i r e c t o r y .x ls m

API- ,
( ). Windows,
Excel VBA , .
, Windows API,
.

VBA Windows
API. .

<Shift>
. , VBA,
. ,
-,
<Shift>. <Shift>,
API- G e t K e y S t a t e . G e t K e y S t a t e ,
. , n V i r t K e y ,
.
, ,
B u t t o n _ C l i c k <Shift>. ,
<Shift> (

10.

323

), G e tKeyState. G e tK e y S t a te 0, ,
<Shift> ; <Shift> .
Declare F u n c t io n G e t K e y S t a t e L i b " u s e r 3 2 "
(ByVal n V i r t K e y As L o n g ) As I n t e g e r
Sub B u t t o n _ C lic k ()
Const V K _ S H IF T As I n t e g e r = &H10
I f G e tK e y S ta te (V K _ S H IF T ) < 0 T h e n
MsgBox " < S h i f t > "
E lse
MsgBox " < S h i f t > "

End I f
End Sub

-
k e y p r e s s . x ls m ,
-,
( ): <Ctrl>, <Shift> <Alt>.

Windows API
Windows API .
API-
. ,
, . VBA- Excel
API- .
,
.


11
Windows API.

-
- w i n 3 2 a p i . t x t ,
,
Windows API.
VBA.

...




VBA
VBA
Excel
Windows API

,
VB .


, ,
, .
VBA. , ,
, .
, VBA.
, Excel:
VB ;
VB ;
, VBA ;

326

III. Visual Basic for Applications

VBA;

Windows API.
.
, ,
.
, VB .
, , :

VBA;

, VBA;

, ;

Windows API.


, , , ..



VBA.


Excel
, , . ,
, ,
.
,
VBA-.
Sub M a c r o l ()
R an g e(" A l " ) . S e le c t
S e l e c t i o n . Copy
R a n g e (" B l" ).S e le c t
A c t i v e S h e e t . P a s te
A p p l i c a t i o n . C u tC opyM ode = F a l s e
End Sub


.
,
.

. , .
, .

11. VBA

327

, . VBA
.
, ,
S e l e c t .
, ,
.
Sub C o p yR a n g e()
R a n g e( " A l " ) . Copy R a n g e ( " B l ")
End Sub

,
.
, .
1 F i l e . x l s x 2 F i l e 2 .x l s x .
, ,
.
Sub CopyRange2 ( )
W orkbooks ( " F i l e l . x l s x " ) . S h e e ts ( " 1 11) . R ange ( " A l " ) .C o p y _
W o rk b o o k s ( " F i l e 2 . x l s x " ) . S h e e t s ( " 2 " ) . R a n g e ( " A l ")
End Sub


, .
Sub C o p yR a n g e3 ()
Dim R n g l As R a n g e , Rng2 As R ange
Set R n g l = W o r k b o o k s ( " F i l e l . x l s x " ) . S h e e t s ( " 1 " ) .R a n g e ( " A l " )
Set Rng2 = W o r k b o o k s ( " F i l e 2 . x l s x " ) . S h e e t s ( " 2 " ) .R a n g e ( " A l " )
R n g l. Copy Rng2
End Sub

, .
, . ,
(
).
Sub CopyRange4 ()
R ang e( " 1 : 8 0 0 " ) .C o p y R ange ( " D l " )
End Sub


VBA
(. ). ,
Cut. ,
.
18 (
1:6) , 1.
Sub M o v e R a n g e lO
Range (" A l : ") . C u t R ang e ( " H I " )
End Sub

III. Visual Basic for Applications

328


,
( ). ,
, .
.
. 11.1 .
, .
, ,
, .

21093

45

25375

49

26180

38

25564

32

29325

22

23069

23

24281

53

10
11
12

. 11.1.

, 1
2 ( 1). Current Region, Range,
( 1).
Sub C o p y C u r r e n t R e g io n 2 ()
R a n g e ( " A l " ) . C u r r e n t R e g i o n . Copy S h e e t s ( " 2 " ) . R a n g e ( " A l ")
End Sub

C u r r e n t R e g io n
^^ ^
(Hom e^ Editing^Find & S elect^ G o Special)
(Current Region).
<Ctrl+Shift+*>. ,
. ,
C u r r e n t R e g io n ,
.


, VBA,
,
.

11. VBA

329


.
.
,
. A c t i v a t e
W o r k s h e e ts .
.
,
.
VBA . ,
R ang e ( " T o t a l " ) , R ange ( "D 45 " ) .
45 .
, (D46).
,
, .
^ ^ (Developer^
Code^Use Relative References).
,
, ,
. ,
.
, (.
).
Excel . ,
, <Ctrl>, .

(. ).

C u r r e n tR e g io n (
), End Range. End ,
, . , ,
.
Range ( A c t i v e C e l l , A c t i v e C e l l . E n d ( x lD o w n ) ) . S e l e c t

,
: x lU p (), x l T o L e f t () x l T o R i g h t ().
JRb

End.
, End .

J^\

UgM

- (r a n g e

s e le c -

t i o n s . x ls m ),

. ,
(Selection Demo), ,
(. 11.2).

III. Visual Basic for Applications

330
[ ]a** 9 %
:

'

A ' * *
.


,
VBA

...
...

- 4 - -

...

15

16
jfjf

...
...
^ ...

21
22

...

( CtrlShift*Down)

Selection Demo

( Ctrl+Shift+Up}

89

78

92

74

{ Ctrl*Shift Right)
{ Ctrl *S M tt* Lett)
! Ctrl*Shift*)
! End, Home, Ctrl -Shift Home)

( Ctrl* Spacebar)

( Shift*Spacebar)
{ Ctrl*A)
34

35

. 11.2. ,
VBA


,
1 .
Sub GetValuelO
Range("Al").Value = InputBox(" ")
End Sub

. 11.3 .
.
(Cancel) , ,
.
(Cancel) .
Sub GetValue2()
Dim UserEntry As Variant
UserEntry = InputBox(" ")
If UserEntry <> "" Then Range("Al").Value = UserEntry
End Sub

,
. , 1 12.
, .
,
. ,
(Cancel).

11. VBA

331

Sub GetValue3 ()
Dim UserEntry As Variant
Dim Msg As String
Const MinVal As Integer = 1
Const MaxVal As Integer = 12
Msg = " " & MinVal & " " & MaxVal
Do
UserEntry = InputBox(Msg)
If UserEntry = "" Then Exit Sub
If IsNumeric(UserEntry) Then
If UserEntry >= MinVal And UserEntry <= MaxVal _
Then Exit Do
End If
Msg = " ."
Msg = Msg & vbNewLine
Msg = Msg Sc " " & _
MinVal Sc " " & MaxVal
Loop

ActiveSheet.Range("Al").Value = UserEntry
End Sub

. 11.4, ,
.
*1

M icro soft Excel


1 12
Cancel

. 11.3. InputBox
,

. 11.4. ,
, VBA
InputBox

-
Getvalue -
inputbox demo.xlsm.



.
, (. 11.5).
Sub G etD ata ()

Dim NextRow As Long


Dim Entryl As String, Entry2 As String
Do
'

NextRow = Cells(Rows.Count, 1).End(xlUp).Row + 1


1
Entryl = InputBox (" ")

If Entryl = "" Then Exit Sub


Entry2 = InputBox(" " )
If Entry2 = "" Then Exit Sub

332
'

III. Visual Basic for Applications


C e lls (N e x tR o w ,
C e lls (N e x tR o w ,
Loop
End Sub

1) = E n t r y l
2) = E n try 2

2
3
4
5
6
7
8
9
10

12
13

983
409
773

0
412
551
895
545
988
545
344

----- \
*j

M icrosoft Excel

------ ------

. 11.5.

, .
, . ( Cancel
()) E x i t Sub.
-
G etD ata -.
n e x t em pty c e l l . xlsm .

, NextRow.
, :
<End> <>.
. Row
; ( ),
1.
,
: ,
2. , .



.
, , ,
. Excel In p u tB o x .

Excel In p u tB o x VBA In p u tB o x .
, .

11. VBA

333

, , ,
.
.
Sub G etU serR ange()
Dim UserRange As Range
Prompt = " ."
T i t l e = " "
1
On E r r o r Resume N e xt
Set UserRange = A p p l i c a t i o n . I n p u t B o x ( _
P ro m p t:= P ro m p t, _
T it le : = T itle , _
D e f a u lt : = A c tiv e C e ll.A d d r e s s , _
T y p e :=8) '
On E r r o r GoTo 0
1 , ?
I f UserRange I s N o th in g Then
MsgBox " ."
Else

U serR ange. F o rm u la = " =RAND( ) "


End I f
End Sub

. 11.6.

. 11.6.

p ro m p t
-.

fo r

a ra n g e .x ls m


8. , On E r r o r Resume
Next. , ,
(Cancel). U s e rR a n g e
. .

III. Visual Basic for Applications

334

OK, . On
E r r o r Go .
. Excel
.

,
In p u tB o x .
, .
, ScreenU p d a tin g A p p lic a t io n .


, ,
C o u n t, ,
( ) . ,
, :
MsgBox S e l e c t i o n . C ount

Excel 2010 ,
C ount . C ount
Long, , ,
2147483647. , 2048
(2147483648 ), C ount . , Microsoft
, C o u n tL a rg e .
D ou ble ,
1,79+308.
C ount.
(,
), C o u n tL a rg e C ount.

d a ta ,
d a t a 11 C ount.
C e llC o u n t = R ange( " d a t a " ) . C ount

, .

:
S e l e c t i o n . C olu m n s. C ount


Rows.
d a t a R ow C ou nt.
RowCount = R an ge ( " d a t a " ) . Rows. C ount

11. VBA

335


Excel :
;
;
;
;
;
( ).
, VBA ,
- .
Range .
, , A re a s,
A re a s.
.
, ,
, :
NumAreas = S e le c t io n . A r e a s . C ount

NumAreas , ,
.
, ,
.
Function (RangeArea As Range) As S t r in g
'
S elect Case T ru e
Case R an ge A rea . C e l l s . C o u n tL a rg e = 1
= " "
Case R an ge A rea . C o u n tL a rg e = C e l l s . C o u n tL a rg e
= " "
Case R an ge A rea . Rows. C ount = C e l l s . Rows. C ount
= " "
Case R an ge A rea . C olu m n s. C ount = C e l l s . C olu m n s. C ount
= " "
Case E ls e
= " "
End S e le c t
End F u n ctio n

Range
, : (C e ll), (W orksheet),
(Column), (Row) (Block). S e l e c t
Case ,
True. , ,
. ,
.
, .
, .
C ase T rue, .

III. Visual Basic for Applications

336

,
C ount La . ,
C ount.
-
-
( a b o u t ra n g e s e le c t io n . x ls m ) .
(R a n g e D e s c rip tio n ),
, .
. 11.7 . ,
Range.

. 11.7. VBA

, , Excel
. , , <Ctrl>,
1 ,
. R a n g e D e s c rip tio n ,
.


,
, .
, .
C o lo r N e g a tiv e ,
. .

.
Excel.
Sub C o lo r N e g a tiv e ()
'

Dim c e l l As Range
I f T y p e N a m e (S e le c tio n ) <> "R ange" Then E x i t Sub

11. VBA
A p p lic a tio n .S c r e e n U p d a tin g = F a ls e
F o r Each c e l l I n S e le c tio n
I f c e ll . V a l u e < 0 Then
c e l l . I n t e r i o r . C o lo r = RGB(255,
E ls e
c e l l . I n t e r i o r . C o lo r = xlN o n e
End I f
N ext c e ll
End Sub

337

0,

0)

C o l o r N e g a t i v e , .
, , ?
? ? , ,
, .
( C o lo r N e g a t iv e 2 ) .
W o rkR a n g e R ange,
.
. 11.8 D, 1048576 .
, , 2:116.
D2:D16,
. , , 15 ,
, 1048576 .

. 11.8.


Sub C o lo rN e g a tive 2 ()
1

Dim WorkRange As Range


Dim c e l l As Range
I f T ype N am e(S e lectio n) <> "R ange" Then E x i t Sub
A p p lic a tio n . S c re e n U p d a tin g = F a ls e
Set WorkRange = A p p l i c a t i o n . I n t e r s e c t ( S e l e c t i o n ,
A ctive S h e e t.U se d R a n g e )
For Each c e l l I n WorkRange

338

III. Visual Basic for Applications


If

c e ll . V a l u e < 0 Then
c e l l . I n t e r i o r . C o lo r = RGB(255,
E ls e
c e l l . I n t e r i o r . C o lo r = x lN o n e
End I f
N e xt c e l l
End Sub

0,

0)

C o lo r N e g a t iv e 2
, ,
. , C o lo r N e g a t iv e 3 ,
, . S p e c i a l C e l l s ,
: ( C o n s t a n t C e l l s ) , ;
( F o r m u la C e lls ) , .
F o r E a c h -N e x t.
, ,
.
Sub C o lo r N e g a tiv e 3 ()
1

Dim F o rm u la C e lls As Range, C o n s ta n tC e lIs As Range


Dim c e l l As Range
I f T y p e N a m e (S e le c tio n ) <> "R ange" Then E x i t Sub
A p p l i c a t i o n . S c re e n U p d a tin g = F a ls e
'

On E r r o r Resume N e xt
S e t F o rm u la C e lls = S e l e c t i o n . S p e c ia lC e lls ( x lF o r m u la s , xlN u m b e rs)
S e t C o n s ta n tC e lls = S e l e c t i o n . S p e c ia lC e lls ( x lC o n s t a n t s , IN um bers)
On E r r o r GoTo 0
'

I f N ot F o rm u la C e lls I s N o th in g Then
F o r Each c e l l I n F o rm u la C e lls
I f c e ll . V a l u e < 0 Then
c e l l . I n t e r i o r . C o lo r = RGB(255,
E ls e
c e l l . I n t e r i o r . C o lo r = x lN o n e
End I f
N e xt c e l l
End I f
'

0,

0)

0,

0)

I f N o t C o n s ta n tC e lls I s N o th in g Then
F o r Each c e l l I n C o n s ta n tC e lls
I f c e ll . V a l u e < 0 Then
c e l l . I n t e r i o r . C o lo r = RGB(255,
E ls e
c e l l . I n t e r i o r . C o lo r = x lN o n e
End I f
N e xt c e l l
End I f
End Sub

On E r r o r , S p e c ia lC e lls
, .

11. VBA

339

, C o lo rN e g a tiv e ,
- e f f i c i e n t lo o p in g . xlsm .


.
, ,
,
UsedRange Worksheet.
Sub DeleteEmptyRows ()
Dim LastRow As Long
Dim r As Long
Dim C o u n te r As Long
A p p lic a tio n .S c r e e n U p d a tin g = F a ls e
LastRow = A c tiv e S h e e t.U s e d R a n g e . Rows. C ount + _
A c tiv e S h e e t.U s e d R a n g e .R o w s ( 1 ) .Row - 1
For r = LastR ow To 1 S te p -1
I f A p p lic a tio n .W o r k s h e e tF u n c tio n .C o u n tA ( R o w s ( r ) ) = 0 Then
R o w s ( r ) . D e le te
C o u n te r = C o u n te r + 1
End I f
Next r
A p p lic a tio n . S c re e n U p d a tin g = T ru e
MsgBox C o u n te r & " ."

End Sub


LastRow. , ,
1. , LastRow
:
1.
Excel (COUNTA), ,
. 0,
. ,
For-Next. ,
.
,
.
, Counter,
.
.
-

, ,
- d e le t e em pty ro w s . xlsm .


, ,
VBA . . 11.9 ,

340

III. Visual Basic for Applications

>

. .
, .
( (RAND)).
(
).
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15


0,276807291
1
2
0,730227266
1
0,946701186
5
0,015892566
3
0,678673514
1
0,554946703
1
0,467700824
2
0,830401846
0,822189002
1
10
0,371007999
2
0,918587635
0,172321775
1
2
0,909526052

. 11.9.

,
.
, , .
, .
Sub DupeRows()
Dim c e l l As Range
'

S e t c e l l = R ange(" 2 ")
Do W h ile N ot I s E m p t y ( c e ll)
I f c e l l > 1 Then
R a n g e ( c e l l . O f f s e t (1, 0 ) , c e l l . O f f s e t ( c e ll . V a l u e
0 ) ) . E n tir e R o w .I n s e r t
R a n g e ( c e ll, c e l l . O f f s e t ( c e ll . V a l u e - 1, _
1 ) ) . E n tir e R o w .F illD o w n
End I f
S e t c e l l = c e l l . O f f s e t ( c e l l . V a l u e , 0)
Loop
End Sub

- 1, _

c e l l 2, ,
. ,
F i l l D o w n .
c e l l , ,
, . . 11.10
.
-
, ,
- d u p lic a t e row s .x ls m .

341

11. VBA

,

In R a n g e , , , Range.
T ru e (), .
F un ctio n I n R a n g e ( r n g l , r n g 2 ) As B o o le a n
1 T r u e ,
rngl r n g 2
InR an ge = F a l s e
I f r n g l . P a r e n t . P a r e n t . Name =
rng2 . P a r e n t . P a r e n t . Name T h e n
I f r n g l . P a r e n t.N a m e =
rng2 . P a r e n t . Name T h e n
I f U n io n ( r n g l, r n g 2 ).A d d r e s s =
rng2 . A d d re s s T h e n
In R a n g e = T r u e
End I f
End I f
End I f
End F u n c tio n

, In R a n g e ,
,

.
,
P aren t, -
. ,
r n g l :
rn g l. P a r e n t . Name

..
1

1
.....2...................


0,811712817
0,408809459

0,817294658

0,965809492

0,777591092

0,704535562

0,566578818

0,560431236

10

0,849621677

11

0,349464908

12

0,347134158

13

0,33883254

14

0,519896123

15

0,956426929

16

0,108305391

1?
18

0,949941449

0,563116763

19
20
21
22
23
24

10

0,881752223

10

0,588564786

10

0,025840496

10

0,199440989

10

0,067126822

10

0,54658458

25
26

10

0,293597337

10

0,936284654

27

10

0,975085451

28

10

0,480195995

0,073935047

30

0,192292217

31

0,10695783

32

0,896294737

33

0,486119769

29

34.......................... ....................
r n g l :
. 11.10.
rn g l. P a r e n t . P a r e n t . Name

VBA U n io n R ange,

R ange. ,
. ,
.
-
, ,
- i n r a n g e f u n c t i o n . x ls m .


Excel ,
, . (ISTEXT),
(ISLOGICAL) (ISERROR). , VBA
IsEmpty, I s D a t e Is N u m e r ic .

342

III. Visual Basic for Applications

Cell Type, -
(, , , , , ),
.
VBA.
F u n c tio n C e llT y p e (R n g )
'
'

Dim T h e C e ll As Range
S e t T h e C e ll = R ng. R ange( " A l ")
S e le c t Case T ru e
Case Is E m p ty (T h e C e ll)
C e llT y p e = " "
Case A p p l i c a t i o n . Is T e x t( T h e C e ll)
C e llT y p e = " "
Case A p p l ic a t io n . I s L o g ic a l( T h e C e ll)
C e llT y p e = " "
Case A p p l i c a t i o n . I s E r r ( T h e C e ll)
C e llT y p e = " E r r o r "
Case Is D a te ( T h e C e ll)
C e llT y p e = " "
Case I n S t r ( l , T h e C e ll. T e x t , " : " ) <> 0
C e llT y p e = ""
Case Is N u m e ric ( T h e C e ll)
C e llT y p e = " "
End S e le c t
End F u n c tio n

Set TheCell. CellType


- , ,
(
TheCell).
-
, ,
- c e l l t y p e f u n c t i o n . xlsm .


, ,
. , Excel
, .
WriteReadRange .
For-Next
. Timer
, .
Sub W rite R e a d R a n g e ()
Dim M y A rra y ()
Dim T im e l As D ou ble
Dim NumElements As Long, i As Long
Dim W rite T im e As S t r i n g , ReadTime As S t r in g
Dim Msg As S t r i n g
NumElements = 60000
ReDim M y A rra y (1 To NumElements)

11. VBA

343

1
For i = 1 NumElements

M y A rra y ( i ) = i
Next i
'

Tim el = T im e r
For i = 1 To NumElements
C e lls ( i , 1) = M y A r r a y ( i)
Next i
W riteTim e = F o rm a t(T im e r - T im e l,
'

" 0 0 :0 0 " )

Timel = T im e r
For i = 1 To NumElements
M y A rra y (i) = C e lls ( i , 1)
Next i
ReadTime = F o rm a t(T im e r - T im e l,

" 0 0 :0 0 " )

1
Msg = " : " & W rite T im e

Msg = Msg & v b C rL f


Msg = Msg & " : " & ReadTime
MsgBox Msg, vbO KO nly, NumElements & " "
End Sub

60
58, 1 , .



F o r-N e x t.
.
,
( ) .
F o r-N e x t.
Sub L oopF illR ange ()
'

Dim
Dim
Dim
Dim
'

CellsDown As Long, C e lls A c r o s s As I n t e g e r


CurrRow As Long, C u rrC o l As I n t e g e r
S ta rtT im e As D ou ble
C urrV al As Long

CellsDown = In p u tB o x ( " ? ")


I f CellsDown = 0 Then E x i t Sub
C ellsAcross = In p u tB o x ( " ? ")
I f C e lls A c ro s s = 0 Then E x i t Sub

.
i

StartTime = T im e r
: 1

CurrVal = 1
A p p lic a tio n . S c re e n U p d a tin g = F a ls e
For CurrRow = 1 To C ellsD ow n

344

III. Visual Basic for Applications


F o r C u rrC o l = 1 To C e lls A c r o s s
A c t i v e C e l l . O ffs e t(C u rrR o w - 1, _
C u rrC o l - 1 ) .V a lu e = C u rrV a l
C u rrV a l = C u rrV a l + 1
N e x t C u rrC o l
N e x t CurrRow

'


A p p lic a tio n .S c r e e n U p d a tin g = T ru e
MsgBox F o rm a t(T im e r - S ta r tT im e , " 0 0 .0 0 " )
End Sub

& " "


.
.
Sub A r r a y F illR a n g e ()
'

Dim C e llsD o w n As Long, C e lls A c r o s s As I n t e g e r
Dim i As Long, j As I n t e g e r
Dim S ta r tT im e As D ou ble
Dim T e m p A rra y () As Long
Dim TheRange As Range
Dim C u rrV a l As Long
1
C e llsD o w n = In p u tB o x ( " ? ")
I f C e llsD o w n = 0 Then E x i t Sub
C e lls A c r o s s = In p u tB o x ( " ?")
I f C e lls A c r o s s = 0 Then E x i t Sub
'

S ta r tT im e = T im e r
'

ReDim T e m p A rra y (1 C e llsD o w n , 1 C e lls A c r o s s )
'

S e t TheRange = A c t iv e C e ll. R a n g e ( C e lls (1, 1 ) , _
C e lls (C e lls D o w n , C e lls A c r o s s ) )
'

C u rrV a l = 0
A p p l i c a t i o n . S c re e n U p d a tin g = F a ls e
F o r i = 1 To C e llsD o w n
F o r j = 1 To C e lls A c r o s s
T e m p A rra y ( i , j ) = C u rrV a l + 1
C u rrV a l = C u rrV a l + 1
N e xt j
N ext i
'

T he R an ge .V alue = Tem pA rray
'

A p p lic a tio n .S c r e e n U p d a tin g = T ru e
MsgBox F o rm a t(T im e r - S ta r tT im e , " 0 0 .0 0 " ) & " "
End Sub

, 1000x250 (250
) 10,05 .
0,18 50
! ? Excel,
.

11. VBA

345

.

,
.

-
, W riteR eadR ange, L o o p F illR a n g e
A r r a y F illR a n g e , - lo o p
vs a r r a y f i l l ra n g e .x ls m .


,
(
).
, ..
.
, .
Excel (TRANSPOSE). 100-
(1:100).
Range(" 1 : 1 0 0 ") .V a lu e = _
A p p lic a t io n . W o rk s h e e tF u n c tio n . T ra n sp o s e (M yA rray)

Excel ,
65536 .

variant
Excel VB.
, , V a r i ant. .
Sub R angeToV ariant ()
Dim As V a r ia n t
x = Range ("A 1 :L 6 0 0 ") .V a lu e
MsgBox U Bound(x, 1)
MsgBox U Bound(x, 2)
End Sub

60 0 (
), 12 ( ). ,
V a r i a n t .
V a r i a n t ,

.
Sub R angeToV ariant2 ()
Dim As V a r ia n t
Dim r As Long, As I n t e g e r
1

346

III. Visual Basic for Applications

x = R ange( " d a t a " ) .V a lu e


F o r r = 1 To U B o u n d (x/ 1)
F o r = 1 To U B ound(x, 2)
'
2
x ( r , ) = x ( , ) * 2
N ext
N ext
'
V a r ia n t
R ange( " d a t a " ) =
End Sub

.
-
, , - v a r i a n t t r a n s f e r . xlsm .


.
, Excel .
S e le c tB y V a lu e .
,
.
Sub S e le c tB y V a lu e ()
Dim C e ll As O b je c t
Dim F o u n d C e lls As Range
Dim WorkRange As Range
If
1

T y p e N a m e (S e le c tio n )

<> "R ange" Then E x i t Sub

?
I f S e l e c t i o n . C o u n tL a rg e = 1 Then
S e t WorkRange = A c tiv e S h e e t.U s e d R a n g e
E ls e
S e t WorkRange = A p p l i c a t i o n . I n t e r s e c t ( S e l e c t i o n ,
A c tiv e S h e e t.U s e d R a n g e )
End I f


On E r r o r Resume N e xt
S e t WorkRange = W orkRange. S p e c ia lC e lls ( x lC o n s t a n t s , x lN u m b e rs)
I f WorkRange I s N o th in g Then E x i t Sub
On E r r o r GoTo 0

1
'

, F o u n d C e lls ,

F o r Each C e ll I n WorkRange
I f C e ll. V a lu e < 0 Then
I f F o u n d C e lls I s N o th in g Then
S e t F o u n d C e lls = C e ll
E ls e
S e t F o u n d C e lls = U n io n ( F o u n d C e lls , C e ll)
End I f

11. VBA

347

End I f
Next C e ll
'
I f F o u n d C e lls I s N o th in g Then
MsgBox "He , ."
Else
F o u n d C e lls . S e le c t
End I f
End Sub

. ,
.
, .
S p e c i a l C e l l s ,
Range, .
F o r-N e x t .
( 0), F o u n d C e lls Range
Union. , U nion .
F o u n d C e lls , U nion
. ,
FoundCells N o th in g .
F o u n d C e lls ,
( N o th in g , ).
, . .
-
s e le c t b y v a lu e .x ls m .


(, , )
, , Excel
.
(That command cannot be
used on multiple selections).
, Excel ,
. VBA,
.
Sub C o p y M u ltip le S e le c tio n ()
Dim SelAreas () As Range
Dim PasteRange As Range
Dim U p p e rL e ft As Range
Dim NumAreas As Long, i As Long
Dim TopRow As Long, L e f t C o l As Long
Dim R owOffset As Long, C o lO f fs e t As Long
I f TypeName ( S e le c tio n )

<> "Range" Then E x i t Sub

1 Range
NumAreas = S e le c tio n .A re a s . C ount
ReDim S e lA re a s (1 To NumAreas)

III. Visual Basic for Applications

348

'

'

1
'

F o r i = 1 To NumAreas
S e t S e lA r e a s ( i) = S e le c t io n . A r e a s ( i)
N e xt

TopRow = A c t iv e S h e e t. Rows. C ount
L e ft C o l = A c t iv e S h e e t. C olu m n s. C ount
F o r i = 1 To NumAreas
I f S e lA r e a s ( i) .R o w < TopRow Then TopRow = S e lA r e a s ( i) .R o w
I f S e lA r e a s ( i) .C o lu m n < L e ft C o l Then L e ft C o l = S e lA re a s _
( i) .C o lu m n
N e xt
S e t U p p e r L e ft = C e lls (T o p R o w , L e ft C o l)

On E r r o r Resume N e x tS e t PasteRange = A p p l i c a t i o n . In p u tB o x _
(P ro m p t: = " _
:" , T i t l e : = " _
" , :=8)
On E r r o r GoTo

I f TypeNam e(PasteRange) <> "R ange" Then E x i t Sub
,
S e t PasteRange = P a ste R a n g e . R ange( " A l ")


F o r i = 1 NumAreas
R o w O ffs e t = S e lA r e a s ( i) .R o w - TopRow
C o lO f fs e t = S e l A r e a s ( i ) . Column - L e ft C o l
S e l A r e a s ( i ) . Copy P a ste R a n g e . O ff s e t( R o w O f fs e t, C o lO ffs e t)
N e xt i
End Sub

. 11.11 .
-
-
, ,
.
m u l t i p l e s e le c t io n . x ls m .



VB .



W orkbooks , .
P u b lic Sub S a v e A llW o rk b o o k s ()
Dim Book As W orkbook
F o r Each Book I n W orkbooks
I f B o o k .P a th <> " " Then B ook.S ave

11. VBA

349

N e x t B ook
End Sub

, P a th . -
P a th , , (
).
, P a th .

. 11.11. Excel InputBox


W o rk b o o k s .
.
Sub C lo se A llW o rkb o o ks ()
Dim Book As W orkbook
For Each Book I n W orkbooks
I f Book.Name <> T h is W o rk b o o k . Name Then
B o o k .C lo s e s a v e c h a n g e s : =True
End I f Next Book
ThisW orkbook. C lo se savechanges : =True
End Sub

, I f , ,
. ,
, ,
, .

350

III. Visual Basic for Applications



, .
. 11.12.
1____ |_____ i__
'

1 8

_________ ___

14 <

] ! / 7

. 11.12. ( G8:K17)
Sub H ideR ow sAndC olum ns()
Dim r o w l As Long, row2 As Long
Dim c o l l As Long, c o l2 As Long
If
1

T ype N a m e -(S e le ctio n )

<> "R ange" Then E x i t Sub

If

R o w s (R o w s .C o u n t).E n tire R o w .H id d e n Or _
C o lu m n s(C o lu m n s. C o u n t) . E n tir e C o lu m n . H id d e n Then
C e l l s . E n tire C o lu m n .H id d e n = F a ls e
C e l l s . E n tire R o w .H id d e n = F a ls e
E x i t Sub
End I f
r o w l = S e le c tio n .R o w s ( 1 ) .Row
row2 = r o w l + S e le c tio n .R o w s . C ount - 1
c o l l = S e le c tio n .C o lu m n s ( 1 ) . C olu m n col2 = c o l l + _
S e le c tio n .C o lu m n s . C ount - 1
A p p lic a tio n .S c r e e n U p d a tin g = F a ls e
On E r r o r Resume N e xt
1

R a n g e ( C e lls (1 , 1 ) , C e lls ( r o w l - 1, 1 ) ) . E n tire R o w .H id d e n = T ru e


R a n g e (C e lls (ro w 2 + 1, 1 ) , C e lls (R o w s . C o u n t, _
1 ) ) . E n tire R o w .H id d e n = T ru e
1

R a n g e ( C e lls (1 , 1 ) , C e l l s ( l , c o l l - 1 ) ) .E n tire C o lu m n .H id d e n = _
T ru e
R a n g e ( C e lls (1, c o l2 + 1 ) , C e l l s ( l , C olum ns. _
C o u n t) ) .E n tire C o lu m n .H id d e n = T ru e
End Sub

11. VBA

351

, A re a
.
-
, ,
- h id e row s and c o lu m n s .x ls m .


, , ,
, , Excel .
, ,
. VBA,
,
:
, ;
, .
.
Sub S yn ch S h e e ts()
1
'

I f T y p e N a m e (A c tiv e S h e e t) <> "W o rk s h e e t" Then E x i t Sub


Dim U se rS h e e t As W o rk s h e e t, s h t As W o rkshe et
Dim TopRow As Long, L e f t C o l As I n t e g e r
Dim U s e rS e l As S t r in g
A p p lic a tio n .S c r e e n U p d a tin g = F a ls e
'

Set U se rS h e e t = A c tiv e S h e e t
'

TopRow = A c tiv e W in d o w . S c ro llR o w


L e ftC o l = A c tiv e W in d o w .S c ro llC o lu m n
U serS el = A c tiv e W in d o w . R a n g e S e le c tio n .A d d re s s
'

For Each s h t I n A c tiv e W o rk b o o k . W o rksh e e ts


I f s h t . V i s i b l e Then '
s h t . A c t iv a t e
R a n g e ( U s e rS e l) .S e le c t
A c tiv e W in d o w .S c ro llR o w = TopRow
A c tiv e W in d o w .S c ro llC o lu m n = L e ft C o l
End I f
Next s h t
1

U s e r S h e e t.A c tiv a te
A p p lic a tio n .S c r e e n U p d a tin g = T ru e

End Sub

-

- s y n c h r o n iz e s h e e ts . x ls m .

352

III. Visual Basic for Applications

VBA
VBA,
.


, :
T r u e () F a ls e ().
N o t, ,
W ra p T e x t .
Sub T o g g le W ra p T e x t()
1
I f T y p e N a m e (S e le c tio n ) = "R ange" Then
S e l e c t i o n . W rapText = N o t A c t i v e C e l l . W rapText
End I f
End Sub

, .
(,
, ), , Excel
. , ,
,
.
Excel.
TypeN am e, ,
. , .
N o t .
,
.
A c tiv e W in d o w . D is p la y H e a d in g s = N ot _
A c tiv e W in d o w . D is p la y H e a d in g s

.
A c t iv e W in d o w .D is p la y G r id lin e s = N ot _
A c tiv e W in d o w . D is p la y G r id lin e s


,
Excel (Print Preview),
.
VBA,
.
Sub P a g e C o u n t()
MsgBox ( A c tiv e S h e e t. H P a ge B rea ks. C ount + 1 ) * _
( A c tiv e S h e e t. V P a g e B re a ks. C ount + 1 ) & " "
End Sub

VBA
(. 11.13).

11. VBA
Sub ShowPageCount()
Dim PageCount As I n t e g e r
Dim s h t As W o rkshe et
PageCount = 0
For Each s h t I n W o rksh e e ts
PageCount = PageCount + ( s h t . H P ageB reaks. C ount + 1 )
(s h t.V P a g e B re a k s . C ount + 1)
Next s h t
MsgBox " = " & PageCount
End Sub

353

* _

-
, ,
- page c o u n t . x ls m .


, Excel
,
VB .
D a te A n d T im e
(. 11.14).
.

. 11.13.
VBA

. 11.14.

F o r m a t D a te .
.
.
Sub DateAndTime ()
Dim TheD ate As S t r i n g , TheTime As S t r in g
Dim G r e e tin g As S t r in g
Dim FullN am e As S t r i n g , F irs tN a m e As S t r in g
Dim SpaceInName As Long
TheDate = F o rm a t(D a te , "L on g D a te ")
TheTime = F o rm a t(T im e , "M edium T im e ")
1

S e le c t Case Time
Case I s < T im e V a lu e ( " 1 2 : 0 0 " ) : G r e e tin g = " , "
Case I s >= T im e V a lu e ( " 1 7 : 0 0 " ) : G r e e tin g = " , "
Case E ls e : G r e e tin g = " , "
End S e le c t
1

FullName = A p p lic a tio n .U s e rN a m e


SpacelnName = I n S t r ( l , F u llN a m e ,

123ak. 3107

" ",

1)

354
'

III. Visual Basic for Applications


,

I f SpacelnName = 0 Then SpacelnName = L e n (F u llN a m e )


F irs tN a m e = L e ft( F u llN a m e , SpacelnName)
G r e e tin g = G r e e tin g & F irs tN a m e
'

MsgBox TheD ate & v b C rL f & v b C rL f & " " & TheTim e, vbOKOnly,
G r e e tin g
End Sub

(Long Date Medium


Time)
. . ,
/ / , :
TheD ate = F o rm a t(D a te ,

" / / " )

,
S e l e c t Case. VBA ,
Excel. 0,5 (), . 0,7083 (5
), . .
VBA T im e V a lu e , .
,
(General) Excel (Excel Options).
VBA I n S t r .
, ,
. ,
N o b o d y , , ,
, . ( ,
, Excel User.)
: SpacelnN am e
, L e f t .
M sgB ox ,
v b C r L f . v b O K O n ly
, 0; .
G r e e t i n g , .
-
D ateAndTim e d a te and tim e . xlsm .


,
, Excel .
, Excel 2010
CommandBar.
Excel, Excel 2007.
S h o w I n s t a lle d F o n t s
.
( Com m andBar), F o n t,
. .

11. VBA

355

Sub S h o w In s ta lle d F o n ts ()
Dim F o n t L is t As C om m andBarControl
Dim TempBar As CommandBar
Dim i As Long
1 CommandBar
Set TempBar = A p p l i c a t i o n . CommandBars.Add
Set F o n t L is t = Tem pBar. C o n tr o ls .A d d ( I D :=172 8)
1
Range( " : " ) . C le a rC o n te n ts
For i = 0 F o n t L i s t . L is tC o u n t - 1
C e lls ( i + 1, 1) = F o n t L i s t . L i s t ( i + 1)
Next i
'

CommandBar
TempBar. D e le te

End Sub


(. 11.15). F o r-N e x t
:
C e l l s ( i + 1 , 1 ) . Font.N am e = F o n t L i s t . L i s t ( i + 1 )
,
.

H 1

385 Century Schoolbook


386 Chaparral Pro
387 C H A R L E M A G N E STD I
388 G|Mbr
389 C olonna MT
390 Comic Sans MS
391 !
392 C onsolas
393 Constantia
394 C w p w B lac k
395 C ooper S t d B la c k
396 C

o pperpla te

G o t h ic B o l d

397 C o p p e r p l a t e G o t h i c L ig h t
398 Corbel
399

C o u r ie r

400

C o u r ie r

New

401 Curb: K f
402 btSb
403 )
404
405 E le p h a n t
406 E N G R A V E R S M T
407 Eptil Obt
408 Eras B old
409 Eras Demi
410 Eras Light
411 Eras Medium ITC

. 11.15.

..........T"

III. Visual Basic for Applications

356

-
l i s t fo n t s .x ls m .


Excel , VBA
. ,
,
Excel .
,
VBA .
.

. Excel;
.
.

. (

9). ,
,
.

. ,

, , , .
I n t e g e r L o n g .

. ,

. ,
I n t e g e r L o n g .
-
- ( s o r t in g demo. xlsm),
.
.

. 11.16
.
.
( 100 100

);
F? 00,50 .
( L o n g ).
R . *3/20 ,
. 11.1 ,
W 00,05 .
.

00,05 .
0,00 ,
- : | <0
0,01 .

, ,
. 11.16. , ,
.

*I

357

11. VBA

11.1. ( ) ,

VBA

VBA


VBA

100
500
1000
5000
10000
50000
100000

0,03
0,05
0,09
0,27
0,52
2,41
4,77

0,00
0,03
0,14
3,28
13,05
317,20
3204,30

0,00
0,00
0,02
0,03
0,06
0,31
0,70

0,03
0,03
0,03
0,03
0,05
0,11
0,19


, ( 10
).
, I n t e g e r Long.



. ,
, . ,
,
.

, .
Sub B a tch P ro ce ss ()
Dim F ile S p e c As S t r in g
Dim i As I n t e g e r
Dim F ileN am e As S t r in g
Dim F i l e L i s t O As S t r i n g
Dim F o u n d F ile s As I n t e g e r
'
F ile S p e c = T h is W o rk b o o k . P a th & " \ " & " t e x t ? ? . t x t "
FileName = D ir ( F ile S p e c )
1 ?
I f FileN am e <> " " Then
F o u n d F ile s = 1
ReDim P re s e rv e F i l e L i s t ( l To F o u n d F ile s )
F ile L is t ( F o u n d F ile s ) = F ileN am e
Else
MsgBox "He " & F ile S p e c
E x it Sub
End I f
1
Do
FileN am e = D i r
I f F ileN am e = " " Then E x i t Do

III. Visual Basic for Applications

358

F o u n d F ile s = F o u n d F ile s + 1
ReDim P re s e rv e F i l e L i s t ( l To F o u n d F ile s )
F ile L is t ( F o u n d F ile s ) = F ileN am e & " * "
Loop
'


F o r i = 1 F o u n d F ile s
C a ll P r o c e s s F i l e s ( F i l e L i s t ( i ) )
N ext i
End Sub

-
b a tc h p r o c e s s in g .x ls m
-.
t e x t O l . t x t , te x t0 2 . t x t te x t0 3 . t x t .

,
. F ou nd
F i l e s , F o r - N e x t .
P r o c e s s F i le s , .
O p e n T e x t .
, ,
.
Sub P r o c e s s F ile s (F ile N a m e As S t r in g )
'
W o rkb o o ks. O penText F ile N a m e : = F ile N a m e , _
O r i g i n : = x lW in d o w s , _
S ta r tR o w := l, _
D a ta T y p e : = x lF ix e d W id th / _
F ie ld In fo := _
A r r a y ( A r r a y (0, 1 ) , A r r a y (3, 1 ) , A r r a y (12, 1 ))
'

R a n g e ( " D l" ) .V a lu e = "A "
R a n g e ("D 2 " ).V a lu e = "B "
R a n g e ("D 3 " ).V a lu e = "C"
R ange( " E l:E 3 " ) .F o r m u la = "=COUNTIF( : B , D l ) "
R ange( " F I:F 3 " ) .F o r m u la = "=SU M IF( : B , D l #: ) "
End Sub


VBA
27.

VBA
,
.
, V B A .
, P r i v a t e
Excel (Insert Function).

11. VBA

359

-
, ,
- VBA u t i l i t y f u n c t io n s .x ls m .

FileExists
( ) ,
.
P riv a te F u n c tio n F ile E x is ts ( fn a m e )
'

F ile E x is t s
End F u n c tio n

As B o o le a n

= (D ir(fn a m e )

<> " " )

FileNameOnly
( ) .
, .
P riva te F u n c tio n F ile N am eO nly(pn am e) As S t r in g
'

Dim temp As V a r ia n t
le n g th = Len(pname)
temp = S p lit( p n a m e , A p p l i c a t i o n . P a th S e p a ra to r)
F ileN am eO nly = te m p (U B o u n d (te m p ))
End F u n c tio n

VBA S p l i t , ( -) v a r i a n t , ,
-. tem p
, A p p l i c a t i o n .P a t h S e p a ra te r ( ).
S p l i t .
: \ e x c e l f i le s \2 0 1 0 \b a c k u p \b u d g e t .x ls x ,
b u d g e t . x l s x .
F ileN am eO n ly (
). ,
.
P rivate F u n c tio n F ile N am eO nly2(p na m e ) As S t r in g
FileN am eO nly2 = D ir(p n a m e )
End F u n c tio n

PathExists
() , .
P rivate F u n c tio n P a th E x is ts (p n a m e ) As B o o le a n
'

I f D ir(p n a m e , v b D ir e c to r y ) = " " Then


P a th E x is ts = F a ls e
Else
P a th E x is ts = (G e tA ttr(p n a m e ) And v b D ir e c to r y )
End I f
End F u n c tio n

= v b D ir e c t o r y

III. Visual Basic for Applications

360

RangeNameExists
( ) ,
.
P r iv a t e F u n c tio n R angeN am eE xists(nnam e) As B o o le a n
'

Dim n As Name
R angeN am eE xists = F a ls e
F o r Each n I n A ctive W o rkb o o k.N a m e s
I f UCase(n.Name) = UCase(nname) Then
R angeN am eExists = T ru e
E x i t F u n c tio n
End I f
N ext n
End F u n c tio n

.
, . , .
P r iv a t e F u n c tio n R angeN am eE xists2(nnam e) As B o o le a n
'

Dim n As Range
On E r r o r Resume N e xt
S e t n = Range(nname)
I f E rr.N u m b e r = 0 Then R angeN am eExists2 = T ru e _
E ls e R angeN am eE xists2 = F a ls e
End F u n c tio n

SheetExists
( ) ,
.
P r iv a t e F u n c tio n S h e e tE x is ts (s n a m e ) As B o o le a n
'
1

Dim As O b je c t
On E r r o r Resume N e xt
S e t x = A c tiv e W o rk b o o k . S hee ts(sna m e)
I f E rr.N u m b e r = 0 Then S h e e tE x is ts = T ru e _
E ls e S h e e tE x is ts = F a ls e
End F u n c tio n

WorkbooklsOpen
( ) ,
.
P r iv a t e F u n c tio n W orkbooklsO pen(w bnam e) As B o o le a n
'

Dim As W orkbook
On E r r o r Resume N e xt
S e t x = W orkbooks(wbnam e)
I f E rr.N u m b e r = 0 Then W orkbooklsO pen = T ru e _
E ls e W orkbooklsO pen = F a ls e
End F u n c tio n

11. VBA

361


,
, .
P riv a te F u n c tio n I s I n C o l l e c t io n ( C o i n As O b je c t, _
Ite m As S t r in g ) As B o o le a n
Dim Obj As O b je c t
On E r r o r Resume N e xt
Set Obj = C o in (Ite m )
I s I n C o l l e c t io n = N o t Obj I s N o th in g
End F u n c tio n
: () (),
.
, . ,
T ru e ; F a ls e .
I s I n C o l l e c t i o n ,
: R angeN am eExists, S h e e tE x is ts W orkbooklsO pen.
, D ata,
I s I n C o l l e c t io n :
MsgBox Is In C o lle c tio n ( A c tiv e W o r k b o o k .N a m e s , "D a ta ")
, B udget,
:
MsgBox Is In C o lle c t io n ( W o r k b o o k s , " b u d g e t. x l s x " )
, 1,
:
MsgBox Is I n C o lle c t io n ( A c t iv e W o r k b o o k . W o rk s h e e ts , " 1 ")


VBA .
,
Excel. VBA (G etV alu e,
), .
XLM,
Excel ( 5), .
P rivate F u n c tio n G e tV a lu e (p a th , f i l e , s h e e t, r e f )
1
Dim a rg As S t r i n g
1
I f R ig h t( p a th , 1) <> " \ " Then p a th = p a th & " \ "
I f D ir ( p a t h & f i l e ) = " " Then
G e tV a lue = " "
E x it F u n c tio n
End I f
1
arg =
& p a th & " [" & f i l e & "] " & s h e e t & " 1 ! "
R a n g e ( re f) . R ange( " A l " ) .A d d re s s (, , x lR lC l)
1 XLM
GetValue = E x e c u te E x c e l4 M a c ro (a rg )
End F u n c tio n

&

III. Visual Basic for Applications

362

G et V a lu e :

p a t h (, " d : \ f i l e s " ) ;

f i l e (, " b u d g e t .x l s " ) ;

s h e e t (, " 1 ");

r e f (, " 4).
, G e tV a lu e.
1 1 2 010B udget .x l s x
( X L F ile s \B u d g e t :).
Sub T e s tG e tV a lu e ()
Dim As S t r i n g ,
f As S t r in g
Dim s As S t r i n g ,
a As S t r in g
p = " c : \ X L F ile s \ B u d g e t "
f = " 2 0 1 0 b u d g e t.x ls x "
s = "JIh c tI"
a = " A l"
MsgBox G e tV a lu e (p , f , s, a)
End Sub

. 1200 (100
12 ) .
Sub T e s tG e tV a lu e 2 ()
Dim As S t r i n g ,
f As S t r in g
Dim s As S t r i n g ,
a As S t r in g
Dim r As Long, As Long
p = " c : \ X L F ile s \ B u d g e t "
f = "2 0 1 0 B u d g e t.x ls x "
s = " 1 "
A p p l i c a t i o n . S c re e n U p d a tin g = F a ls e
F o r r = 1 To 100
F o r = 1 To 12
a = C e l l s ( r , c ) .A d d r e s s
C e l l s ( r , c) = G e tV a lu e (p , f , s , a)
N ext
N e xt r
End Sub

(3 )

G e tV a lu e ,
. ,
.

-

- v a lu e fro m a c lo s e d w orkb o o k .x ls m .
m yw o rkbo ok. x ls x .

Excel
, , ,
. ,
VBA,
(ThisWorkbook), (UserForm).

11. VBA

363

-
w o rk s h e e t f u n c t io n s . xlsm .


,
.
(, , ,
, ).

,

Excel.
( ), <Ctrl+Alt+F9>.
:
A p p lic a tio n .V o la tile

<F9>.

, ,
, . ,
.
Function I s B o l d ( c e l l )

As B o o le a n

1 ,

IsB o ld = c e ll. R a n g e ( " A l " ) . F o n t.B o ld


End F u n c tio n

,
( ). Excel 2010
D i s p l a y F o rm a t.
. I s B o l d ,
, .
Function I s B o l d ( c e ll )

As B o o le a n

IsB o ld = c e ll. R a n g e ( " A l " ) . D is p la y F o r m a t. F o n t.B o ld


End F u n c tio n

,
.
Function I s l t a l i c ( c e l l )
1 ,

As B o o le a n

I s l t a l i c = c e l l . R an ge ( " A l " ) . F o n t. I t a l i c
End F u n c tio n

,
(,
). , , ,
.
Function A llB o ld ( c e l l )
'

As B o o le a n

364

III. Visual Basic for Applications

'


I f I s N u l l ( c e l l . F o n t. B o ld ) Then
A l l B o l d = F a ls e
E ls e
A l l B o l d = c e l l . F o n t.B o ld
End I f
End F u n c tio n

AllBold .
F u n c tio n A l l B o l d ( c e l l ) As B o o le a n
1 ,
'

A ll B o l d = N o t I s N u l l ( c e l l . F o n t. B o ld )
End F u n c tio n

Fill Color, , ,
( ).
, 4142.

( ^^ (Insert^Tables1^
Table)) . DisplayFormat, .
F u n c tio n F i l l C o l o r ( c e l l ) As I n t e g e r
'
,
'

F i l l C o l o r = c e ll. R a n g e ( " A l " ) . I n t e r i o r . C o lo r ln d e x
End F u n c tio n


Say I t Excel ,
.
F u n c tio n S a y l t ( t x t )
A p p lic a tio n .S p e e c h .S p e a k
S a y lt = t x t
End F u n c tio n

(tx t)

,
. , :
= IF (SUM (: ) >25000, S a y lt ( " " ) )

25000,
, , . Speak
,
.



Excel ,
Bui It inDocument Properties Work
book. .
F u n c tio n L a s tS a v e d O
A p p lic a tio n .V o la tile
L a s tS a v e d = T h is W o rk b o o k .

11. VBA

365

B u iItin D o c u m e n tP r o p e r tie s ( " ")


End F u n c tio n

, ,
, (Related Dates)
Backstage. 1^
(File^Info). ,
A u to S a v e .
.
,

. ,
#.
F unction L a s t P r i n t e d ()
A p p lic a tio n .V o la tile
L a s tP r in te d = T h is W o rk b o o k . _
B u ilt in D o c u m e n tP r o p e r tie s ( " " )
End F u n c tio n


( <F9>), .

, Excel .
, Number o f B y te s ,
, .
.

l a s t S a v e l a s t P r i n t e d
, .
, (, p e r s o n a l . x l s b ) ,
, .
(ThisWorkbook), .
.
A p p l i c a t i o n . C a l l e r , Range.
, . P a r e n t . P a r e n t
( R ange W o rk b o o k ).
.
Function L a s tS a v e d 2 ()
A p p lic a tio n .V o la tile
LastSaved2 = A p p l i c a t i o n . C a l l e r . P a r e n t. P a r e n t. _
B u ilt in D o c u m e n tP r o p e r tie s ( " " )
End F u n c tio n


Excel :
. A p p l i c a
tio n . Excel , , ,
.. ,
R ange.

366

III. Visual Basic for Applications

A p p l i c a t i o n
W orkbook
W o rkshe et
Range

- Range
() Worksheet ( ), .
Worksheet Workbook ( ),
, Workbook Application
(, .. Excel).
? VBA
SheetName, . ()
, .
Parent Range. Parent ,
, Range.
F u n c tio n S h e e tN a m e (re f) As S t r i n g
SheetName = r e f . P a rent.N am e
End F u n c tio n

WorkbookName
. , Parent .
Parent Worksheet, Parent
Workbook.
F u n c tio n W o rkb o o kN a m e (re f) As S t r in g
WorkbookName = r e f . P a r e n t. P a r e n t. Name
End F u n c tio n

AppName, ,
, Parent .
Application .
Microsoft Excel.
F u n c tio n A p pN a m e (re f) As S t r in g
AppName = r e f . P a r e n t. P a r e n t. P a r e n t. Name
End F u n c tio n


CountBetween (
), , .
F u n c tio n C o u n tB e tw e e n (In R a n g e , n u m l, num2)
'

W ith A p p lic a tio n .W o r k s h e e tF u n c tio n
I f num l <= num2 Then
C ountBetw een = . C o u n t I f ( In R a n g e ,
. C o u n t I f ( In R a n g e , "> " & num2)
E ls e
C ountB etw een = . C o u n t I f ( In R a n g e ,
. C o u n t I f ( In R a n g e , "> " & n u m l)
End I f
End W ith
End F u n c tio n

As Long
num l num2
"> = " & num l)

- _

"> = " & num2)

- _

, Excel (COUNTIF).
, CountBetween , .

11. VBA

367

, Excel 2007.
Excel.

, C o u n tB e tw e e n .
1:100, 10
20.
=CountBetween (A l : A l 0 0 ,10 , 2 0)

VB, :
( 1: 100, "> = 1 0 ") - ( A l : 100 , "> 2 0 ")



: L a s tln C o lu m n ,
, L a s tln R o w ,
.
.
( L a s tln C o lu m n ) , (
LastlnR ow ).
, ,
. , :
=LastInColumn (5)

7:
=LastInRow (7 : D9)

L a s tln C o lu m n .
Function L a s tln C o lu m n (rn g As Range)
1
Dim L a s tC e ll As Range
A p p lic a tio n .V o la tile
W ith r n g .P a r e n t
W ith . C e l l s ( . Rows. C o u n t, rn g .C o lu m n )
I f N o t Is E m p ty ( . V a lu e ) Then
L a s tln C o lu m n = .V a lu e
E l s e l f Is E m p ty ( . E n d ( x lU p ) ) Then
L a s tln C o lu m n = " "
E ls e
L a s tln C o lu m n = . E n d ( x lU p ) .V a lu e
End I f
End W ith
End W ith
End F u n c tio n
, ,
.
A p p l i c a t i o n . V o l a t i l e ,
.
Rows . C o u n t .
, ,
( Excel ).

368

III. Visual Basic for Applications

r n g . Column
rn g .

r n g . P a r e n t ,
r n g .

End ( xlU p)
<End> <>.

IsE m p ty , . ,
.
0.
L astln R o w . L astlnC olum n.
F u n c tio n L a s tln R o w (rn g As Range)
1
A p p lic a tio n .V o la tile
W ith r n g . P a re n t
W ith . C e lls ( r n g .R o w , . C olu m n s. C o u n t)
I f N o t Is E m p ty ( .V a lu e ) Then
L a s tln R o w = .V a lu e
E l s e l f Is E m p ty ( . E n d ( x lT o L e f t ) ) Then
L a s tln R o w = " "
E ls e
L a s tln R o w = . E n d ( x lT o L e f t ) .V a lu e
End I f
End W ith
End W ith
End F u n c tio n


I s L ik e ( ).
, .

I s L ik e . ,
VBA L ik e .
F u n c tio n I s L i k e ( t e x t As S t r i n g , p a t t e r n As S t r in g ) As B o o le a n
1 ,
I s L ik e = t e x t L ik e p a t t e r n
End F u n c tio n

I s L ik e :

t e x t , ;

p a t t e r n , .



( - 9)
_
, _

#
[ _ ]
[ ! _ ]

11. VBA

369

, *
. , ,
.
= IsLike ( " g u i t a r " , " * " )

, ?
. 11Unit 12",
.
= IsLike ( " U n it 1" , " U n i t ? " )

,
.
= Is L ik e ( " " , " [ a e i o u ] ")

, 1
: , , i, , , , , I, , U. (UPPER)
.
=IsLike ( ( 1 ) , ( " [ a e i o u ] " ) )

, 1
, 1 (.. 100
199).
= Is L ik e ( A l/ "1 # # ")

n-
E x t r a c t E le m e n t (
VB ), . ,
, E x t r a c tE le m e n t .
123-456-789-0133-8844

, , 0133, ..
. (-) .
= E x tra c tE le m e n t("1 2 3 -4 5 6 -7 8 9 -0 1 3 3 -8 8 4 4 " ,4 , " - " )

E x t r a c t E le m e n t :
t x t , (
);
, ;
S e p a r a t o r , .

- ,
,
. ,
.

VBA E x t r a c t E le m e n t.
Function E x t r a c tE le m e n t ( T x t, n , S e p a ra to r) As S t r in g
1 n - ,

370
'

III. Visual Basic for Applications


-

Dim A llE le m e n ts As V a r ia n t
A llE le m e n ts = S p l i t ( T x t , S e p a ra to r)
E x tra c tE le m e n t = A llE le m e n t s ( n - 1)
End F u n c tio n

VBA- S p l i t ,
, . (
), n - 1.


SPELLDOLLARS ,
(
). ,

4 5 /1 0 0

=SPELLDOLLARS(1 2 3 ,4 5 )

. 11.17
SPELLDOLLARS. , , .

, 1 :
=SPELLDOLLARS(Al)

, .
1
2
3
4
5
6
7
8
9
10

12
13
14
15
16

32
37,56
-32
-26,44
-4
1,87341
1,56
1
6,56
12,12
1000000
1000000000

<
- 00/100 Dollars
- 56/100 Dollars
(- 00/100 Dollars)
(- 44/100 Dollars)
( 00/100 Dollars)
87/100 Dollars
56/100 Dollars
00/100 Dollars
56/100 Dollars
12/100 Dollars
00/100 Dollars
00/100 Dollars

. 11.17.

s p e lld o lla r s

-
s p e l l d o l l a r s ,
. w o rk s h e e t f u n c t io n . x ls m
-.


, ,
. , VBA
S t a t F u n c t io n . :

11. VBA

371

(rng) ().
, Excel: (AVERAGE),
(COUNT), (), (MEDIAN), (MIN), (MODE),
(STDEV), (SUM) (VAR).

, :
= S ta tF u n c tio n ( B l : 24 , 2 4 )

24,
: (AVERAGE), (COUNT), () ..
.
Function S t a t F u n c t io n ( r n g , op)
S e le c t Case UCase(op)
Case ""
S t a tF u n c t io n = W o r k s h e e tF u n c tio n . Sum (rng)
Case ""
S t a tF u n c t io n = W o rk s h e e tF u n c tio n .A v e ra g e (rn g )
Case ""
S t a tF u n c t io n = W o rk s h e e tF u n c tio n . M e d ia n (rn g )
Case ""
S t a tF u n c t io n = W o rk s h e e tF u n c tio n . M od e(rn g )
Case ""
S t a tF u n c t io n = W o r k s h e e tF u n c tio n .C o u n t(rn g )
Case "MAKC"
S t a tF u n c t io n = W o rk s h e e tF u n c tio n .M a x (rn g )
Case ""
S t a tF u n c t io n = W o rk s h e e tF u n c tio n .M in (r n g )
Case ""
S t a tF u n c t io n = W o rk s h e e tF u n c tio n . V a r (r n g )
Case ""
S t a tF u n c t io n = W o rk s h e e tF u n c tio n . S tD e v (rn g )
Case E ls e
S t a tF u n c t io n = C V E rr(x lE rrN A )
End S e le c t
End F u n c tio n

SheetOf fset
Excel . ,
, .
,
.
, ,
.
, , VBA S h e e tO f f s e t ,
. ,
1 :
=SheetOf f s e t ( - 1 , A l )

,
. .
,
.
VBA S h e e tO f f s e t.

372

III. Visual Basic for Applications

F u n c tio n S h e e t O f f s e t ( O f f s e t As Long, O p tio n a l C e ll As V a r ia n t )


1
Dim W ksIndex As Long, WksNum As Long
Dim wks As W o rkshe et
A p p lic a tio n .V o la tile
I f I s M is s in g ( C e ll) Then S e t C e ll = A p p l i c a t i o n . C a lle r
WksNum = 1
F o r Each wks I n A p p l i c a t i o n . C a l l e r . P a r e n t. P a r e n t. W o rksh e e ts
I f A p p l i c a t i o n . C a l l e r . P arent.N am e = wks.Name Then
S h e e tO ffs e t = W orksheets(W ksNum + _
O f f s e t ) . R a n g e ( C e ll( 1 ) .A d d re s s )
E x i t F u n c tio n
E ls e
WksNum = WksNum + 1
End I f
N e x t wks
End F u n c tio n



1
, :
=(1: 4 ! 1)

1 1,
4 .

, 4 ( 5)?
, ,
.
= (1: ! 1)

M a x A llS h e e ts, , ( )
.
, 1
.
= M a x A llS h e e ts (1)

.
F u n c tio n M a x A llS h e e ts ( c e ll)
Dim M axVal As D ou ble
Dim A d d r As S t r in g
Dim W ksht As O b je c t
A p p lic a tio n .V o la tile
A d d r = c e ll. R a n g e ( " A l " ) .A d d re s s
M axVal = -9 .9 E + 3 0 7
F o r Each W ksht I n c e l l . P a r e n t. P a r e n t. W o rk s h e e ts
I f W ksht.Name = c e l l . P arent.N am e And _
A d d r = A p p lic a t io n . C a lle r . A d d r e s s Then
1
E ls e
I f Is N u m e ric (W k s h t.R a n g e (A d d r)) Then
I f W k s h t. R ange (A dd r) > M axVal Then _
M axVal = W k s h t. R a n g e (A d d r).V a lu e
End I f

11. VBA

373

End I f
Next Wksht
I f MaxVal = -9 .9 E + 3 0 7 Then M axVal = 0
M axA llS h e ets = M axVal
End F u n c tio n

For Each :
c e ll. P a r e n t. P a r e n t. W o rksh e e ts

,
. , For Each .
I f , ,
, . ,
.
%

,

, .



Randomlntegers, ,
.
.
{=RandomIntegers () }


<Ctrl+Shift+Enter>. ,
. 50 ,
1 50.
Randomlntegers.
Function R a n d o m ln te g e rs ()
Dim FuncRange As Range
Dim V () As V a r ia n t , V a lA r r a y O As V a r ia n t
Dim C e llC o u n t As D ou ble
Dim i As I n t e g e r , j As I n t e g e r
Dim r As I n t e g e r , As I n t e g e r
Dim Tempi As V a r ia n t , Temp2 As V a r ia n t
Dim RCount As I n t e g e r , CCount As I n t e g e r
'

Range
Set FuncRange = A p p l i c a t i o n . C a lle r
1 , FuncRange
C e llC o u n t = FuncR ange. C ount
I f C e llC o u n t > 1000 Then
R an do m ln te ge rs = C V E rr(x lE rrN A )
E x it F u n c tio n
End I f
1
RCount = FuncR ange. Rows. C ount
CCount = FuncR ange. C olu m n s. C ount
ReDim V (1 To R C ou nt, 1 To C C ount)

374

1
1

III. Visual Basic for Applications


ReDim V a l A r r a y ( l To 2, 1 To C e llC o u n t)


F o r i = 1 C e llC o u n t
V a lA r r a y (1, i ) = Rnd
V a lA r r a y (2, i ) = i
N ext i
S o r t V a lA r r a y
F o r i = 1 To C e llC o u n t
F o r j = i + 1 To C e llC o u n t
I f V a lA r r a y (1, i ) > V a lA r r a y (1, j ) Then
Tempi = V a lA r r a y (1 , j )
Temp2 = V a lA r r a y (2, j )
V a lA r r a y (1, j ) = V a lA r r a y (1, i )
V a lA r r a y (2, j ) = V a lA r r a y (2, i )
V a lA r r a y (1, i ) = Tempi
V a lA r r a y (2, i ) = Temp2
End I f
N e xt j
N ext i

'

V
i =
F o r = 1 R cou nt
F o r = 1 C count
i = i + 1
V ( r , ) = V a lA r r a y (2, i )
N ext
N e xt r
R a n d o m ln te g e rs = V
End F u n c tio n



R angeR andom ize, ,
,
.
F u n c tio n R angeR andom ize(rng)
Dim V () As V a r ia n t , V a lA r r a y () As V a r ia n t
Dim C e llC o u n t As D ou ble
Dim i As I n t e g e r , j As I n t e g e r
Dim r As I n t e g e r , As I n t e g e r
Dim Tempi As V a r ia n t , Temp2 As V a r ia n t
Dim RCount As I n t e g e r , CCount As I n t e g e r
'

,
C e llC o u n t = rn g .C o u n t
I f C e llC o u n t > 1000 Then
RangeRandomize = C V E rr(x lE rrN A )
E x i t F u n c tio n
End I f


RCount = r n g . Rows. C ount
CCount = r n g . C o lu m n s. C ount
ReDim V (1 To R C ount, 1 To CCount)

11. VBA

375

ReDim V a l A r r a y ( l 2, 1 C e llC o u n t)
'
1
For i = 1 C e llC o u n t
V a lA r r a y (1, i ) = Rnd
V a lA r r a y (2, i ) = r n g ( i )
Next i

' V a lA r r a y
For i = 1 To C e llC o u n t
F or j = i + 1 To C e llC o u n t
I f V a lA r r a y (1,
i ) > V a lA r r a y (1,
j ) Then
Tempi = V a lA r r a y (1 , j )
Temp2 = V a lA r r a y (2 , j )
V a lA r r a y (1,
j ) = V a lA r r a y (1,
i)
V a lA r r a y (2,
j ) = V a lA r r a y (2,
i)
V a lA r r a y (1 ,
i ) = Tempi
V a lA r r a y (2,
i ) = Temp2
End I f
N ext j
Next i
1 V
i =

For = 1 R co u n t
For = 1 C cou nt
i = i + 1
V ( r , ) = V a lA r r a y (2 ,

i)

N ex t
Next r

RangeRandomize = V
End F u n c tio n

R a n d o m ln te g e rs . . 11.18
. 2:11 :
{= RangeRandomize (2 :11) }

2:11, .

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16

Hiyaiia _____

. 11.18. RangeRandomize

III. Visual Basic for Applications

376

Windows API
VBA ,
(Dynamic Link Libraries DLL).
Windows API.

API Excel 2010 (32-


64- ). ,
-, Excel.


Windows .
(
).
G et c u t a b l e Windows API
, . ,
. t x t ; , Re
adme . t x t Windows. G e tE x e c u ta b le
(
).

Windows API
VBA.
P r iv a t e D e c la re P trS a fe F u n c tio n F in d E x e c u ta b le A L ib _
" s h e l l 3 2 . d l l " (B yV a l l p F i l e As S t r i n g , B yV al _
l p D i r e c t o r y As S t r i n g , B yV al Ip R e s u lt As S t r in g ) As Long
F u n c tio n G e t E x e c u t a b le ( s t r F ile As S t r in g ) As S t r in g
Dim s t r P a t h As S t r i n g
Dim in t L e n As I n t e g e r
s t r P a t h = S p a c e (255)
in t L e n = F in d E x e c u t a b le A ( s t r F ile , " \ " , s tr P a th )
G e tE x e c u ta b le = T r im ( s t r P a th )
End F u n c tio n

. 11.19 G e tE x e c u ta b le ,
MP3.
, .

. 11.19.
,

377

11. VBA

-
f i l e a s s o c ia t io n . x ls m .


VBA .
API-,
.
. 11.20 VBA,
, ,
.
.


,
....

!Q

:\

:\

80015491072

67 694 669 824

12 320821248

D:\

160031014912 149153 247232

10877767 680

:\

F:\

6:\

1029 750 784

1009893 376

L fic ri

19857408

. 11.20. Windows API ,


Windows API ,
.
-.
-

- d r iv e i n f o r m a t i o n . xlsm .


, , Windows API
.
.
.

III. Visual Basic for Applications

378

P r iv a t e D e c la re P trS a fe F u n c tio n G e t P r o f ile S t r in g A L ib _


" k e r n e l3 2 " (B yV al IpAppName As S t r i n g , B yV al lpKeyName As _
S t r i n g , B yV al lp D e f a u lt As S t r i n g , B yV al Ip R e tu r n e d S tr in g As _
S t r i n g , B yV al n S iz e As Long) As Long
Sub D e f a u l t P r i n t e r l n f o ()
Dim s trL P T As S t r i n g * 255
Dim R e s u lt As S t r in g
C a ll G e t P r o f ile S t r in g A _
("W in d o w s", " D e v ic e " , s trL P T , 254)
R e s u lt = A p p l i c a t i o n . T rim (s trL P T )
R e s u ltL e n g th = L e n (R e s u lt)
Comma1 = I n S t r ( l , R e s u lt,
1)
Comma2 = In S tr(C o m m a l + 1, R e s u lt, " , " , 1)
'

'

P r in t e r = L e ft( R e s u lt,
D r iv e r = M id ( R e s u lt,

Commal - 1)

Commal + 1, Comma2 - Commal - 1)

'


Msg = " :" & C h r(9 ) & P r i n t e r & C h r(1 3 )
Msg = Msg & " :" & C h r(9 ) & D r iv e r & C h r(1 3 )
Msg = Msg Sc " :" & C h r(9 ) & P o r t

MsgBox Msg, v b ln f o r m a t io n , " "

P o r t = R ig h t ( R e s u lt , R e s u ltL e n g th - Comma2)

'

End Sub

A c t iv e P r i n t e r A p p l i c a t i o n
( ).
.
.

. 11.21 , .
-
-
p r i n t e r i n f . xlsm .


Windows API
.
, , ,
. , .
, .
D e c la re P trS a fe F u n c tio n G e tS y s te m M e tric s L ib _
"u s e r3 2 " (B yV al n ln d e x As Long) As Long
P u b lic
C onst SM_CMONITORS = 8 0
P u b lic
C onst SM_CXSCREEN = 0
P u b lic
C onst SM_CYSCREEN = 1
P u b lic
C on st SM_CXVIRTUALSCREEN = 78
P u b lic
C onst SM_CYVIRTUALSCREEN = 79
Sub D is p la y V id e o I n f o ()
Dim n u m M o n ito rs As Long

11. VBA

379

Dim v id W id th As Long, v id H e ig h t As Long


Dim v i r t W i d t h As Long, v i r t H e i g h t As Long
Dim Msg As S t r in g
num Monitors = GetSystemMetrics(SM_CMONITORS)
v id W id th = GetSystemMetrics(SM_CXSCREEN)
v id H e ig h t = GetSystemMetrics(SM_CYSCREEN)
v ir t W id t h = GetSystemMetrics(SM_CXVIRTUALSCREEN)
v ir t H e ig h t = GetSystemMetrics(SM_CYVIRTUALSCREEN)
I f n um M onitors > 1 Then
Msg = n u m M o n ito rs & " " & v b C rL f
Msg = Msg & " :
" & v ir tW id th & " X "
Msg = Msg & v i r t H e i g h t & v b C rL f & v b C rL f
Msg = Msg & " :
"
Msg = Msg & v id W id th & " X " & v id H e ig h t
Else
Msg = Msg & " : "
Msg = Msg & v id W id th & " X " & v id H e ig h t
End I f
MsgBox Msg
End Sub

. 11.22 ,
.

: Adobe PDF
:
wmspool
:
Ne04:

. 11.21. Windows API

: 1920 X 1080

. 11.22.
Windows API

-
-
v id e o m ode.xlsm .


, , Excel
. ,
WAV MIDI. ,
. .
, Excel
WAV MIDI, .
-
s o u n d . xlsm .

WAV-
API-,
so u n d .w a v , ,
.

III. Visual Basic for Applications

380

P r iv a t e D e c la re F u n c tio n P la yS o un d L ib " w in m m .d ll" _


A l i a s "P layS o u nd A " (B yV al IpszName As S t r i n g , _
B yV al hM odule As Long, B yV al d w F lag s As Long) As Long
C onst SND_SYNC = &H0
C onst SND_ASYNC = &H1
C onst SND_FILENAME = &H2 0000
Sub PiayW AV()
WAVF i 1e = " s o u n d . w av"
W AVFile = T h is W o rk b o o k .P a th & " \ " & W AVFile
C a ll P la yS o u n d (W A V F ile , 0&, SND_ASYNC Or SND_FILENAME)
End Sub

WAV- .
, .
, :
C a ll P la yS o u n d (W A V F ile ,

0&, SND_SYNC Or SND_FILENAME)

MIDI-
MIDI,
API-. MIDI- P la y M I D I .
S to p M ID I MIDI-.
x f i l e s .m id.
P r iv a t e D e c la re F u n c tio n m c iE x e c u te L ib "w in m m .d ll" _
(B yV a l IpstrC om m and As S t r in g ) As Long
Sub P la y M ID I()
M ID IF ile = " x f i l e s . m i d "
M ID IF ile = T h is W o rk b o o k .P a th & " \ "
m c iE x e c u te ( " p la y " & M ID IF ile )
End Sub

& M ID IF ile

Sub S to p M ID I()
M ID IF ile = " x f i l e s . m i d "
M ID IF ile = T h is W o rk b o o k .P a th & " \ "
m c iE x e c u te ( " s to p " & M ID IF ile )
End Sub

& M ID IF ile


A larm , ,
. Windows API ,
.
D e c la re F u n c tio n P la yS o un d L ib "w in m m .d ll" _
A l i a s "P layS o u nd A " (B yV al IpszName As S t r i n g , _
B yV al hM odule As Long, B yV al d w F lag s As Long) As Long
F u n c tio n A la r m ( C e ll, C o n d itio n )
Dim W AVFile As S t r in g
C onst SND_ASYNC = &H1
C onst SND_FILENAME = &H20000
I f E v a lu a t e ( C e ll. V a lu e & C o n d itio n ) Then
W AVFile = T h is W o rk b o o k .P a th & "\s o u n d .w a v "
C a ll P la yS o u n d (W A V F ile , 0&, SND_ASYNC Or SND_FILENAME)
A la rm = T ru e
E ls e
A la rm = F a ls e

11. VBA

381

End I f
End F u n c tio n

A larm : (
). , A larm
WAV-, 13 1000.
=ALARM(B13, "> = 1 0 0 0 ")

VBA E v a lu a te ,
. ( ),
, .
-

- s o u n d . xlsm .



s a y lt .


Windows
( 4). VBA
.
Windows API.
Private D e c la re P trS a fe F u n c tio n RegOpenKeyA L ib "AD VAPI32.D LL" _
(ByVal hKey As Long, B yV al sSubKey As S t r i n g , _
ByRef h k e y R e s u lt As Long) As Long
Private D e c la re P trS a fe F u n c tio n R egC loseK ey L ib "ADVAPI32.DLL" _
(ByVal hKey As Long) As Long
Private D e c la re P trS a fe F u n c tio n R egS etV alueE xA L ib "AD VAPI32.D LL" _
(ByVal hKey As Long, B yV al sValueName As S t r in g , _
ByVal dwR eserved As Long, B yV al dwType As Long, _
ByVal s V a lu e As S t r i n g , B yV al dw S ize As Long) As Long
Private D e c la re P trS a fe F u n c tio n R egC reateKeyA L ib "AD VAPI32.D LL" _
(ByVal hKey As Long, B yV al sSubKey As S t r in g , _
ByRef h k e y R e s u lt As Long) As Long
Private D e c la re P trS a fe F u n c tio n R egQ ueryValueExA L ib "ADVAPI32.DLL" _
(ByVal hKey As Long, B yV al sValueName As S t r in g , _
ByVal dwR eserved As Long, ByR ef lV a lu e T y p e As Long, _
ByVal s V a lu e As S t r i n g , ByR ef IR e s u ltL e n As Long) As Long

-
-,
: G e tR e g is tr y W r ite R e g is tr y .
- w indow s r e g i s t r y .x ls m .
,
.

III. Visual Basic for Applications

382


G et R e g is t r y .
.

R oot Key. , , .
:
HKEY_CLASSES_ROOT;
HKEY_CURRENT_USER;
Y_LOCAL_MACHINE;
HKEY_USERS;
HKEY_CURRENT_CONFIG;
HKEY_DYN_DATA.

P ath . , .

R egE n try. , .

. ,
, G e t R e g i s t r y
( , ).
R ootK ey = " h k iy _ c u r r e n t _ u s e r "
P a th = " C o n tr o l P a n e l\D e s k to p "
R e g E n try = " W a llp a p e r"
MsgBox G e tR e g is try (R o o tK e y , P a th , R e g E n tr y ) , _
v b ln f o r m a t io n , P a th & " \R e g E n try "


( , ).


W r it e R e g i s t r y .
, ;
. W r i t e R e g i s t r y
( ).

R ootK ey. , , .
:
HKEY_CLASSES_ROOT;
HKEY_CURRENT_USER;
Y_LOCAL_MACHINE;
HKEY_USERS;
HKEY_CURRENT_CONFIG;
HKEY_DYN_DATA.

P ath . . , .

R eg E n try. , .
, .

R egV al. , .

11. VBA

383

, ,
Excel. Excel.
Sub Workbook_Open ()
RootKey = " h k e y _ c u r r e n t _ u s e r "
Path = " s o f t w a r e \ m i c r o s o f t \ o f f i c e \ 1 4 . 0 \ e x c e l\ L a s t S t a r t e d "
R egEntry = "D a te T im e "
RegVal = Now()
I f W r ite R e g is tr y ( R o o tK e y , P a th , R e g E n try , R egVal) Then
msg = R egVal & " ."
E ls e msg = " "
End I f
MsgBox msg
End Sub

,
Excel.


Excel, Windows API.
VBA G e tS e ttin g S a v e S e ttin g .
,
. ,
:
HKEY_CURRENT_USER\Software\VB and VBA Program S e t t in g s

,
, Excel.

...
12

13

14

15

13 . 3107




...
...

VBA MsgBox
Excel G e tO p e n F ile n a m e

Excel G e tS a v e A sF ile n a m e

Excel

,
Excel.

...

Windows. Windows,
, . Excel
(UserForm).
, VB , .

,
Excel, .

IV.

388


,
. , ,
, .
I n p u t Box: VBA,
A p p l i c a t i o n .

inputBox VBA
:
In p u tB o x ( [, ] [ ,
[, , ] )

_ ] [ ,

xpos] [ ,

ypos]

_ . ,
( ).

x p o s , y p o s.
( ).
, . (
).

, ( ).
( ).

I n p u t Box .
, .
, , 1024 (
). ,
,
.
. ,
.
, . 12.1, VBA InputB o x , ( ).
.
Sub GetName()
Dim UserName As S t r i n g
Dim F ir s tS p a c e As I n t e g e r
Do U n t i l UserName <> 11"
UserName = In p u tB o x ( " :
" , ")
Loop
F irs tS p a c e = In S tr(U s e rN a m e , " ")
I f F ir s tS p a c e <> 0 Then
UserName = L e ft(U s e rN a m e , F irs tS p a c e - 1)
End I f
MsgBox " " & UserName
End Sub

", _

: Input B o x Do Until.
, .
(Cancel) , UserName

12.

389

, .
(
I n S tr ) . , L e f t
, .
, .
, In p u tB o x . ,
In p u tB o x ,
, VBA V al.
In p u tB o x Excel.
. 12.2 VBA In p u tB o x .
.
. .
?

-2]

- .

Windows 7. ,
Windows 7
,
Windows 7 ,
, , ,
- . ,

Microsoft.

. 12.1.
VBA InputBox

Cancel
-------

. 12.2. VBA Input


Box,

Sub GetWord ()
Dim TheWord As S t r in g
Dim p As S t r in g
Dim t As S t r i n g
p = R ange( " A l ")
t = " ?"
TheWord = In p u tB o x ( p r o m p t: =p, T i t l e : = t )
I f UCase(TheWord) = "WINDOWS 7" Then
MsgBox " ."
E ls e

MsgBox " ."


End I f
End Sub

-
, ,
- VBA in p u t b o x . xlsm .

Excel i n putBox
Excel InputBox ( VBA InputBox)
:
;
;
.

IV.

390

InputBox .
In p u tB o x { ,
[,

] ,

[,

[, ] , [, _ ] ,
, ] , [, ] )

[,

],

, ( ).

_ . ,
( ).

, .
( ).

( ).

, .

).

. , (
). . 12.1.

12.1. , Excel In p u tB o x

0
1
2
4
8
16
64

()
( )

(, #/)

Excel InputBox .
, . , ,
,
3 (.. 1+2 +). 8,
. ,
.
EraseRange, , InputBox.
, (. 12.3).
, .
InputBox 8 Range (
Set). (
Clear).
. (Cancel), On Error
.
Sub E ra se R a n g e ()
Dim U serRange As Range
On E r r o r GoTo C a n ce le d
S e t UserRange = A p p l i c a t i o n . In p u tB o x _
(P ro m p t: = " :", _
T i t l e : =" ", _
D e f a u l t : = S e le c tio n .A d d r e s s , _
T y p e := 8 )

12.

391

U serR ange. C le a r
U serR ange. S e l e c t
C a n c e le d :
End Sub
S i

Visual ^
Basic

-
..

29

:
68

..
18

49

ss

| | !

&

1.....< * '

.... 1

17

42

75

19

41

42

12

87

53

58

76

25

99

95

33

34

29

62

91

41

39

73

22

12

14

21

28

43

55

8 7 ....

54

44

38

40

16

47

31

24

60

15

88

24

80

251

85

40

85

72

96

29

86

11

78

39

29
11
56
88
69

94

65
29
20
36
89
44

37

37

70
38
63
82
92
27

20
84
39

85

95

39

56

38

71

94

68

14

41

<sfcB

10

95

76

79

29

11

12

46

38

23

58

20

83

77

76

13

60

22

13

14

94!

94

41

66

15

60

22

11

18

29

16

58

35

56

17

20

17

96

88

31

36

81
87
33
49
99
91
84
7

18

91

74

69

27

89

19

81

79

57

19

20

39

68

88

54

14

22

78

-H *J

JSFS9:SK$21

97

PUPv7 1 Q

-.

j
;

3
4

} 65

..

F9

S3

inputbox method - Microsoft Excel

*0 ' ?
1

. %j\

'

64
13
25
66
6

7S
76

18
17
31
27
65
23
54
34

3
46
78

42
61
33

20
11
56

88
88
30
18
17

10

44

52
17
41

37
2
30
57

76

59

39
29
20
36

92
32
44

21

78

22

34

19

17

37

27

65

62

47

69

27

LI4

23

39

71

66

33

65

26!

28

14

60

85

86

24

97

85

19

85

90

30

75

43

22

81

71

18

25

27

17

45

51

36

'

71

36

78

42

4 1..Sbeetl
; 46,94871795

; 73

< ......
: 3662

44

28

. 12.3. inputBox

/g \

-
-
in p u tb o x m e th o d .x ls m .

Excel I n p u t Box
Excel.
EraseRange , , Excel
(. 12.4).

, , , .

. 12.4. Excel inputBox

392

IV.

VBA M sgB ox
VBA MsgBox
. (
). MsgBox
.
.
M sgBox { [,

] [ ,

] [,

])

,
( ).

, ,
( ).
. 12.2.

.
.

( ).

, . (
).
. ,
. ( . 12.2 ,
.) ,
.

12.2. ,
M sgbox

vbOKOnly

vbOKCancel

v b A b o rtR e try Ig n o re

vbYesNoCancel

vbYesNo

vbRe t Cane e1

v b C r itic a l

16

v b Q u e stio n

32

v b E x c la m a tio n

48

v b ln fo r m a tio n

64

v b D e fa u ltB u tto n l

v b D e fa u ltB u tto n 2

256

v b D e fa u ltB u tto n 3

512

vbDe f a u ltB u tto n 4

768

vbSystemModal

4096

vbM sgBoxHelpButton

16384


,
( )
. ,
-

12.

393

M sgB ox (
), .
M sgBox , ,
. .
Sub MsgBoxDemo()
MsgBox " ."

End Sub

,
MsgBox .
(. 12.3), MsgBox .
Sub GetAnswer ()
Dim Ans As I n t e g e r
Ans = M sgBox( " ? " , vbYesNo)
S e le ct Case Ans
Case vbYes
'
. . . [ Ans Yes]
Case vbNo
1
. . . [ Ans No]
End S e le c t
End Sub

12.3. , M sgbox

vbOK

OK

vbCancel

vbAbort

vbRetry

vblgnore

vbYes

vbNo

MsgBox , Integer.

MsgBox. GetAnswer.
Sub GetAnswer2 ()
I f MsgBox( " ? " , vbYesNo)
'
. . . [ Ans Yes]
Else

. . . [ Ans No]
End I f
End Sub

= vbYes Then


, .
(. 12.5).
Conf ig.
Private F u n c tio n C o n tin u e P ro c e d u re () As B o o le a n
Dim C o n fig As In t e g e r
Dim Ans As I n te g e r
Config = vbYesNo + v b Q u e s tio n + v b D e fa u ltB u tto n 2

IV.

394

Ans = MsgBox(" . ?", Config)


If Ans = vbYes Then ContinueProcedure = True _
Else ContinueProcedure = False
End Function

C o n tin u e P r o c e d u r e . ,
C o n tin u e P r o c e d u r e (
). (..
), .
:
If Not ContinueProcedure() Then Exit Sub

,
vbC rL f ( vbNew Line) .
(. 12.6).
T

. ?

||

.
.

. 12.5. MsgBox
,

. 12.6.

Sub MultiLineO
Dim Msg As String
Msg = " ." & vbCrLf & vbCrLf
Msg = Msg & " ." & vbCrLf
Msg = Msg & " ."
MsgBox Msg
End Sub

vbTab.

13x3 1:13 (. 12.7).
vbTab. vbCrLf.
MsgBox ,
1023 . ,
. , ,
, , 11 .
Sub ShowRange()
Dim Msg As String
Dim r As Integer, As Integer
Msg = ""
For r = 1 To 12
For = 1 To 3
Msg = Msg & Cells(r, c).Text
If <> 3 Then Msg = Msg & vbTab
Next
Msg = Msg & vbCrLf
Next r
MsgBox Msg
End Sub

12.

395

. 12.7.


15 ,
MsgBox.

Excel G e tO p e n F ile n a m e
,
I n p u t B o x ,
. G e tO p e n F ile n a m e
A p p lic a t io n , ,
( ).

, .
, , .
.
( ):
Application.GetOpenFilename (_, _, ,
_, _)
_. ,

( ).
_.

, ( ).
. ( ).

, .
_. Macintosh.

396

IV.

_ .

, .
.

_
, . ,
, ,
. .
, , .
"

( * . * ) . ,
. * . *
.
F i l t .
_
G e tO p e n F ile n a m e .
( ).
F i l t ,
VB . .
F i l t = " ( * . t x t )
" L o tu s ( * . p r n ) , * . p r n , "
",
" A S C II ( * . a s c ) , * . a s c , "
" ( * . * ) , * . * "

, * . t x t ," & _
& _
(*.csv), * . csv," & _
& _

_ _ ,
. ,
. _ ,
. .
.
.
Sub G e tIm p o rtF ile N a m e ()
Dim F i l t As S t r i n g
Dim F i l t e r l n d e x As I n t e g e r
Dim T i t l e As S t r i n g
Dim F ileN am e As V a r ia n t
'

'
'


F i l t = " ( * . t x t ) , * . t x t , " & _
" L o tu s ( * . p r n ) , * . p r n , " & _
", ( * . c s v ) , * . c s v , " & _
" A S C II ( * . a s c ) , * . a s c , " & _
" ( * . * ) , * . * "
* . *
F ilt e r ln d e x = 5

T i t l e = " "

F ileN am e = A p p l i c a t i o n . G etO penF ilenam e _
( F ile F ilte r := F ilt, _
F ilt e r ln d e x : = F ilte r In d e x , _
T it le : = T it le )

12.

397

1
I f FileN am e = F a ls e Then
MsgBox " ."
E x i t Sub
End I f
'


MsgBox " " & F ileN am e
End Sub

. 12.8 ,
, .
1

i -

JLj
j j

41
5 1
1
~7~|

8|
11
111
121
JLJ

D: >\6} 12_a.csv

...
1

lij
14
15

1"

16
17
18
19

. 12.8. GetOpenFilename ,

. ,
, <Shift> <Ctrl>,
. ,
F ileN am e.
,
. .
Sub G e tIm p o rtF ile N a m e 2 ()
Dim F i l t As S t r i n g
Dim F i l t e r l n d e x As I n t e g e r
Dim F ileN am e As V a r ia n t
Dim T i t l e As S t r i n g
Dim i As I n t e g e r
Dim Msg As S t r i n g
'


F i l t = " ( * . t x t ) , * . t x t , " & _
" L o tu s ( * . p r n ) , * . p r n , " & _
", ( * . c s v ) , * . c s v , " & _
" A S C II ( * . a s c ) , * . a s c , " & _
" ( * . * ) , * . * "

'

* . *
F i lt e r l n d e x = 5

T i t l e = " "

'

398

IV.

F ileN am e = A p p l i c a t i o n . G etO penFilenam e


( F ile F ilte r := F ilt, _
F ilt e r ln d e x : = F ilte r In d e x , _
T i t l e : = T itle , _
M u l t i S e l e c t : =T rue)

" "

I f N o t Is A rr a y ( F ile N a m e ) Then
MsgBox " ."
E x i t Sub
End I f
'

F o r i = L B o u n d(F ile N a m e) To U B ound(F ileN am e)


Msg = Msg & F ile N a m e ( i) & v b C rL f
N ext i
MsgBox " :" & v b C rL f & Msg
End Sub

: F ile N a m e
( ). ,
F ile N a m e , .
-

- p ro m p t f o r f i l e . x ls m .

Excel G e tS a v e A s F ile n a m e
G e tO p e n F ile n a m e .

( ) . ,
.
:
A p p lic a tio n .G e tS a v e A s F ile n a m e { _ , _,
_ , , _ )

.
( ).

_ .

_ .
( ).

_ . ,
( ).

).

_.

Macintosh.

12.

399


,
G etO penFileN am e. (
), Excel F ile D ia lo g .
(. 12.9),
. M sgB ox
( ).
f/|

0 U

FU_Backup

Microsoft O ffk

&

MSOffice95

MSC)ffice2003
MSOffice201Q

Jg Program Files
lH totakm d

i l l Tracing

24.092010 8:38

09J03 2010 21:21

09.032010 22:14

Documents am

09.03201021:21

J |i

10.09,2010 0:06

16.03201019:13

yj

09.03.2010 21:21

Work

r-a

09.032010 21:21

jftl

Windows

24.03.2010 22:26

10.03201012:36

09.03.2010 21:21

JjP

09.032010 21:21

(AMResCV)

. 12.9. F ile D ia lo g
Sub G e t A F o l d e r ()
With A p p l i c a t i o n . F i l e D i a l o g ( m s o F i l e D i a l o g F o l d e r P i c k e r )
. I n i t i a l F i l e N a m e = A p p l i c a t i o n . D e f a u l t F i l e P a t h & " \"
. T i t l e = " "
. Show
I f . S e l e c t e d l t e m s . C o u n t = 0 T h en
M sgBox ""
E lse
M sgBox . S e l e c t e d l t e m s (1)
End I f
End W ith
End Sub

F i l e D i a l o g
I n i t i a l F i l e N a m e .
Excel, .

Excel
VBA Excel,
.

IV.

400

, (
). , VBA
1^ ^ 1^ (Home^Editing^Find & Select^
Go ) 1: .
(Go ) ( ).
A p p lic a t io n . G o t o R e fe r e n c e : = R a n g e ("A 1 :C 3 ")

Excel,
. D ia lo g s A p p l i c a t i o n .

Excel
D ia lo g s A p p lic a t io n . ,
Microsoft ,
. ,
Excel, .

Excel
CommandBar. Excel 2007 Excel 2010
- , , .


, CommandBar,
22.

Excel 2007 C om m andBar


. , C om m andBar
VBA. ,
, . ,
(. 12.10).
A p p lic a tio n .C o m m a n d B a rs . E xe c u te M s o ( "S h e e tU n h id e ")

[_ _]

. 12.10. ,

VBA

E x e c u te M s o , id M s o ,
. ,
.

401

12.

-
- r ib b o n c o n t r o l
n a m e s .x ls x ,
Excel. ,
. (
).
. , Excel
, F u n c tio n w iz a r d
.
.
(. 12.11).
A p p lic a tio n . CommandBars . E xecuteM so ( " F o r m a tC e lls F o n tD ia lo g " )

Calibri

11

12
14

ZA

*^(>^^
.Dialog 9
.Ruler
? 1251Pragmatica
4 1251 .................
:

zi

|
:

|7

*
______I__

TrueType. , .

. 12.11. ExecuteMso


Excel ,
. Excel
,
.
, , (
^^ (Insert^Tables^Table)).
. 12.12.


- Excel ,
.
. .

402

IV.

< .,
Central

07.09.2009
Single Family
25.02.2009

Single Family
Single Family
Single Family

Single Family

Single Family
Single Family
Single Family
Adams

27.02.2009
2

1800

Single Family
Single Family

2 041

Single Family

3 1 940
3 3927

Single Family
Single Family

2,5 2 030

S. County
Central
Shasta

Condo

. 12.12.
Excel

1.
(Customize
Quick Access Toolbar).
(Quick Access Toolbar)
Excel (Excel Options).
2. (Choose Commands From)
(Commands Not in the Ribbon).
3. (Form).
4. (Add)
.
5. Excel.

.
, Excel 2003

, Excel,
Excel 2007 ( CommandBar).
Excel CommandBar , -
.
, ^^
(Format^Sheet^Unhide) Excel 2003.
A p p l i c a t i o n . C om m a n d B a r s( " W o r k s h e e t Menu B a r " )
C o n t r o l s ( "") . C o n t r o l s ( " ") _
C o n t r o l s ( " . . . " ) . E x e c u te


(Unhide).
( ).
.
(Format Cells).

12.

403

A p p lic a tio n . CommandBars( "W o rksh e e t Menu B a r " ) _


C o n t r o l s ( " ") . C o n t r o l s ( " . . . " ) . E x e c u t e

CommandBar ,
Excel.

,
Excel .
.
(Form) . Excel
, .
<>. ,
( ).
, .
(New).
Excel ,
.

VBA
Show DataForm Excel.
,
. 1 ( ),
.
Sub D is p la y D a ta F o rm ()
Range("Al").Select
A c tiv e S h e e t. ShowDataForm
End Sub

-

- ( d a ta fo rm e x a m p le . xlsm ).

13)

...
Excel
U serF orm


Toolbox





U serF orm


Toolbox


Excel
Excel,
.
Excel.

IV.

406

Excel
. , Excel 97,
.
,
. Excel 97
Excel 5/95.
, U s e rF o rm ; ,
.

, Visual Basic (VBE).
,
.
1. U serF orm VBAProject .
2. U s e rF o rm .
3. .
4. .
U s e rF o rm
(, ).
5. , U serForm .
VBA ( U serF orm ).
6. , . 5.
, ..

U s e rF o rm
U s e rF o rm , VBE (
<Alt+Fll>,
Inserts UserForm (^ UserForm)). U s e rF o rm
, U s e r F o r m l, U s e rF o rm 2 ..

U ser
Form. Name ()
Properties (). ( ,
<F4>.) . 13.1 Properties,
UserForm .

U s e rF o rm ,
.

13.

407

. 13.1. Properties UserForm



U s e rF o rm ,
Toolbox ( ). , VBE
,
. Toolbox ,
Vie\AF>Toolbox (^
I* 08
Toolbox). Toolbox . 13.2.

F* -J
Toolbox,
3 10
.


(
). , . 13.2.
Toolbox
,
.

,
. ,
C om m an dB utton U s e rF o rm ,
C o m m a n d B u tto n l.
C om m andB utton, C om m andB utton2.

,
VBA.
, . , d u c tL is tB o x , L is t B o x i.
Properties () VBE.
Name.

IV.

408

Toolbox
,
Toolbox.
-
UserForm, ,
. 13.3. all
userf orm controls.xlsm -.

Label 1

Pagejk ;2 |

(* jOptoonButtonr
|

_ OptionButton2

ZJ

__

jj

<1 1
ToggteButti^il

. 13.3. U s e r F o r m 15

UserForm
ActiveX (. Toolbox ).

CheckBox
C h e c k B o x
: , , ..
C h e c k B o x , T ru e ,
F a ls e .

ComboBox
Com boBox L i s t B ox.
, Com boBox ,

13.

409

. ,
,
ComboBox.

CommandButton

C o m m a n d B u tto n . C o m m a n d B u tto n ,
.

Frame
F ra m e
. ,
.
Frame ,
O p t io n B u t t o n .

Image
Im a g e
, .
, Im a g e
. .
,
.
JEJk

,
.
.

Label
L a b e l .

ListBox
L i s t B o x ,
( ). L i s t B o x
. , ,
. .
, L i s t B o x VBA.

MultiPage
M u lt iP a g e
,
(Format Cells). M u lt iP a g e .

IV.

410

OptionButton
O p t i o n B u t t o n
.
, . Op
t i o n B u t t o n , O p t i o n B u t t o n
.

O p t io n B u t t o n ,
G roupN am e. O p t io n
B u t t o n .
O p t i o n B u t t o n F ram e,
.

RefEdit
R e f E d i t ,
.

ScrollBar
S c r o l l B a r
S p in B u t t o n . ,
S c r o l l B a r .
S c r o l l B a r
.

SpinButton
S p i n B u t t o n
. ,
. S p in B u t t o n
T e x tB o x L a b e l,
S p in B u t t o n .

TabStrip
T a b S t r i p M u lt iP a g e ,
. T a b S t r i p , M u ltiP a g e ,
. , M u l
t i P a g e .

TextBox
T e x tB o x .

ToggleButton
T o g g le B u t t o n : .

. T r u e ()
F a ls e (). ,

13.

411

OptionButton CheckBox .



.
Excel ^ ^ (Developer^Controls^lnsert).
,
. , ,
. ,
CheckBox (),
, L in k e d C e ll. ,
. ,
.
,
ActiveX. , a c t iv e x w o rk s h e e t
c o n tro ls . x ls x , -.
.

--------- ~--------

JL

4J


565

$345 000

5,65

" $5,000

10%

30

15%

<* 15

$276 000

15

15

30

20%

$276 000

10%

5,65%

20%

15%

20%

$2 277,18


, .

.
.

ActiveX.
, .
,
, . -

412

IV.

,
ActiveX.
ActiveX Excel
.
,
, .
(Properties) ActiveX
^ => (Developer^Controls^Properties).
B u tto n
(), (Form).
.
CommandButton,
ActiveX,
(, C o m m a n d B u tto n i_ d ic k ),
(Sheet). .
Excel ,
. ,
^ ^ (Developer^Controls^Design
mode). , .



,
.
.

.
<Shift>
.

U s e rF o rm ,
.
,
. ,
, VBE Tools^Options (1^).
Options () General ()
Form Grid Settings (
).
Format () VBE ,
.
,
. , . . 13.4
O p t io n B u t t o n
. . 13.5 ,
.

13.

413

. 13.4. Format^Align

. 13.5. O ptionB utton


,
.
, ,
.

414

IV.


,
.
.

.
Properties ().

,
. VBA.

Properties
VBE Properties ()
(
U s e rF o rm ) (. 13.6).

. 13.6. Properties O ptionB utton

Properties () . Alphabetic (
) .
Categorized ( )
. , -.

,
.
, .
Properties , .
, . ,
T e x t A l i g n : 1 f m T e x t A lig n L e f t ,
2 f m T e x t A l ig n C e n t e r 3 f m T e x t A l ig n R i g h t .

13.

415

(, F o n t P i c t u r e )
.
.
P i c t u r e Im a g e ,
.
.
, P i c t u r e Im a g e
<Ctrl+V> .

,
Properties ,
.

U serForm , .
, ,
,
. , F o n t
,
.


,
, . ,
Name ,
( H e ig h t , W id th , L e f t R ig h t ) .
VBA,
. , O p t io n B u t t o n ,
, t i o n B u t t o n l . :
O p tio n B u tto n l .V a lu e = T ru e

O p t i o n B u t t o n
(, o b L a n d s c a p e ), :
o bL an d sca p e .V a lu e = T ru e

&

, .
ob,
, O p tio n B u tto n .

.
, O p t i o n B u t
to n .
O p t i o n B u t t o n L e f t Properties.
L e f t .

IV.

416


.
Properties <F1>. . 13.7 ,
.
: Excel_________________________________________________ _

& # # <... ......__ _ _

_________________________

. .

...

_ _

MousePointer Property
; 10 Devao

>V>satf & fof & Langsegp

Mi>c>soft formi Visa* 6*sk RsfetWit Rf**

MousePointer Property
Specifies the type o f pointer tfcplayed when the user positions the mouse over a particular object
S y n ta x

object.M ouseP ointer [= fmMousePonta]


The M ou seP o inte r property syntax has these parts:
P a rt

D escriptio n

object
fmfifousePanter

Requred. A valid object.

Optional. The shape you want for the mouse pointer.

Settings
The settings for

fmMousePomterare:

Constant

fmMousePomterDefauft
fmMousePanterArrow
fmMousePonterCross
(mMousePanterlBeam
fmMousePohterSoeNESW
fmMousePointsrS/zef'S
fmMousePanterSizeNWSE
fmMousePomterS<*eWE
fmMousePonterUpArrow
fmMousePonterHourgtass

fmMousePantcrAppStartng
fmMousePotnterHetp
fmMousePomterStzeAi
fmMoLxePanterCustom

Value

Description

0
1
2

Standard pointer. The image s determined by the object (default).


Arrow.
Cross-hair pointer.

I-beam.

6
7
8
9
10
11
12
13
14
15
99

Double arrow pointing northeast and southwest


Double arrow pointing north and south.
Double arrow pointing northwest and southeast.
Double arrow pointing west and east.
Up arrow.
Hourglass.
'Not'symbol (drde with a diagonal line) on top of the object being dragged. Indicates an mvafcd drop target.
Arrow with an hourglass.
Arrow with a question mark.
Size al cursor (arrows pointingnorth, south, east, and west).
Uses the icon specified by the M ou s elc on property.

Remarks
Use the M ouseP ointer property when you want bo indicate changes in functionality as the mouse pointer passes over controls on a form. For example, the hourglass setting (11) is usefti to
indicate that the user must wait for a process or operation to finish.
Some icons vary depending on system settings, such as the icons associated with desktop themes.
2D10 Microsoft Corporation. All rights reserved.

. 13.7.



. <> <Shift+Tab>
. ,
, :
.
()
,
<>
<Shift+Tab>. , ,
.
T e x tB o x , .
O p t io n B u t t o n , .
, ,
.

13.

417

, View^Tab Order
(1^ ). , > Tab Order .
Excel Tab Order ( ), . 13.8. Tab Order
, . , Move Up ( )
ove Down ( ). ; ( <Shift> <Ctrl>).
file

|<jit

vtew

Q-A
ij 1

Insert

Format

\ W *?

Debug

gun

Tools

Window

Help

_ PUP/TRIAL (pup7jdam)

VBM>roject (PERSOHAUCLSB)
ft] -1 (!)

& VBAProject ()
]

Actd-tns

& J? *

1 (
2(2)
()

Q322I
prir.r.ptjrr. 4,;

0ptionButton4
0phonButton5

. 13.8. Tab Order

,
Properties. oT ablndex, 0. T a b ln d e x T a b ln d e x
. . ,
T a b ln d e x .
, T a b S to p F a ls e .

, Frame M u ltiP a g e ,
.
().
O p tio n B u tto n s ,
Frame,
Frame , View^Tab Order.

IV.

418



. , ,
<Alt> . Accelerator Properties,
.

, T e xtB o x, Ac
c e le r a t o r , C a p tio n .
,
L a b e l. Label
T e xtB o x.



VBA,
, Show UserForm.
UserForm , VBA.
UserForm UserForml,
.
Sub ShowFormO
U s e rF o rm l. Show
End Sub

VBA,
UserForm.

,
. CommandButton,
.
Unload, Hide
UserForm. .


. ,
, -
(.. ).
. Excel, .
:
U s e rF o rm l. Show vb M o de less



UserForm . :

Run^Run Sub/UserForm (^
/ );

13.

419

<F5>;
Run Sub/UserForm,
.

. ,
, .



, U s e rF o rm .

, A d d U s e rF o rm
U s e rF o rm s Show
UserForm s. U s e rF o rm
My Form , .
MyForm = "U s e rF o rm l"
UserForms . Add (MyForm) . Show


VBA L o a d .
.
Show, .
U s e r F o r m l :
Load U s e r F o r m l

,
,
Show. , Load
.


,
L is t B o x ,
CommandButton .. , ,
. , Com
m andButton C l i c k C o m m a n d B u tto n .
,
. .

U serForm .

, VBA.

VBA ,
(.. ). ,

420

IV.

L i s t B o x ,
L a b e l .
.


U s e r F o r m l U n lo a d , :
U n lo a d U se rF o rm l
U s e r F o r m ,
:
U n lo a d Me
Me
.
V B A U n l o a d , U s
e r F o r m . , U s e r F o r m
C o m m a n d B u tto n , .
.
U s e r F o r m .
, ,
U n lo a d , .
U s e r F o r m , ,
, . ,
, ,
. , ,
( U s e r F o r m ),
P u b l i c , VBA.
, .

U serForm ,
(Close) (
).
Q u e ryC lo se UserForm , T e rm i
n a te .
U s e r F o r m H id e .
, ,
. ,
.
U s e rF o rm l. H id e
(
U se r F o r m ):
M e.H ide
-
, H id e
, D o E v e n t s . , -

13.

421

UserForm ,
CommandButtonl. .
'r iv a te Sub C o m m a n d B u tto n l_ C lic k ()
Me. H id e
A p p l i c a t i o n . S c re e n U p d a tin g = T ru e
For r = 1 To 10000
C e l l s ( r , 1) = r
N ext r
U nload Me
!nd Sub

ScreenUpdating
True, Excel UserForm.
, UserForm .


15 ,
. ,
, .



,
, .
VBA
.
,
.
TextBox, , OptionButton
(, ). ,
, .


. 13.9 ,
. ,
. .
1. <Alt+Fl 1> VBE.
2. Project ()
Inserts UserForm (^ UserForm)
UserForm.

3. Caption UserForm
UserForml. Properties ()
Caption UserForm . (
Properties , <F4>.)

IV.

422

>Edit 50*wJmert
;s e -

.. ?

Wug

gun

loots


m?

AcW-lm

Window

i. %af * Q

AcrobatTOfMakrr {POFMakerjda)

& PUPTTRIAt (w 7 jd w n )

VBAProJtct (PfRSOHAL-XLSe)

1 (1)
^

VBAProject (4)

P /WtI (fWrrl)

'

. 13.9.

4. L a b e l , .

A c c e le r a to r
C a p tio n

T a b ln d ex

5. TextB ox .

Name
T a b ln d ex

TextN ame
1

6. Frame .

C a p tio n

T a b ln d ex

7. O p t i o n B u t t o n Frame
.

A c c e le r a to r
C a p tio n
Name
T a b ln d ex

O p t io n M a l e
0

8. O p t i o n B u t t o n Frame
.

13.

A c c e le r a to r
C a p tio n
Name
Tab lnd ex

O ptionFem ale
1

423

9. O p t i o n B u t t o n Frame
.

A c c e le r a to r
C a p tio n
Name
T ablndex
V alue

Opt i onUnknown

2
True

10. C o m m a n d B u tto n F ram e


.

C a p tio n
D e fa u lt
Name
T ablndex

True
OKButton
3

. C o m m a n d B u tto n
.

C a p tio n
D e fa u lt
Name
T ablndex

F a lse
C lo se K B u tto n

^,

,
,
.
<Ctrl> ,
.
.



ActiveX, (CommandButton).
, U s e rF o rm .
.
1. Excel ( <Alt+Fl 1>).
2. ^ ^ (Developer1^
Controls1^ Insert) (CommandButton),
ActiveX (ActiveX Controls).

IV.

424

3. .
.
CommandButton1^ Edit ( 1^
). , .

Properties ().
Properties.
4. C o m m a n d B u tto n .
VBE.
C o m m a n d B u tto n ,
.
5. C o m m a n d B u tt o n l_ C lic k ,
. 13.10. Show
U s e r F o r m l .

. 13.10. C om m an d B u tto n i_d ic k



,
.

, ,
. , ,
- . ,
Excel - ,
ActiveX.
^
^ (Developer^Controls^Design Mode).
, .

13.

425


(. 13.11).

*1

...
^ :

14
15
16
17

"

18
19
20

\Js i j !s s l J S L :Z

fipyroe

<I.

.....1..
::::::

.!

. 13.11. Click CommandButton


UserForm

,
. ,
, U serF o rm
.


, ,
.
.
1. VBE <Alt+Fl 1>.
2. , ,
. .
3. U serForm ,
C lo s e B u tto n _ C lic k . ,
,
.
4. , . ( C lic k
C lo se B u tto n .)

IV.

426
P r iv a t e Sub C lo s e B u tto n _ C lic k ()
U n lo a d U se rF o rm l
End Sub

, ,
UserForml.
5. <Shift+F7>
UserForml ( View Object ( )
Project Explorer ( )).
6. (
Click OKButton).
P r iv a t e Sub O K B u tto n _ C lic k ()
Dim NextRow As Long
'
'


S h e e ts ( " 1 " ) . A c t i v a t e

NextRow = _
A p p lic a tio n .W o r k s h e e tF u n c tio n .C o u n tA ( R a n g e ( " : " ) ) + 1
1

C e lls (N e x tR o w ,
'

= TextN am e. T e x t

If
If
If
'

1)

O p tio n M a le Then C e lls (N e x tR o w , 2) = " "


O p tio n F e m a le Then C e lls (N e x tR o w , 2) = ""
O ptionU nknow n Then C e lls (N e x tR o w , 2) = " "

TextN am e. T e x t = " "


O ptionU nknow n = T ru e
T extN am e. S e tF o cus
End Sub

7. Excel ,
. .
.

.
OKButton_Click . ,
1 . Excel (COUNTA)
.
Text Box . If
OptionButton,
(, , ). ,
(
). , .
( )
.


. ,
,

13.

427

( , ).
O K B u t t o n _ C lic k
. , (
) T e x tB o x . T e x tB o x ,
, .
, .
E x it Sub .
'


I f TextN am e. T e x t = " " Then
MsgBox " . "
TextN am e. S e tF o cus
E x i t Sub
End I f

,!

( ).
,
.
.
.
-

- g e t name and s e x .x ls m .

U se rF o rm
U s e rF o rm ( U s e rF o rm )
, .
Excel.
, (C o m m a n d B u tto n )
C lic k C o m m a n d B u tto n . ,
.
.
, , , S p in B utton S p in U p C hange.
Show, Excel
I n i t i a l i z e A c t i v a t e U s e rF o rm . (
I n i t i a l i z e U s e rF o rm
.)

Excel , S heet
(), C h a rt () T h isW o rkb o o k ().
18.

IV.

428


,
, .
1. .
2. ,
U s e rF o rm . VBE ,
.
3.
,
.
. 13.12 C h e c k B o x .
4. , VBE .
- lo t x l

13 Ut

ErJrt

View Insert

AH

Format

Debug Bun

> i

0 3 (J
(POfMaker-xU)
it) ^ PUP7TR1AL (pup/jdam )
| $ VBAProject {KRSOHMJaSB)

V
S/Wt 1(Iki 1)

'

Tools

AiM-lro

jf

Window

&

2,0

Private Sub CheckBox2_Click()


End Sub____________________
Private Sub CloseButton_Click()
Unload UserForml
End Sub__
Private Sub OKButtonClickO
Dim NextRow As Long
'
Sheets("1").Activate
'
NextRow = _
Application.WorksheetFunction.CountA(Range("A:A"))
'
Cells(NextRow, 1) = TextName.Text
'


If OptionMale Then Cells(NextRow, 2) = ""
If OptionFemale Then Cells(NextRow, 2) = ""
If OptionUnknown Then Cells(NextRow, 2) = "

'


TextName.Text = ""
OptionUnknown = True

. 13.12. CheckBox


. ,
.
,
. .

,
. , ,

. !
, ,
.

13.

429

U s e r F o r m

UserForm.
Initialize. UserForm.
, UserForm .
Activate. UserForm.
Deactivate. UserForm.

UserForm.
QueryClose. UserForm.
Terminate. UserForm.


, .
Show I n i t i a l i z e A c
t i v a t e ( ). Load
I n i t i a l i z e . U n lo a d Q u eryC lo se
T e rm in a te ( ). H id e
- .

-
- u s e rfo rm
e v e n ts .x ls m ,
.
U serF orm , ,
, .

S p i n B u t t o n
,
, SpinButton.

-
- u s e rfo rm
e v e n ts .x ls m , ,
S p in B u tto n U serForm ( ).

S p in B u tto n userForm .
,
.

. 13.1 SpinButton.

IV.

430

13.1. S p in B u tto n

A fte rU p d a te

,


,


V alue
, S p in B u tto n

BeforeD ragO ver


B eforeD ropO rP aste
B eforeU pdate
Change
E n te r

UserForm
E rro r

E x it

KeyDown
KeyPress
KeyUp
SpinDown
SpinUp

.





, ,

,
, ,

, ( )
S p in B u tto n
, ( )
S p in B u tto n

S p i n B u t t o n (
) .

S p in
B u t t o n , :
1) E n t e r ( , );
2) Change;
3) SpinU p.

<> ,
S p in B u tto n .
.
, :

13.

431

1) E n t e r ;
2) KeyDown;
3) C h a n g e;

4) S p in U p ( S p in D o w n );
5) K eyUp.

,
S p i n B u t t o n VBA,
. ,
V a l u e S p i n B u t t o n l ,
C h a n g e .
, V a l u e .
S p in B u tto n l. V a lu e =
, ,
E n a b l e E v e n t s A p p l i c a t i o n F a l s e .
, ,
Excel: W o rk b o o k , W o r k s h e e t C h a r t .


SpinButton T e x t B o x
S p i n B u t t o n V a l u e ,
. ,
S p i n B u t t o n ,
.

S p i n B u t t o n i ioo:
T e x t B o x ,
je|
S p i n B u t t o n - I _____________________________
, . 13.13. T extB ox. , S p in B u tton
S p in B u tt o n , - MTextBox
T e x t B o x .
. 13.13 . M in S p i n
B u tto n 1, 100. ,
S p i n B u t t o n

1 100.
-
, ,
- s p in b u tto n and te x tb o x .x ls m .

, S p i n B u t t o n T e x t B o x ,
. ,
V a l u e S p i n B u t t o n
T e x t T e x t B o x .

432

IV.


C ha ng e S p in B u t t o n . ,
, S p in B u t t o n
, .
P r iv a t e Sub S p in B u tto n l_ C h a n g e ()
T e x t B o x l. T e x t = S p in B u tt o n l.V a lu e
End Sub

V a lu e
S p i n B u t t o n T e x t T e x t B ox.
, ( S p i n B u t t o n l T e x tB o x l) .
T e x tB o x ,
C hange, .
P r iv a t e Sub T e x tB o x l_ C h a n g e ()
NewVal = V a l( T e x t B o x l. T e x t )
I f NewVal >= S p in B u tt o n l.M in And _
NewVal <= S p in B u t t o n l. Max Then _
S p in B u tt o n l.V a lu e = NewVal
End Sub

VBA V a l,
T e x t B o x ( T e x tB o x
, V a l 0).
, . ,
V a lu e S p i n B u t t o n
, T e x tB o x .
, (
O K B u tto n ) S p i n B u t t o n .
C l i c k C o m m a n d B u tto n
.
P r iv a t e Sub O K B u tto n _ C lic k ()
'

I f C S tr ( S p in B u tto n l.V a lu e ) = T e x t B o x l. T e x t Then
A c t iv e C e ll = S p in B u tt o n l.V a lu e
U n lo a d Me
E ls e
MsgBox " .", v b C r i t i c a l
T e x t B o x l. S e tF o cus
T e x t B o x l. S e lS t a r t = 0
T e x t B o x l. S e lL e n g th = L e n ( T e x tB o x l. T e x t )
End I f
End Sub

: ,
T e x tB o x , S p in B u tt o n .
. ,
T e x tB o x ,
S p i n B u t t o n , ,
, . ,
V a lu e S p i n B u t t o n
C S tr . , ,
. S p i n B u t t o n

13.

433

T e x tB o x ,
. T e x tB o x ,
( S e l S t a r t S e lL e n g th ) . ,
.
T ag
U serForm Tag.
. Tag
, .
, T e x tB o x
.
. . Tag
, .
Tag , , R e q u ire d .
Tag.
,
T e x tB o x U se rF o rm l
, .
Function Em ptyC ount ()
Dim c t l As C o n tr o l
Em ptyCount= 0
For Each c t l I n U s e r F o r m l. C o n tr o ls
I f T y p e N a m e (c tl) = "T e x tB o x " Then
I f c t l . T a g = "R e q u ire d " Then
I f c t l . T e x t = " " Then
Em ptyC ount = Em ptyC ount + 1
End I f
End I f
End I f
Next c t l
End F u n c tio n

,
Tag.



, U se Form , VBA
U se Form . ,
VBA .
,
U se Form . ,
VBA. ,
U s e r F o r m l.
Sub GetData ()
U se rF o rm l. Show
End Sub

434

IV.

, U s e r F o r m l
( T e x t B o x l) . .
.
Sub G e t D a t a ()
U s e rF o rm l. T e x t B o x l. V a lu e = " "
U s e rF o rm l. Show
End Sub


I n i t i a l i z e U s e rF o rm . U s e rF o r m _ I n i t i a l i z e , .
.
P r iv a t e Sub U s e r F o r m _ I n i t i a li z e ()
T e x t B o x l. V a lu e = " "
End Sub

,
U se Form .
:
A u to L i s t M em ber,
.

UserForm,
Me. , UserForm
, ( ) .



. ,
U s e rF o rm l:
MsgBox U s e rF o rm l. C o n t r o ls . C ount

VBA .
, CommandButton.
TypeName.
F o r Each Con
t r o l s . CommandButton,
U serF orm l.
Sub C o u n tB u tto n s ()
Dim cbC ount As I n t e g e r
Dim c t l as C o n tr o l
cbC ount = 0
F o r Each c t l I n U s e rF o rm l. C o n tr o ls
I f T y p e N a m e (c tl) = "Com m andButton" Then _
cbC ount = cbC ount + 1
N e xt c t l
MsgBox cbC ount
End Sub

13.

435

Toolbox
U s e r Form VBE, Toolbox
, .
Toolbox.


Toolbox .
New Page ( ),
Toolbox. , ,
. Rename (
) .



. , , Command
Button, .
: W idth (), H e ig h t (), C a p tio n (), De
fa u lt ( ) Name ().
Com m andButton Toolbox.
.
, .
Toolbox,
. , Com
mandButton, . ,
.
Toolbox. Toolbox
.
,
. , Frame
O p tio n B u tto n (
). Frame
Toolbox, Frame.


Toolbox. ,
Toolbox
Excel. Toolbox
Export Page ( ).

-
- (
n e w c o n tr o ls .),
.
Toolbox.
Import Page ( ). -

IV.

436

. Toolbox
. 13.14. :
, ,
, ,
, Frame,
O p tio n B u tto n , T e x tB o x S pinner,
CheckBox.

. 13.14. Toolbox

ActiveX

ActiveX, Microsoft .
ActiveX
Toolbox, Additional
Controls ( ).
, . 13.15.
Additional Controls ActiveX,
. ,
.
.


ActiveX, ,
. ,
,
.
, .

13.

437

Additional Controls
Available Controls:
:-) VideoS oft FlexArray Control
:-) VideoS oft FlexString Control
adbanner Class

OK

3
Z
j

Adobe Acrobat Control for ActiveX


Axis Class
HlBrowseButton Class
CCR S lider. ccrpS lider
COMNSView Class
Contact Selector
ContentVerifier.XlateCheckControl
CoverEdDrl Control
Cube Class
.1.1............... - ...- ..................1

Show

zi

"

Selected Items Only

BrowseButton Class-------------------------------------------------------- -*---------------------


Location

C:\Program Files\Nero\Nero 7\Nero WaveEditor\Controls.dll

. 13.15. Additional Controls



ActiveX.



. ,
CommandButton,
.
,
.
,
. :
.
,
, .
, . File^ Export
File (^ ) ( <Ctrl+E>).
.
File ^Import File (^ ),
.
Excel
Windows
. Excel
Excel.

Excel. ,
,
. Excel
. Excel
.
,
Excel VBA.

438

IV.



, , .
, .

?
,
M u l t i .

VBA ,
<Esc> ?

(
)?

S c r o l l B a r S p i n B u t t o n
?

U se F o rm ,
?

L i s t B o x ( S i n g l e , M u l t i
E x te n d e d )? L i s t
B o x 14.

...

Use Form





L is tB o x

M u l t i


L a b e l

u s e rF o rm
.
:
C o m m a n d B u tto n
L istB o x.

IV.

440


15
U se r F o r m .

C o m m a n d B u t t o n
. 14.1 U s e rF o rm ,
C o m m a n d B u tto n .
, ,
, . C o m m a n d B u tto n
. ,
C o m m a n d B u tto n l.
P r i v a t e Sub C o m m a n d B u t t o n l _ C l i c k ()
C a ll M acrol
U n l o a d Me
End Sub

M a c r o l
U s e rF o rm . ( C o m m a n d B u tto n l)
.

L i s t B o x
. 14.2
L is t B o x .
I n i t i a l i z e .
A d d I t e m L is t B o x .
P r i v a t e Sub U s e r F o r m _ I n i t i a l i z e ()
W it h L i s t B o x l
. A d d l t e m "1"
. A d d l t e m "2"
. A d d l t e m ""
. A d d l t e m "4"
. A d d l t e m ""
. A d d l t e m ""
End W it h
End Sub

. 14.1.
, CommandButton

. 14.2. ,
ListBox

,
(Execute) .

14.

441

Private Sub E x e c u te B u tto n _ C lic k ()


S e le c t Case L i s t B o x l . L is t ln d e x
Case -1
MsgBox " .
E x i t Sub
Case 0 1
Case 1 2
Case 2
Case 3 4
Case 4
Case 5
End S e le c t
Unload Me
i Sub

L i s t l n d e x
L is tB o x , , (
L is t ln d e x -1 , ).
.

-
, ,
- u s e r f orm menus . xlsm .


15 , UserForm
.


Excel
. , (Goal Seek),
1^ ^
,> (Data^Data Tools^What-If Analysis^Goal
Seek) .
, .
.
R e f E d i t .
, Excel,
.
, ,
(
Excel).

, R e fE d it
(,
, <Shift+Nl>). ,

( )
. .

442

IV.

. 14.3
R e f E d it.

. O p tio n B u tto n .
73
3
-9

-53

41

-22

93

-25

76

63
-97

*1
62

-41

-79

-6

-51

77

-55

-24

-21

$8$4:$D$10|

<?

37

-97
:

. 14.3. R e fE d it

-

- ra n g e s e le c t i o n demo. xlsm .

,
R e f E d i t .

R e f E d i t ,
. R ange.
:
S e t UserRange = R a n g e (R e fE d it1 . T e x t )

R e f E d i t
. U s e r F o r m _ In it i a l i z e :
R e f E d i t l . T e x t = A c tiv e W in d o w . R a n g e S e le c tio n .A d d re s s


R e f E d i t F ra m e M u lt iP a g e .
Excel.

R e f E d i t .

.
, . <

14.

443

, , .

. , ,
, R ef E d i t ,
.
On E r r o r Resume N e xt
S e t UserRange = R a n g e ( R e fE d itl. T e x t)
I f E rr.N u m b e r <> 0 Then
MsgBox " "
R e f E d i t l . S e tF o cus
E x i t Sub
End I f
On E r r o r GoTo 0

,
R ef E d it.
. ,
,
. .
2 ! $$1: $$4

,
.
:
Set O n e C e ll = R a n g e ( R e f E d i t l . T e x t ) . Ran ge ( " A l ")


12,
Excel In p u tB o x .



. .
, Excel,
.
Excel
.
, .
-

- , .
s p la s h s c re e n .x ls m .

.
1. .
2. Visual Basic Editor (VBE)
. ,
U s e rF o rm U s e r F o r m l.

444

IV.

3.
U s e rF o rm l.
, Im age,
. . 14.4
.
A

X Y Z Pet S u p p ly
Customer

11
12
13

14
15

16
17
18

Tracking
Sysftrn

&

19

20

21
22

?
Copyright 2010. Company Confidential

23
24

25
26

| >

Sheet 1 / Sheet2

K'J

.........................-

eh i

................ .

_ .j

>ii

. 14.4.

4. (ThisWorkbook).
P r i v a t e Sub W o r k b o o k _ O p e n ()
U s e r F o r m l . Show
End Sub

5. U se rF o rm l
( ).
, Tim e V a lu e .
P r i v a t e Sub U s e r F o r m _ A c t i v a t e ()
A p p l i c a t i o n . OnTime Now + _
T i m e V a l u e ( " 0 0 : 0 0 : 0 5 " ) , " K i ll T h e F o r m "
End Sub

6. VBA .
P r i v a t e Sub K i l l T h e F o r m ()
U n lo a d U serF orm l
End Sub

W o rkbo ok_O p e n
U s e rF o rm (. 4).
A c t i v a t e , U s e rF o rm
A c t i v a t e (. 5). O nT im e Ap
p l i c a t i o n K i l l T h e F o r m

14.

445

.
A c t i v a t e . K i l l T he F orm
U s e rF o rm .
7.
C o m m a n d B u tto n C ane e l B u t t o n , C a n c e l
T r u e
U s e rF o rm .
P r iv a t e Sub C a n c e lB u tt o n _ C lic k ()
K illT h e F o r m
End Sub

, ,
.
<Esc>. ,
.
Jfflb

, , . ,
,
, .

VBA- ,
,
. W orkbook Open .
P r iv a t e Sub W orkbook_O pen()
U s e rF o rm l. Show vb M o d e le ss
'

End Sub



,
(Close) ( ) U s e rF o rm

. . , ,
U serF orm Command
Button. ,
, .
Q u e r y C lo s e .
, U s e r
Form, (..
QueryClose).
Private Sub U serF orm _Q ue ryC lo se _
(Cancel As I n t e g e r , CloseMode As In te g e r )
I f CloseMode = vb F o rm C o n tro lM e n u Then

IV.

446

MsgBox " ."


C an cel = T ru e
End I f
End Sub

U s e r F o r m _ Q u e r y C lo s e . C lo s e
Mode , Query C lo s e . C lo se M o d e v b F o rm C o n tro lM e n u (
), , .
; C a n c e l T ru e , .
-

- q u e ry c lo s e demo. x ls m .

, <Ctrl+Break>,
.
<Ctrl+Break> U serForm
, .

:
A p p l i c a t i o n . E n a b le C a n ce lK e y = x lD is a b le d

, ,
.
.


,
. , Excel (Find and
Replace), ^^
1^ (Home^Editing^Find & Select^Replace),
(Options).

.

W id t h H e i g h t U s e rF o rm .

15, User
Form,
.

. 14.5 , . 14.6
(Options). ,
.

447

14.

Ell

01

.1

zl

i |

. 14.5. ,

4
5

. 14.6. ,

, ,
.
U s e r F o r m _ I n i t i a l i z e .
, .
Const SmallSize As Integer = 124
Const LargeSize As Integer = 164

.
, .
, .
Private Sub OptionsButton_Click ()
If OptionsButton.Caption = " >>" Then
Me.Height = LargeSize
OptionsButton.Caption = "<< "
Else

Me.Height = SmallSize
OptionsButton.Caption = " >>"
End I f
End Sub

C a p t io n C o m m a n d B u tto n
H e i g h t U s e rF o rm
C a p t io n .

- ,
,
.
<Alt+L> (
),
.
,
, .

-

- change userform size. xlsm.

448

IV.



, ,
S c r o l l B a r
. . 14.7 (
100 400%) S c r o l l B a r ,
. S c r o l l B a r
.
A

97

297

99

225

441

480

432

466

375

439

261

149

421

498

239

417

271

91

20

472

18

228

111
9

96

372

176

82

375

78

483

263

251

172

139


50

j T* j **

52

468

259

205

81

193

426

287

230

265

97

173

147

219

293

99

132

491

59

363

10

404

08

25

107

361

307

390

348

406

270

438

11

164

42

70

157

35

218

425

49

236

212

231

12

174

208

121

141

335

339

226

450

376

295

250

102

13

251

45

147

223

233

315

188

242

394

402

253

14

273

133

107

279

405

159

30

475

257

360

265

431

15

320

124

498

331

362

327

407

148

258

233

265

265

16

178

304

383

452

244

258

56

380

219

271

481

427

17

56

174

11

140

16

389

130

209

178

55

140

263

18

122

24

188

209

140

224

145

437

285

375

80

163

19

311

130

214

170

98

48

264

473

414

455

202

11

20

309

11

390

315

386

358

348

271

182

126

288

487

108

473

362

129

424

328

324

321

371

315

185

. 14.7. ScrollBar

-

- zoom and s c r o l l s h e e t.x ls m .

, .
U s e r F o r m _ I n i t i a l i z e , .
P r iv a t e Sub U s e r F o r m _ I n i t i a li z e ()
L a b e lZ o o m .C a p tio n = A c tiv e W in d o w . Zoom & "%"
'

W ith S c ro llB a rZ o o m
.M in = 10
.Max = 400
.S m allC hange = 1
. LargeC hange = 10
.V a lu e = A ctive W in d o w .Z o o m
End W ith
'

W ith S c ro llB a rC o lu m n s
.M in = 1
.Max = A c tiv e S h e e t.U s e d R a n g e . C olu m n s. C ount
.V a lu e = A c tiv e W in d o w .S c ro llC o lu m n
.LargeC hange = 25
.S m allC hange = 1
End W ith

14.

'

449

W ith S c ro llB a rR o w s
.M in = 1
.Max = A c tiv e S h e e t.U s e d R a n g e . Rows. C ount
.V a lu e = A c tiv e W in d o w .S c ro llR o w
.LargeC hange = 25
.S m allC hange = 1
End W ith
End Sub


S c r o l l B a r . ,
. S c r o l l B a r Zoom
S c r o l lB a r Z o o m _ C h a n g e ( ).
Zoom A c t iv e W in d o w V a lu e
S c r o l l B a r . , ,
.
P rivate Sub S c ro llB a rZ o o m _ C h a n g e ()
W ith A c tiv e W in d o w
.Zoom = S c ro llB a rZ o o m .V a lu e
LabelZoom = .Zoom & "%"
End W ith
End Sub
.
S c r o l l R o w S c r o l l C o lu m n s A c t iv e W in d o w
V a l u e S c r o l l B a r .
P rivate Sub S c ro llB a rC o lu m n s _ C h a n g e ()
A c tiv e W in d o w . S c ro llC o lu m n = S c ro llB a rC o lu m n s .V a lu e
End Sub
Private Sub S c ro llB a rR o w s _ C h a n g e ()
A c tiv e W in d o w .S c ro llR o w = S c ro llB a rR o w s .V a lu e
End Sub

&

change
s c r o l l . ,
.
S c r o l l change s c r o l l .

L is t B o x

L i s t B o x ,
.
L i s t B o x .

, ,
ComboBox.

15. 3107

IV.

450

,
L i s t B o x . .

L i s t B o x
( R o w S o u r c e ) VBA
( A d d lt e m ).

L i s t B o x
.
M u ltiS e le c t.

L i s t B o x ,
L i s t B o x
C o n t r o l S o u r c e .

L i s t B o x
( L i s t l n d e x -1 ).
,
. M u l t i S e l e c t T r u e .

L i s t B o x (
C o lu m n C o u n t) (
C o lu m n H e a d s).

L i s t B o x ,
,
U s e r F o r m .

L i s t B o x
, ,
, .
L i s t S t y l e .


L i s t B o x .

ListB ox
,
L i s t B o x , L i s t B o x
. L i s t B o x
, .
, V B A
.
:

U s e r F o r m U s e r F o r m l;

U s e r F o r m l L i s t B o x ,
L i s t B o x l ;

1 , 1: 12
, L i s t B o x .

14.

451

L i s t B o x
L i s t B o x
, .
RowSource ,
L is tB o x . . 14.8 Properties ()
L is tB o x . R o w S o u rc e 1 ! A l : 12.
U s e rF o rm , L i s t B o x
.
L is tB o x , ,
R o w S o u rc e .

J.

. 14.8. RowSource

, RowSource .
L is tB o x
.
, , :
[ b u d g e t . x ls x ] 1 ! 1 : 1 2
,
.
, ,
.

IV.

452

L i s t B o x
L is t B o x ,
:

R ow Source,
, ;

, A d d ltem
L is tB o x .

, R ow Source
, Properties. ,
R ow Source L is t B o x ,
U se Form.
C a t e g o r i e s B u d get.
U s e rF o rm l. L i s t B o x l . RowSource = "B u d g e t! C a te g o r ie s "
U s e rF o rm l. Show

L is t B o x ,
VBA L istB ox
.
L is t B o x

A ddltem .
Sub Show U serForm 2()
'

W ith U s e rF o rm l. L is t B o x l
R ow S o u rce = ""
A d d lte m " "
A d d lte m " "
A d d lte m " "
A d d lte m " "
A d d lte m " "
A d d lte m " "
A d d lte m " "
A d d lte m " "
A d d lte m "
A d d lte m " "
A d d lte m " "
A d d lte m " "
W ith
U s e rF o rm l. Show
End Sub

RowSource
. ,
, Properties RowSource
L is t B o x .
L is t B o x ^
RowSource, permission denied
( ).

14.

453

A d d ltem
ListBox, .
L is t B o x 1:12 1.
For Row = 1

12

U s e rF o rm l. L is t B o x l .A d d lte m S h e e ts (11 1 " ) . C e lls (Row, 1)


Next Row

L i s t .
, For N ex t.
U serForm l. L i s t B o x l . L i s t = A p p l i c a t i o n . T ra n s p o s e (S h e e ts ( _
" 1 " ) . R a n g e ("A 1 :A 1 2 "))

, T r a n sp o s e ,
List -,
-.
() ,
L i s t . , , M yL ist,
50 . 50-
L is t B o x l .
UserForm l. L i s t B o x l . L i s t = M y L is t

-
-
lis t b o x . x l s m .

f i l l

L i s t B o x


L is tB o x () .
, , .
(. 14.9).
L is t B o x , ,
.
C o l l e c t i o n .
C o l l e c t i o n :
object.A dd ite m ,

k e y , b e fo r e ,

a fte r

k e y ( ) ,
.
, ,
. ,
.
.
NoDupes.
, , D a ta , ,
.

454

IV.

D
6

7
9
10
8

1005

1006

1007

-------------

1008

~ ~ ~ 1

1009

_________

11 1010

12 1011

1012

i_________i

14 1013

15 1014

16 1015

17 1016

18 1017

: 41

19 1018

20 1019

21 1020

22 1021

23 1022

24 1023

25 1024

26 1025

27 1026

28 1027

29 1028

30 1029

31 1030

... 1.

.... 1..

_1L

j
>
. 14.9. C o l l e c t i o n
L i s t B o x
, NoDupes
. , (
) k ey.
On E r r o r Resume N e x t , VBA
, .
, ,
. NoDupes
L is t B o x . U serForm ,
.
Sub R e m o v e D u p lic a te s l()
Dim A l l C e l l s As Range, C e ll As Range
Dim NoDupes As New C o l l e c t io n
On E r r o r Resume N e x t
F o r Each C e ll I n R an ge ( " S t a t e " )
N oD upes.Add C e ll. V a lu e , C S tr ( C e ll. V a lu e )
N e x t C e ll
On E r r o r GoTo 0
1

F o r Each Ite m I n NoDupes


U s e r F o r m l. L is t B o x l. A d d lt e m
N e x t Ite m
1

L is t B o x

Ite m

U s e r F o r m l. L a b e l l . C a p tio n = " :
'
U serForm
U s e r F o r m l. Show
End Sub

" & NoDupes. Count

14.

455


- ( l i s t b o x u n iq u e it e m s i .x ls m ).
l i s t b o x u n iq u e ite m s 2 .x ls m ,
.


, ,
UserForm L i s t B o x ,

. :
, .

L is t B o x
M u l t i s e l e c t
.

, ,
V a lu e L i s t B o x . , ,
L i s t B o x l .
MsgBox L is t B o x l. V a lu e

,
.
(
), L i s t l n d e x
L istB o x .
,
L i s t B o x .
MsgBox " #" & L i s t B o x l . L is t ln d e x

, L i s t l n d e x -1 .

L is t B o x ,
c l . , L is t ln d e x
,
L is t c o u n t , 1.



M u l t i S e l e c t L i s t B o x
.

0 ( f m M u lt i S e l e c t S i n g l e ) . .

1 ( f m M u lt i S e l e c t M u l t i ) .
( ) .

IV.

456

2 ( f m M u l t i S e l e c t E x t e n d e d ) . <Shift>,
.

<Shift> .

L i s t B o x
( M u l t i S e l e c t 1 2), L i s t l n d e x
V a lu e . S e le c t e d ,
, 0. ,
T ru e , L is t B o x .
MsgBox L i s t B o x l . S e le c t e d (0)

-
- ,

L is tB o x . L is tB o x ,
,
l i s t b o x s e le c te d ite m s , xlsm .
, ,
-,
L i s t B o x . ,
M sg. , .
P r iv a t e Sub O K B u tto n _ C lic k ()
Msg = " "
F o r i = 0 To L i s t B o x l . L is tC o u n t - 1
I f L i s t B o x l . S e le c t e d ( i) Then _
Msg = Msg & L i s t B o x l . L i s t ( i ) & v b C rL f
N ext i
MsgBox " : " & v b C rL f & Msg
U n lo a d Me
End Sub
. 14.10
L is t B o x .

. 14.10.
L istB o x

14.

457


ListBox

L is tB o x , ,
O p tio n B u tto n .
. 14.11 U s e rF o rm .
L is tB o x . ,
C l i c k O p t io n B u t t o n ,
RowS o u r L i s t B o x

. .

.....

*1

<* :

6
vt

10
11

........................1
j

12

13
14
15
16

. ...

17

..........

18
19

:.................

20

21
22

23

............
.

24

.,.......

25
26
<

I
1

J,
1

....

..

.. , . ... J

>0

. 14.11. ListBox ,
OptionButton
P r iv a t e S u b o b M o n t h s _ C l i c k ()
L i s t B o x l . R o w S o u rc e = " 1 ! "
End Sub

O p t io n B u t t o n , o b M o n th s ,
R o w S o u rc e L is t B o x ,
1 .

-

- l i s t b o x m u l t i p l e l i s t s , x ls m .

ListBox
.
.

IV.

458

(Quick Access Toolbar)


Excel (Excel Options).
. 14.12 L is tB o x .
, L i s t
B o x , L i s t B o x .
.
. ,
, ,
, .
*J

J ]

1|

zi

. 14.12.

. ,
.
P r iv a t e Sub A d d B u t to n _ C lic k ()
I f L i s t B o x l . L is t ln d e x = -1 Then E x i t Sub
I f N ot c b D u p lic a te s Then
'

For i
If

= 0 To L is t B o x 2 . L is tC o u n t - 1
L is t B o x l. V a lu e = L is t B o x 2 . L i s t ( i ) Then
Beep
E x i t Sub
End I f
N ext i
End I f
L is tB o x 2 .A d d lte m L i s t B o x l . V a lu e
End Sub

.
P r iv a t e Sub R e m o v e B u tto n _ C lic k ()
I f L is t B o x 2 . L is t ln d e x = -1 Then E x i t Sub
L is t B o x 2 . R em oveltem L is t B o x 2 . L is t ln d e x
End Sub

,
. L i s t l n d e x L i s t B o x -1,
, . .
,
( ).
L i s t B o x (
).
, L is t B o x 2 .

14.

459

P r iv a t e S u b L i s t B o x l _ E n t e r ()
R e m o v e B u tto n . E n a b le d = F a ls e
End S u b
P r iv a t e S u b L i s t B o x 2 _ E n t e r ()
R e m o v e B u tto n . E n a b le d = T r u e
End S u b

-

- l i s t b o x it e m t r a n s f e r . x l s m .


ListBox
,
*
, .

J
,

L is t B o x . VBE

ZA
U s e rF o rm (
U s e rF o rm
OK
Tab Order).
. 14.13
L i s t B o x . 14.13.

C o m m a n d B u tto n .

L is t B o x .

.

-
-
lis t b o x

m ove

it e m s . x ls m .

-
CommandBu 1 1 on.
P r iv a t e S u b M o v e U p B u t t o n _ C l ic k ()
Dim N u m Ite rn s A s I n t e g e r , i A s I n t e g e r , Ite m N u m A s
Dim T e m p lte m A s S t r i n g , T e m p L i s t O
I f L i s t B o x l . L i s t l n d e x <= 0 T h e n E x i t S u b
N u m lte m s = L i s t B o x l . L i s t C o u n t
Dim T e m p L is t O
ReDim T e m p L is t ( 0 T o N u m lte m s - 1)
'
F o r i = 0 N u m lte m s - 1
T e m p L is t ( i) = L i s t B o x l . L i s t (i )
Next i
1
ItemNum = L i s t B o x l . L i s t l n d e x
1

In te g e r

460

IV.

T em pltem = T e m p L ist(Ite m N u m )
T e m p L ist(Ite m N u m ) = T e m p L is t( ItemNum - 1)
T e m p L ist(Ite m N u m - 1 ) = Tem pltem
L i s t B o x l . L i s t = T e m p L is t
'
L i s t B o x l . L is t ln d e x = ItemNum - 1
End Sub
P r iv a t e Sub M o v e D o w n B u tto n _ C lic k ()
Dim Num ltem s As I n t e g e r , i As I n t e g e r , ItemNum As I n t e g e r
Dim Tem pltem As S t r i n g , T e m p L is t()
I f L i s t B o x l . L is t ln d e x = L i s t B o x l . L is tC o u n t - 1 Then E x i t Sub
Num ltem s = L i s t B o x l . L is tC o u n t
Dim T e m p L is t()
ReDim T e m p L is t(0 To Num ltem s - 1)
'

F o r i = 0 Num ltem s - 1
T e m p L is t( i) = L i s t B o x l . L i s t ( i )
N ext i
1
ItemNum = L i s t B o x l . L is t ln d e x
'

Tem pltem = T e m p L is t( ItemNum)
T e m p L ist(Ite m N u m ) = T e m p L is t( ItemNum + 1)
T e m p L ist(Ite m N u m + 1) = Tem pltem
L i s t B o x l . L i s t = T e m p L is t
1
L i s t B o x l . L is t ln d e x = ItemNum + 1
End Sub


ListB ox
, L i s t B o x ,
. L is t B o x ,
, .
. 14.14 L i s t B o x ,
.

-

- l i s t b o x m u ltic o lu m n l .x ls m .

L i s t B o x ,
, ,
.
1. , C o lu m n C o u n t L is t B o x
,
.
2. ,
R o w S o u rc e
L is t B o x .

14.

461

3. , C o lu m n H eads T ru e .
, R o w S o u rc e . VBA
, ,
R o w S o u rce .

. 14.14. ListBox

4. , C o lu m n W id th s ,

(1/72 ) .
, C o lu m n W id th s
L i s t B o x 100 ; 4 0 ; 30.
5. B o u n d C o lu m n .

,
V a lu e L is t B o x .

L i s t B o x

, ,
L i s t
L is tB o x .
( 12x2)
Data. L i s t B o x
1,
2 (. 14.15). ,
C o lu m n C o u n t 2.
P rivate Sub U s e r F o r m _ I n i t i a li z e ()
1 L is t B o x
Dim D a t a ( l 12, 1 2)

_______

31
28
31
30
31
30
31
31
30

. 14.15.
ListBox,

462

IV.

F o r i = 1 12
D a t a ( i, 1) = F o r m a t( D a t e S e r ia l(2007, i , 1 ) ,
N ext i
F o r i = 1 To 12
D a ta ( i , 2) = D a y ( D a te S e r ia l(2007, i + 1, 1)
N e xt i
L i s t B o x l . C olum nCount = 2
L i s t B o x l . L i s t = D ata
End Sub

"mmmm")
- 1)

-
-
l i s t b o x m u ltic o lu m n 2 .x ls m .


ColumnHeads, VBA.

ListBox

, ,
. L is t B o x ,
(. 14.16).
L is t B o x .
, , , .
,
L is t B o x . ,
.
<Ctrl>. , ,
, .

-

- l i s t b o x s e le c t ro w s .x ls m .

, M u l t i S e l e c t
L i s t B o x 1 f m M u l t i S e l e c t M u l t i .
L i s t S t y l e L i s t B o x 1 ( f m L i s t S t y l e O p t io n ) .
U s e rF o rm ,
I n i t i a l i z e . r n g ,
. R o w S o u rce
C o lu m n C o u n t L is t B o x ,
C o lu m n W id th s , L i s t B o x
.
P r iv a t e
Dim
Dim
Dim

Sub U s e r F o r m _ I n i t i a li z e ()
C o lC n t As I n t e g e r
rn g As Range
cw As S t r in g

14.

463

Dim As I n t e g e r
C olC nt = A c t iv e S h e e t. U sedR ange. C olum ns. C ount
Set rn g = A c tiv e S h e e t.U s e d R a n g e
W ith L is t B o x l
. Colum nCount = C o lC n t
.RowSource = rn g .A d d re s s
cw = " 11
F o r = 1 To .C olum nC ount
cw = cw & r n g . C o lu m n s (c ).W id th & " ; 11
N e xt
. C olum nW idths = cw
.L is tln d e x = 0
End W ith
End Sub
A

' 1

1
1

JL
3
4
5

A dam s

17.03.2010
*5jC.UX.
1 z1
Z
U1u

A dam s

04.10.2009

A dam s

25.12.2009

15

10 A dam s

15.07.2009

11 A dam s

07.01.2010

Adams

7
9

$199 000

Central

2,5

1510

Condo

<)

17.0 Central

$199 000

2,5

Condo

Z j

21 Adams

25.0

Central

$214 500

2,5

Single

[a| Adams

Adams

04.H Central

$265 000

25.1

Central

$268 500

14 Rom ero

10.09.2009

Adams

15.0 Central

$273 500

>
S.ngte F a M

angle Far,..
Sngte F a r ^ j >

15 Ham ilton

02.08.2009

Adams

07.0

Central

$309950

SintfeFar

16 Randolph

30.09.2009

Adams

23.0 Central

$325000

2,5

Single Fat

Single Far

jj

Single Far

12 A da m s
13 Jenkins

23.06.2009
07.07.2009

17 A dam s

27.09.2009

18 Shasta

30.08.2009

19 K elly

15.11.2009

2,5

Jerfcns

07.0 N. County

$1200 500

Hamlton

02.0i N. County

$425 900

1<1

>f

23.01.2010
12.11.2009

22 A dam s

17.07.2009

23 Robinson

05.09.2009

N . County

$379000

3000

24 Barnes

02.12.2009

, S. Co unty

$208 750

1800

25 B en net

18.10.2009

Central

$229 500

26 B en net

15.10.2009

Central

$549 000

gee

>

Single Fam ily

Single Fam ily

2041

Single Fam ily

1940

S ingle Fam ily

] [

OK

____

20 Shasta
21 A dam s

______.

L
. 14.16. L is tB o x

V" !

Fl<

( S e l e c t A l l B u t t o n S e l e c t N o n e B u t t o n )
, .
P rivate Sub S e l e c t A l lB u t t o n _ C li c k ()
Dim r As I n t e g e r
For r = 0 To L i s t B o x l . L is t C o u n t - 1
L i s t B o x l . S e le c te d ( r ) = T ru e
Next r
End Sub
P rivate Sub S e le c tN o n e B u tto n _ C lic k ()
Dim r As I n t e g e r
For r = 0 To L i s t B o x l . L is tC o u n t - 1
L i s t B o x l . S e le c te d ( r ) = F a ls e
Next r
End Sub

464

IV.

O K B u t t o n _ C lic k .
R ange, RowRange. ,
L is t B o x .
, S e l e c t e d
L is t B o x . U n io n
RowRange.
P r iv a t e Sub O K B u tto n _ C lic k ()
Dim RowRange As Range
RowCnt = 0
F o r r = 0 To L i s t B o x l . L is tC o u n t - 1
I f L i s t B o x l . S e le c t e d ( r ) Then
RowCnt = RowCnt + 1
I f RowCnt = 1 Then
S e t RowRange = A c tiv e S h e e t.U s e d R a n g e . R o w s(r + 1)
E ls e
S e t RowRange = _
U nion(R ow R ange, A c t iv e S h e e t. UsedR ange. R o w s(r + 1 ))
End I f
End I f
N ext r
I f N o t RowRange I s N o th in g Then RowRange. S e le c t
U n lo a d Me
End Sub

-

- l i s t b o x s e le c t ro w s .x ls m .

ListBox

, , , .
L i s t B o x (
) .
:

( , Excel 5/95);

. 14.17 .
U s e r F o r m _ I n i t i a l i z e ( )
,
. L is t B o x .
P u b lic O r ig in a lS h e e t As O b je c t
P r iv a t e Sub U s e r F o r m _ I n i t i a li z e ()
Dim S h e e tD a ta O As S t r i n g
S e t O r ig in a lS h e e t = A c tiv e S h e e t
S h tC n t = A c tiv e W o rk b o o k . S h e e ts . C ount
ReDim S h e e tD a ta ( l To S h tC n t, 1 To 4)
ShtNum = 1

14.

465

F or Each S h t I n A c tiv e W o rk b o o k . S h ee ts
I f Sht.Nam e = A c tiv e S h e e t.N a m e Then _
L is tP o s = ShtNum - 1
S h ee tD a ta(S h tN um , 1) = Sht.Nam e
S e le c t Case TypeName(S h t)
Case "W o rk s h e e t"
S h ee tD a ta(S h tN um , 2) = " "
S h ee tD a ta(S h tN um , 3) = _
A p p l i c a t i o n . C o u n tA (S h t. C e lls )
Case " C h a r t"
S h ee tD a ta(S h tN um , 2) = ""
S h ee tD a ta(S h tN um , 3) = " / "
Case " D ia lo g S h e e t"
S h e e tD a ta (ShtNutib, 2) = " "
S h ee tD a ta(S h tN um , 3) = " / "
End S e le c t
I f S h t . V i s ib l e Then
S h ee tD a ta(S h tN um , 4) = ""
E ls e
S h ee tD a ta(S h tN um , 4) = " "
End I f
ShtNum = ShtNum + 1
N ext S h t
W ith L is t B o x l
. C olum nW idths = "100 p t ; 3 0 p t ; 4 0 p t ; 5 0 p t "
. L i s t = S h e e tD a ta
. L i s t l n d e x = L is tP o s
End W ith
End Sub
m

jkJ

i * ct2

5
JVct6
7
/* 8
9

256
10
7
117
72
128
50
0

......j.....;...

,* ^ 1 /, -2 . /,-,
-'
. 14.17.

L i s t B o x l _ C l i c k .
P rivate Sub L is t B o x l _ C l i c k ()
I f c b P re v ie w Then _
S h e e t s ( L is t B o x l. V a lu e ) . A c t iv a t e
End Sub

466

IV.

C heckBox ( c b P r e v ie w )
,
L is tB o x .
( OKButton)
O K B u tto n _ C lick , .
P r iv a t e Sub O K B u tto n _ C lic k ()
Dim U se rS h e e t As O b je c t
S e t U se rS h e e t = S h e e ts ( L is tB o x l.V a lu e )
I f U s e r S h e e t.V is ib le Then
U s e r S h e e t.A c tiv a te
E ls e
I f MsgBox ( " ? 11, _
v b Q u e s tio n + vb Y esN o C an cel) = vbYes Then
U s e r S h e e t.V is ib le = T ru e
U s e r S h e e t.A c tiv a te
E ls e
O r ig in a lS h e e t . A c t iv a t e
End I f
End I f
U n lo a d Me
End Sub

O K B u tto n _ C lick ,
. , . ,
, .
,
. (

O r ig in a lS h e e t ) .
L is t B o x
, . L i s t B o x l_ D b lC lic k ,
, O K B u tto n _ C lick .
P r iv a t e Sub L is t B o x l_ D b lC lic k ( B y V a l C a n ce l As _
S Form s. R e tu rn B o o le a n )
C a ll O K B u tto n _ C lic k
End Sub

-

- l i s t b o x a c t i v a t e s h e e t.x ls m .

M u lt iP a g e
M u ltiP a g e
. M u ltiP a g e
, .
. 14.18 U serForm , M u ltiP age.
,
.

14.

467

I *1

J | |

^j^gtcy |

J |

; j

*1

*1

;2 |

. 14.18. M ultiPage
,

<)

-
-
m u ltip a g e c o n t r o l dem o.xlsm .

T o o lb o x
T a b s tr ip , M u ltiP a g e .
M u ltiP a g e , T a b s t r ip
. M u ltiP a g e ,
T a b s tr ip .

M u lt iP a g e
. ,
M u lt iP a g e .
( ), ,
V a lu e M u ltiP a g e . 0
. 1 ..
M u lt iP a g e .
,
New Page ( ).
M u lt iP a g e ,
. Properties ,
.
M u lt iP a g e ,
.

IV.

468

, . ,
<>
.
MultiPage Properties.

M u lt iP a g e ,
M u lt iR o w T ru e , .

, .
S t y l e 1. S t y l e 2,
M u lt iP a g e , .

T a b O r i e n t a t i o n
M u lt iP a g e .

.
T r a n s i t i o n E f f e c t . ,
, . T r a n s i t i o n P e r io d , .


, , Microsoft
Windows Media Player. Excel
( Windows), U serF orm .
Microsoft Windows Media
Player .
1. VBE.

2. T o o lb o x
Additional Controls ( ).
Toolbox , Viev\F>Toolbox (1^
Tookbox).
3. Additional Controls Windows Media Player.

4. .
.
. 14.19 Windows Media Player,
U se Form , Properties. URL URL-
( ).
, URL
.
. 14.20 .
, ,
Windows Media Player. ,
L is t B o x , MP3.
(Play) .
(Close)
U s e rF o rm . U s e rF o rm ,
.

14.

469

. 14.19. Windows Media Player,

applause, mp3
beeping.mp3

gong.mp3
horses.mp3
pump.mp3

.
siren.mp3
thunder.mp3

zJ

19

,:

. 14.20. Windows Media Player

-

- m e d i a p l a y e r . x l s m .
-.

IV.

470

. -
U s e r F o r m _ I n i t i a l i z e .
, .
, ,
.
P r iv a t e Sub U s e r F o r m _ I n i t i a li z e ()
Dim F ileN am e As S t r in g
'

F ileN am e = D ir( T h is W o r k b o o k . P a th & " \ * . m p 3 " ,


Do W h ile L e n (F ile N a m e ) > 0
L is t B o x l.A d d lte m F ileN am e
F ileN am e = D i r ( )
Loop
L i s t B o x l . L is t ln d e x = 0
End Sub

vb N o rm a l)


D i r
27.

P l a y B u t t o n _ C l i c k ,
URL W in d o w s M e d ia P la y e r l.
P r iv a t e Sub P la y B u t t o n _ C lic k ()
1 URL
W in d o w s M e d ia P la y e rl.U R L = _
T h is W o rk b o o k . P a th & " \ " & L i s t B o x l . L i s t ( L i s t B o x l . L is t ln d e x )
End Sub

Label


L a b e l. U s e rF o rm , . 14.21,

.
T e x t B o x
. L a b e l
,
. ,
.
. 14.22 ,
1 10000.
, .
Dim S top pe d As B o o le a n
P r iv a t e Sub S t a r t S t o p B u t t o n _ C lic k ()
Dim Low As D o u b le , H i As D ou ble
If
1

S t a r tS t o p B u tto n .C a p t io n = " S t a r t " Then


I f N o t Is N u m e r ic ( T e x tB o x l. T e x t ) Then
MsgBox " . " , v b ln f o r m a t io n

14.

471

W ith T e x tB o x l
. S e lS t a r t =
.S e lL e n g th = L e n ( .T e x t)
. S e tF o cus
End W ith
E x i t Sub
End I f
I f N ot Is N u m e ric ( T e x tB o x 2 . T e x t ) Then
MsgBox " . " ,
W ith TextB o x2
. S e lS t a r t = 0
.S e lL e n g th = L e n ( .T e x t)
. S e tF o cus
End W ith
E x i t Sub
End I f
'

v b ln fo r m a t io n

Low = A p p lic a t io n . M in ( V a l( T e x t B o x l. T e x t ) , _
V a l( T e x tB o x 2 . T e x t ))
H i = A p p lic a t io n . M a x ( V a l( T e x t B o x l. T e x t ) , _
V a l( T e x tB o x 2 . T e x t) )
'

( )

S e le c t Case A p p lic a t io n . M a x ( L e n ( T e x t B o x l. T e x t ) , _
L e n (T e x tB o x 2 . T e x t ))
Case I s < 5: L a b e l l . F o n t. S iz e = 72
Case 5: L a b e l l . F o n t. S iz e = 60
Case 6 : L a b e l l . F o n t. S iz e = 48
Case E ls e : L a b e l l . F o n t. S iz e = 36
End S e le c t
S t a r tS t o p B u tto n .C a p t io n = " "
S topped = F a ls e
Randomize
Do U n t i l S top pe d
L a b e l l . C a p tio n = I n t ( (H i - Low + 1)
D oE vents '
Loop
Else
S topped = T ru e
S t a r t S t o p B u t t o n . C a p tio n = " "
End I f
End Sub

* Rnd + Low)

( ),
S to p p e d ,
. I f - T h e n ,
T e x tB o x .
,
.
L a b e l
. Do U n t i l lo o p .
D o E v e n ts . Excel
. , L a b e l
. ,
DoEvents .

IV.

472

(Name)____________ jUserForml
j S S S E S S H B H f l 8H8000000F&
BorderCokx
i aH80000012&
0 fmBorderStyteNone
BorderStyte
Caption

0 fmCydeAlFarms
Cyde
DrawBuffer
Enabled
Font
ForeCotor
Height
HeipContextID
KeepSooJBarsVaabie
Left
Mouselcnn
MousePonter

PictureAignment
PtetureSzeMode
PSctureTlrig
RightToLeft
SaoCars
ScrolHex/it
Smibcft
SaolTop
SooMfcfth
ShowModal
SpeoaEffect
Star tlJpPos bon
fag

WhatsTtasButton
W hatsTh^H p

Width
Zoom

| 6332

32000
True
Tahoma
8H80000012&
113,25
0
3 - fmScrotearsBoth
0
(None)
0 - fmMousePonterDefault
(None)
2 - frnPictureAigrwnen tCenter
0 - frnPictixeSizeModeCSp
F *e
False
0 fmScroearsNone

..

o
0
0
to
True
0 - ftnSpedaCffeclflat
1 -CenterOwner
0
False
M b
4?.5,/b
100........

. 14.21.
[

.

:

[*

. 14.22.

U s e rF o rm C o m m a n d B u tto n ,
.
U s e rF o rm , . C a n c e l Command
B u t t o n T ru e . <Esc>
, .
S to p p e d T r u e U s e rF o rm .
P r i v a t e S u b C a n c e l B u t t o n _ C l i c k ()
S to p p e d = T ru e
U n lo a d Me
End Sub

-
-

ra n d o m n u m b e r g e n e r a t o r . x ls m .

...



M sgBox
U s e rF o rm
U se r F o r m
U s e rF o rm
U se r F o r m


U se F orm



U s e rF o rm

, 14,
U s e rF o rm .

474

IV.


, , , ..
, ,
. .
, ,
.
U s e rF o rm :
U s e rF o rm l. Show vb M o de less

v b M o d e le s s , 0.
, .
U s e rF o rm l. Show 0

. 15.1 ,
. ,
, ,
, Excel.

. 15.1. ,

-
m odeless u s e r f o r m l. x ls m .


, .
: S h e e tS e le c tio n C h a n g e
S h e e t A c t i v a t e .
T h is W o r k b o o k ().

15.

475


U J

19 .

- .
Private Sub W o rk b o o k _ S h e e tS e le c tio n C h a n g e _
(ByVal Sh As O b je c t, B yV al T a rg e t As Range)
C a ll U pdateB ox
End Sub
Private Sub W o rk b o o k _ S h e e tA c tiv a te (B y V a l Sh As O b je c t)
C a ll U pdateB ox
End Sub

U p d a te B o x ,
.
Sub UpdateBox ()
W ith U se rF o rm l
'

I f T y p e N a m e (A c tiv e S h e e t) <> "W o rk s h e e t" Then


. lb lF o r m u la . C a p tio n = " / "
. lb lN u m F o rm a t. C a p tio n = " / "
. lb lL o c k e d .C a p t io n = " / "
E x i t Sub
End I f
.C a p tio n = " :

" & A c t iv e C e ll. A d d r e s s ( F a ls e , F a ls e )

I f A c t i v e C e l l . H asF orm ula Then


. lb lF o r m u la . C a p tio n = A c t i v e C e l l . F orm ula
E lse
. lb lF o r m u la . C a p tio n = " ( ) "
End I f
1

. lb lN u m F o rm a t. C a p tio n = A c tiv e C e ll.N u m b e rF o rm a t


1

. lb lL o c k e d . C a p tio n = A c t i v e C e l l . Locked
End W ith
End Sub

U p d a te B o x U s e rF o rm ,
.
Label ( lb l F o r m u l a , lb lN u m F o r m a t l b l L o c k e d ) .
, , .
U s e rF o rm ,
, .
, .
, L a b e l /.
S e le c t io n _ C h a n g e
( T h is W o r k b o o k ()).
L a b e l .

IV.

476

. 15.2 .
. ,
Excel, ,
(Info) ( Excel ).
, , (
) .

1 ;.... 3331

2909

2579
8819

2122]

2 791

8 244

1 892

3111;

7912 j

4,0%|

8 756

10,7%

2 321
$

6 335

3856
$

9 758

$2 4 912

19
UserForm,
8 &11


. UserForm

: 027176077-02

: -4,0%

,
.

<

*: Double
: 0.0%
: -{5)5
: ()

/0!
!

:
: $)
: .
: .
:
: 2

. 15.2. userForm

-
m od ele ss u s e r fo r m 2 .x ls m
-.

, .

U se F o rm
(Auto Update). ,
. ,
(Update).


: S h e e t S e le c t io n C h a n g e S h e e t A c t iv a t e .
, ,
,
(, ).
(, )
- . U s e rF o rm
.


29
.

15.

477

, ,
. P r e c e d e n ts
D e p e n d e n ts .

, VBA
L a b e l,
U s e rF o rm .


Excel
. ,
,
. .
.
,
( ).

U s e rF o rm

, U s e rF o rm .
U s e rF o rm M u lt iP a g e
, .
, U s e rF o rm .
U s e rF o rm ,
.
,
.
. ,
( ), ,
, .
, ,
, Excel .



Excel. .
, ,
,
.
:
A p p lic a tio n . S ta tu s B a r = ", ..."
. ,
P e t, ,
, :
A p p lic a tio n . S ta tu s B a r = " ... " & P et & "% "
.
:
A p p lica tio n . S ta tu s B a r = F a ls e

IV.

478

,
.

,
,
.
, .



.
U serF o rm .
, 20 .
Sub G enerateR andom N um bers()
'
C onst RowMax As I n t e g e r = 500
C onst ColM ax As I n t e g e r = 4 0
Dim r As I n t e g e r , As I n t e g e r
I f T y p e N a m e (A c tiv e S h e e t) <> "W o rk s h e e t" Then E x i t Sub
C e l l s . C le a r
F o r r = 1 To RowMax
F o r = 1 To ColMax
C e l l s ( r , c) = In t( R n d * 1000)
N ext
N e xt r
End Sub

( ) U s e r
Form , . 15.3, .

. 15.3. UserForm

15.

479

-
-
p ro g re s s i n d i c a t o r l . xlsm .

U se r F o r m ,

U s e rF o rm ,
.
1. U s e rF o rm
C a p t io n .
2. Fram e Fram e P r o g r e s s .
3. L a b e l F ram e
L a b e l P r o g r e s s .
, ( B a c k C o lo r ) .
.
4. L a b e l Fram e,
().

.

5. U s e rF o rm ,
, . 15.4.

. 15.4. UserForm

. ,
S p e c ia lE f f e c t Fram e , .


,
U s e rF o rm .
I n i t i a l i z e . ,

IV.

480

, . ,
A c t i v a t e , U s e rF o rm

, .
U serF orm .
G e n e ra te R a n d o m N u m b e rs ,
U s e rF o rm . G e ne ra te R a n d o m N u m b e rs,
VBA, ,
, .
P r iv a t e Sub U s e r F o r m _ A c tiv a t ()
C a ll GenerateRandomNumbers
End Sub

G e n e ra te R a n d o m N u m b e r.
, ,
P e t D one.
Sub G enerateR andom N um bers()
'

Dim C o u n te r As I n t e g e r
C onst RowMax As I n t e g e r = 500
C onst ColM ax As I n t e g e r = 4 0
Dim r As I n t e g e r , As I n t e g e r
Dim PctDone As S in g le
I f T y p e N a m e (A c tiv e S h e e t) <> "W o rk s h e e t" Then E x i t Sub
C e l l s . C le a r
C o u n te r = 1
F o r r = 1 To RowMax
F o r = 1 To ColM ax
C e l l s ( r , c) = In t( R n d * 1000)
C o u n te r = C o u n te r + 1
N e xt
PctDone = C o u n te r / (RowMax * ColMax)
C a ll U p d a te P ro g re s s (P c tD o n e )
N ext r
U n lo a d U s e rF o rm l
End Sub

G e n e ra te R a n d o m N u m b e rs .
U p d a t e P r o g r e s s ,
( P c tD o n e ,
). 0 100.
Sub U p d a te P ro g r e s s ( P e t)
W ith U s e rF o rm l
. F ra m e P ro g re s s . C a p tio n = F o rm a t(P e t, "0%")
. L a b e lP r o g r e s s . W id th = P e t * ( . F ra m e P ro g re s s . W id th - 10)
. R e p a in t
End W ith
End Sub


, , Us
e r Form . VBA.
Sub ShowUserForm ()
W ith U se rF o rm l

15.

481

. L a b e lP r o g r e s s . W id th =
. Show
End W ith
End Sub

g b

,
. showUserForm
.
. L a b e lP r o g r e s s . B a c k C o lo r = A c tiv e W o rk b o o k . Theme. _
Them eC olorSchem e. C o lo rs (m s o T h e m e A c c e n tl)


S h ow U serF orm L a b e l
0. Show U s e r F o r m l,
U se r F o r m (
). U s e Form ,
A c t i v a t e , G e n e r a te R a n d o m Numbers. G en era teR a n d o m N u m b ers ,
U p d a te P r o g r e s s .
, U p d a te P r o g r e s s R e p a in t
U serForm . ,
. G en era teR a n d o m N u m b ers
U se r F o r m .
, ,
.
P c tD o n e .
.
( ),
. ,
.


MultiPage
U serF orm .
,
U serF orm .
, :
;
U ser F o r m (
M u ltiP a g e ) ;
.

16 3ak. 310 7

-
, ,
- p ro g r e s s i n d i c a t o r 2 . xlsm .

IV.

482

, .
, U serForm ,
(. 15.5).

1
2

_________1.........................................

JL

..F

1________ X

^ ,

5
6

1 500

r d

25

7
S

OK

10
11

.............

..................i

12
13
14
15
16

'

-*

j
-.. -..... -....

'

j
.....

j.

!-.t --- --.1

. 15.5.
,


, U se Form .
M u lt iP a g e .
M u lt iP a g e .
,
. ,
VBA V a lu e M u lt iP a g e .
,
.
M u lt iP a g e
U serF orm .
U serF o rm M u ltiP a g e .
M u ltiP a g e
, , . 15.6.
, .
1. Fram e, F r a m e P r o g r e s s .
2. L a b e l Fram e,
L a b e l P r o g r e s s . ,
.
3. L a b e l,
().
4. M u lt iP a g e (
), S t y l e 2 fm T a b S ty le N o n e .
( .) ,
M u lt iP a g e , .

15.

483

------------------|Pa ge 2 Page

Pagel Page j

...
0/-

Alphabetic | Categorized |
1 (Name)

Page2

> Accelerator
Pa9e

1 ControfTipText
1 Cyde. . . . .
0- fmCydeAForms
Enabled
fltu e . . . . .
; Index
jl
1KeepScrotearsVtstole 3- fmSadBarsBoth
S Picture
..O^one)
1PictureAkgnment i2 - fmPictureAbgnmentC
PictureSizeMode
0 - fmPictureSizeModeCt

1PictureTing

False

ScrollBars
0 - frnScrdBarsNone
< ScroHHetght
0. . . . . . . . . . . . . . . . . . . . 1
ij SaoHeft
10_ _ _ _ _ _ _ _ _ _ _ _ _ |
| ScrafTop
lo
j SaoHWidth
0
Tag
_________
0 - fmTrartabonEffectNc
i TranationEffiect
TransbonPenod
o..........
Viable
Zoom

True
100

. 15.6. M ultiPage,

M u ltiP a g e ,
, ,
Properties.
v a lu e M u ltiP a g e : 0 P agel, 1 2 ..

U p d a t e P r o g r e s s
U se Form .
Sub U pdateProgress (P e t)
With U serF orm l
. F ra m e P ro g re ss. C a p tio n = F o rm a t(P e t, "0%")
.L a b e lP ro g re s s .W id th = P e t * ( . F ra m e P ro g re s s . W id th - 10)
.R e p a in t
End W ith
End Sub

U p d a t e P r o g r e s s
.


,
. C l i c k
O K B u tto n_C lick. .

MultiPagel .Value = 1

IV.

484


M u lt iP a g e (, ).

,
. PctD one.
, .
, .
C a ll U p d a te P ro g re s s (P c tD o n e )


, ,
U s e rF o rm .
M u lt iP a g e
.


MultiPage
, , ,
. ,
M u lt iP a g e .
U s e rF o rm .
, , ,
U s e rF o rm .
,
U s e rF o rm , .

-
p r o g r e s s in d ic a t o r 3 . x ls m .

. 15.7 U s e rF o rm VBE. H e ig h t
U s e rF o rm 172.
U se rF o rm , H e ig h t 124 (
, , ,
). , VBA
H e ig h t 172. :
M e .H e ig h t = 172

. 15.8 U s e rF o rm
.



.
Excel
. , , ,
.

15.

485


. ,
. ,
(Finish), , .
XI
,
.

jl_abel3 Label
. .
1
j
Alphabetic j Categorized j

] (Name)

ll; l

LabeJ3

i Accelerator
AutoSze
BackCoior
BaAStyte
BofderCokx
: BorderStyfe

0***-
i

False

....

.
_________________

01aH8000000F&
1 - fmBackStyteOpaque

8H80000006&

0 - fm&orderStyteNone
1> ..._____

jj

5 ControrTipText
j Enabled
True
_______________ _________ _
Font
jTahoma___________
SH800000124
j ForeColor
5Height
31,5.......
; HetoContexffl) 0
6,7
|j Left
: Mouselcon
(None)
_______
MousePointer 0 - fmMousePonterOefault
(None)
Picture
H PtcturePosibon 7 - fmPtcturePosibonAboveCenter
SpeaalEffect 0 - fmSpeaalEffiectfla t
Tablndex
[8
TabStop
False
_ I Z 'I .....................................................I
!! Tag.........._ 1 ...
j TextAign
1 - fmTextAlgnLeft
Top
102,7
' _
____________ _________
Viable
.............................. .......................
tlTrue
Width
200,25
i w ordwrap
True

. 15.7. UserForm
,
A

705

533

45

414

524

767

829

824

106

999

295

382
412[
261

410

905

561

694

10

513

462

!F

47Q
7

*1

,
.
-4 ..
.
1

| 500

__

77%

11

364

489

12

506

390

13

73

105

331

!
.9*J

______

128

G
77

536

14

760

814

71

56

949

22

647

263

95

980

243

03

798

284

78

160

162

86

583

80

31

627

428
677

16

430

43

979

60

42

156

938

96

832

18

657

544

827

14

191

678

454

357

149

704

928

530

89

15

401

461

492

207

329

95

589

169

927

16

443

272

872

750

272

673

256

89

30

17

790

297

235

480

254

340

44

482

206

. 15.8.

VBA-
U s e rF o rm . -

486

IV.

U s e F orm
M u l t i P a g e .

. 15.9 , .
U s e Form ,
M u l t i P a g e .
M u l t i P a g e .

. 15.9. , MultiPage

-
, ,
- w iz a r d demo .x ls m .

-.

MultiPage
U se r F o r m .
M u l t i P a g e . .
M u l t i P a g e ,
(
). - ,
M u l t i P a g e .
M u l t i P a g e . S t y l e
M u l t i P a g e 2 f m T a b S t y le N o n e .

u s e rF o rm ()
(
M u ltiP a g e ).

15.

487


M u lt iP a g e .
. M u lt iP a g e ,
.


,
.
M u ltiP a g e ,
M u lt iP a g e . , .

. ,
.

. .
.

. .
.

. .


, ,
.
. ,
,
. ,
-,
.
C o m m a n d B u tto n ()
C a n c e lB u t t o n , B a c k B u tto n , N e x t B u t t o n F i n i s h B u t t o n .



C l i c k .
C a n c e lB u t t o n .
M sgB ox (. 15.10), ,
.
, U s e rF o rm
.
.

. 15.10.

P rivate Sub C a n c e lB u tto n _ C lic k ()


Dim Msg As S t r in g
Dim Ans As I n t e g e r
Msg = " ?"
Ans = MsgBox(Msg, v b Q u e s tio n + vbYesNo, APPNAME)

488

IV.

I f Ans = vbYes Then U n lo a d Me


End Sub

.
P r iv a t e Sub B a c k B u tto n _ C lic k ()
M u ltiP a g e l.V a lu e = M u ltiP a g e l.V a lu e - 1
U p d a te C o n tro ls
End Sub
P r iv a t e Sub N e x t B u t t o n _ C lic k ()
M u ltiP a g e l.V a lu e = M u ltiP a g e l.V a lu e + 1
U p d a te C o n tro ls
End Sub

. V a lu e
M u ltiP a g e , ,
U p d a te C o n tr o ls ( ).
U p d a te C o n tr o ls B u tto n N e x tB u tto n .
Sub U p d a te C o n tr o ls ()
S e le c t Case M u ltiP a g e l.V a lu e
Case 0
B a c k B u tto n .E n a b le d = F a ls e
N e x tB u tto n . E n a b le d = T ru e
Case M u lt iP a g e l. P a g e s. C ount - 1
B a c k B u tto n . E n a b le d = T ru e
N e x t B u t to n . E n a b le d = F a ls e
Case E ls e
B a c k B u tto n . E n a b le d = T ru e
N e x tB u tto n . E n a b le d = T ru e
End S e le c t


M e .C a p tio n = APPNAME & " "
& M u ltiP a g e l.V a lu e + 1 & " " _
& M u lt iP a g e l. P a g e s. C ount
'

I f tb N a m e .T e x t = " " Then
F in is h B u t t o n . E n a b le d = F a ls e
E ls e
F in is h B u t t o n . E n a b le d = T ru e
End I f
End Sub

UserForm ,
( APPNAME
M o d u lel).
M u ltiP a g e (
T extB ox,
tbName). ,
. T ex tB o x ,
F in is h B u t t o n . ,
.

15.

489



, .
- ,
. ( )
Microsoft.
O p t io n B u t t o n ,
.

C hange M u ltiP a g e .
M u ltiP a g e ( ),
M u l t i Page l_ C h a n g e .
( ), C h e ckB o x
, .
.
:
CheckBox, ( ),
F ra m e ( ). F o r N e x t
F ra m e ,
.
F ram e. ,
, ,
, T e x tB o x , .
(, , ).
M u l t i Page l_ C h a n g e .
P riva te Sub M u l t i Page l_C ha ng e ()
1

I f M u ltiP a g e l.V a lu e = 3 Then


'

Dim
S et
S et
S et
'

Dim
S et
S et
S et

CheckBox

P ro d C B (l To 3) As MSForms. CheckBox
P ro d C B (l) = c b E x c e l
ProdC B(2) = cbWord
ProdC B(3) = cbA ccess

Frame

P ro d F ra m e (l To 3) As MSForms. Frame
P ro d F ra m e (l) = F ram eE xcel
P ro dF ram e(2) = FrameWord
P ro dF ram e(3) = Fram eAccess

TopPos = 22
FSpace = 8
A tL e a stO n e = F a ls e
1

F or i
If

= 1 To 3
P ro d C B (i) Then
P r o d F r a m e ( i) . V is ib le = T ru e
P ro d F ra m e ( i ) . Top = TopPos
TopPos = TopPos + P r o d F r a m e ( i) .H e ig h t + Fspace
A tL e a stO n e = T ru e
E ls e

IV.

490
P r o d F r a m e ( i) . V is ib le = F a ls e
End I f
N ext i
1

I f A tL e a s tO n e Then
lb lH e a d in g s . V is ib le = T ru e
Im a g e 4 .V is ib le = T ru e
lb lF i n i s h M s g . V i s i b l e = F a ls e
E ls e
l b l H e a d in g s . V is ib le = F a ls e
Im a g e 4 .V is ib le = F a ls e
lb lF i n i s h M s g . V i s i b l e = T ru e
I f tbName = " " Then
lb lF in is h M s g . C a p tio n = _
"

1 ."

E ls e
lb lF in is h M s g . C a p tio n = _
"

."

End I f
End I f
End I f
End Sub


, :
U s e rF o rm
. F i n i s h B u t t o n _ C l i c k .

().
.
P r iv a t e Sub F in is h B u t t o n _ C lic k ()
Dim r As Long
r = A p p lic a tio n .W o r k s h e e tF u n c t io n . _
C o u n tA (R a n g e ( " A : A " ) ) + 1
1

C e lls (,

1)

= tb N a m e .T e x t

S e le c t Case T ru e
Case o b M a le : C e l l s ( r , 2) = " "
Case obF em ale: C e l l s ( r , 2) = " "
Case obNoAnswer: C e l l s ( r , 2) = " "
End S e le c t
1

C e lls (,
C e lls ( r ,
C e lls ( r ,

3) = c b E x c e l
4) = cbWord
5) = cbA ccess

If
If
If
If
If

o b E x c e ll Then C e l l s (r , 6 ) _
o b E x c e l2 Then C e l l s ( r , 6 ) = 0
o b E xce l3 Then C e l l s (r , 6 ) = 1
o b E x c e l4 Then C e l l s ( r , 6 ) = 2
o bW ordl Then C e l l s ( r , 7) _

15.
If
If
If
If
If
If
If

obWord2 Then C
obWord3 Then C
obWord4 Then C
o b A c c e s s l Then
obAccess2 Then
obAccess3 Then
obAccess4 Then

e l l s ( , 7)
e l l s ( r , 7)
e l l s ( r , 7)
C e lls ( r ,
C e lls ( r ,
C e lls ( r ,
C e lls ( r ,

=
=
=
8)
8)
8)
8)

491

1
2
= ""
=0
=1
=2

U nload Me
End Sub

,
S t y l e M u lt iP a g e .
2 fm T a b S ty le N o n e .

M sgB ox
VBA M sgB ox .
. , , ,
, , .
,
VBA M sgB ox. , .
, M sgB ox (
, ), :
, M sgB ox, .


.
,
u serF orm . ,
.
. , ,
, ..

, M sgB ox,
M yM sgBox. ,
MyMsgBox :

(
, );

( );

(
, );

M yM sgBox.
MyMsgBox( [,

[,

])

M sgB ox,
( ) .

IV.

492

M yM sgBox , MsgBox:
v b O K O n ly , v b Q u e s t io n , v b D e f a u l t B u t t o n l ..

VBA MsgBox,
.

M y M s g B o x
M yM sgBox U s e rF o rm ,
M yM sgB oxF orm . . .
I n i t i a l i z e (U se rF o rm
In itia liz e ) .

-
MyMsgBox ,
, msgbox e m u la tio n .x ls m ,
-.
, .
P u b lic P ro m p t1 As S t r i n g
P u b lic B u t t o n s l As I n t e g e r P u b lic T i t l e l As S t r in g
P u b lic U s e r C lic k As I n t e g e r
F u n c tio n M yM sgBox(ByVal Prom pt As S t r i n g , _
O p tio n a l B yV al B u tto n s As I n t e g e r , _
O p tio n a l B yV al T i t l e As S t r in g ) As I n t e g e r
P ro m p t1 = Prom pt
B u t t o n s l = B u tto n s
T it le l = T itle
MyMsgBoxForm. Show
MyMsgBox = U s e r C lic k
End F u n c tio n

. 15.11 MyMsgBox.
VBA,
(Calibri, 12 , ), .
, U s e rF o rm
Excel.
, M yM sgB oxForm .
W ith MyMsgBoxForm
. S t a r tU p P o s itio n = 0
. L e f t = A p p l i c a t i o n . L e f t + (0 .5 * A p p l i c a t i o n . W id th ) - _
0 .5 * .W id th )
.Top = A p p lic a t io n . T o p + (0 .5 * A p p l i c a t i o n . H e ig h t ) - _
(0 .5 * .H e ig h t)
. Show
End W ith

, .
Prom pt
Prom pt
Prom pt
Prom pt
B u tto n s

=" " & v b C rL f


=Prom pt & " , " &
v b C rL f
=Prom pt & " . " & v b C rL f
& v b C rL f
=Prom pt & " ? "
= v b Q u e s tio n + vbYesNo

15.
T i t l e = " "
Ans = MyMsgBox(P ro m p t, B u tto n s ,

493

T itle )

He ,
.



. ( P ro m p t 1, B u t t o n s 1 T i t l e l )
, . ( U s e r C lic k )
, . U s e r F o r m _ I n i t i a l i z e
.
( P u b l i c )
.
U s e rF o rm (. 15.12) Im ag e
( ), C o m m a n d B u tto n ,
T e x tB o x .

>

-
........... ...........


,
.
?

1 . ... ........ J

1
, , ]

. 15.11.
M s g B o x

. 15.12. U s e r F o r m ,
M y M s g B o x


image,
.
L a b e l.

U s e r F o r m _ I n i t i a l i z e
:

, (
);

, (
);

, ;

C o m m a n d B u tto n ;

494

IV.

( API-,
);

U s e Form.


C om m andB utton. ,
. U s e r C l i c k .
() .
:
VbYesNoCancel + V b Q u e s tio n + V b D e fa u ltB u tto n 3

M sgBox (,
),
. 547 (3+32+512).
.
:
. , 547 1000100011.
4 -6 , 8 -1 0
, 1 2 , .

M y M s g B o x
,
MyMsgBoxMod MyMsgBoxForm.
. MyMsgBox
, M sgBox.

U s e r F o r m

,
. U serF o rm , . 15.13,
Im age.
.

-

- move c o n t r o l s . x ls m .

Im age
: M ouseDown M ouseM ove.
Im age 1 ( ,
).
P r iv a t e Sub Im agel_M ouseD ow n(B yV al B u tto n As I n t e g e r , _
B yV al S h i f t As I n t e g e r , B yV al X As S in g le , B yV al Y As S in g le )
1

15.

495

OldX = X
OldY = Y
Im a g e l. Z O rder 0
End Sub
P riva te Sub Im agel_M ouseM ove(B yV al B u tto n As I n t e g e r , _
ByVal S h i f t As I n t e g e r , B yV al X As S in g le , B yV al Y As S in g le )
1
I f B u tto n = 1 Then
Im a g e l. L e f t = I m a g e l. L e f t + (X - OldX)
Im a g e l.T o p = Im a g e l.T o p + (Y - OldY)
End I f
End Sub

. 15.13. image

M ouseDown
X Y .

OldX OldY. Z O rder,
.

MouseMove. .
B u t t o n 1, , .
Im age .
,
. , M o u se
P o in te r 15 f m M o u s e P o in t e r S i z e A ll.
, , .

U s e r F o r m
Excel U serF o rm
. API-.
. 15.14.

IV.

496

U s e Form
. 15.15. Im age C om m andButton.

. 15.14.
userForm

. 15.15. userForm

-
no t i t l e b a r .x ls m
-. -
, 14. s p la s h
scree n2 .x ls m userF orm .

U se r F o rm
Windows API: G etW indow L ong, S etW in d ow L on g, DrawM enuBar
FindW indow A ( ,
-).
U s e r F o r m _ I n itia liz e .
P r iv a t e Sub U s e r F o r m _ I n i t i a li z e ()
Dim IngW indow As Long, lF rm H d l As Long
lF rm H d l = F in d W in d o w A (v b N u lIS trin g , M e .C a p tio n )
IngW indow = G etW indow Long( lF rm H d l, GWL_STYLE)
IngW indow = IngW indow And (N ot WS_CAPTION)
C a ll S e tW in d o w L o n g (lF rm H d l, GWL_STYLE, IngW indow )
C a l1 D raw M enuBar(1 F rm H d l)
End Sub


.
M ouseDown M ouseM ove, .

FindW indowA
userF orm , , c a p tio n
.

15.

497


U s e r F o r m
, Excel 2007,
. Excel 2007 . ,
VBA,
Excel VBA. Excel 2007
^
(Add-Ins^Custom Toolbars). ,
, .

: U s e rF o rm ,
. . 15.16 U s e rF o rm ,
.
7

' 12456

12456

12456

12456

12456

12456

34251!

34251

34251

34251

34251

34251

34251

34251

12500

12500

12500

12500

12500

12500

12500

10
11

15000!

1600
;

15000

15000

12

13

12456

[U s e rF o rm

1600

30000

14

31500

15

23000

31500
23000

23000

23000

23000

23000

23000

16

34000

34000

34000

34000

34000

34000

34000

34000

17

41000J

41000

41000

41000

41000

41000

41000

41000

18

12435J

12435

12435

12435

12435

12435

12435

12435

19

1 ;

13000

13000

13000

13000

13000

13000

2345QL-

2345Q.

2345.

13000
73450

23450

23430

23450

2345Q

. 15.16.

U s e rF o rm ,

-
-
s im u la te d t o o lb a r . x lm .

U s e rF o rm Im a g e ,
. . 15.17 U s e rF o rm ,
VBE. :

U s e rF o rm ;

VBA ,
U s e rF o rm ,
. , Windows API,
U s e rF o rm
. U s e rF o rm
C o n t r o l T i p T e x t
Im a g e .

498

IV.

,
.

. 15.17. userForm,

,
-, , ,
. ,
Im age M ouseM ove,
S p e c i a l E f f e c t . M ou se
Move Im a g e 1 (
).
P r iv a t e Sub Im ag el_M ouseM ove(B yV al B u tto n As I n t e g e r , _
B yV al S h i f t As I n t e g e r , B yV al X As S in g le , B yV al Y As S in g le )
C a ll N oR aise
Im a g e l. S p e c ia lE f f e c t = fm S p e c ia lE ffe c tR a is e d
End Sub

N o R a is e ,
, .
P r iv a t e Sub N o R a is e ()
'
,
Dim c t l As C o n tr o l
F o r Each c t l I n C o n tr o ls
c t l . S p e c ia lE f f e c t = f m S p e c ia lE f f e c t F la t
N ext c t l
End Sub

,
,
( ).. ,
U serF o rm (,
, ).
Excel.

15.

499

, ,
Wingding.
Excel ^^ (Insert^Text^Symbol).

P ic t u r e Properties.
userF orm .

U s e r F o r m

Excel . ,
(Name Manager)
.
,
, .
Windows API. , .
,
U se r F o r m .

, Excel
M icrosoft (MVP), .
Excel.
( ) -
h t t p : //a n d y p o p e . i n f o .

. 15.18 U s e rF o rm , .
L is t B o x , .
L is t B o x .
, , .
,
.
. 15.19 U s e r Form,
. ,
L istB ox , ()
. ,
U se Form.

-

- r e s iz a b le u s e r fo r m .x ls m .

L a b e l,
U se F orm . ,
, ,
L a b e l. :
( 111) Marlett, 2. (

IV.

500

o b j R e s i z e r ) U serForm
U serForm I n i t i a l i z e .
A

......

-S i

2

.

3
4

5
6
7

6 507

82 18 2 3

8 995

6 216

/ /0 8

7628

5 744

5 295

6 084

10

5 254

7 271

11

_______ 1

|
*

12

1[...................
;.................... ;..................

13

----

14
15
16
17
18
19
20
21

[....................
IS
M

.
.

. . ............................

. 15.18. U s e rF o rm

2
1

D
1 .

.......
1

G
I

... ....;.... i
1

1 *..


7Z ... j

3
4
5

6 507

8 218

6 584

5 942

8763

7 085

89 95

6 216

5829

6 268

7422

5 830

7
8

7628

5744

7261

8 673

7294

9 585

5 295

6084

5817

8853

5735

6060

10

5 254

7271

5852

6469

6 721

9120

11

|~]

86 34

9 301

8 106

5 105

7 357

9 452

12
13

5483

8 870

9 898

5373

7133

9 407

5 773

7 729

8764

7720

5461

6608

5609

7323


<1.............

14
15
16
17

8 701

9338

7 390

5022

5086

5 586

8 434

8657

6775

9 352

9 243

6 467

7143

5 487

9642

9 654

5 530

8669

7849

8 981

9989

| |||| |||

7892

-1

18

19

20

21____ 1
I

77
i

14

....

. 15.19. U se rF o rm
P r iv a t e Sub U s e r F o r m _ I n i t i a li z e ()

1
'

, ,
U serForm

S e t o b jR e s iz e r = Me. C o n tr o ls .A d d ( "F o rm s . l a b e l . 1 " ,


M R e s iz e r, T ru e )
W ith o b jR e s iz e r
.C a p tio n = C h r(1 1 1 )
.F ont.N am e = " M a r l e t t "
. F o n t . C h a rs e t = 2
. F o n t. S iz e = 14
.B a c k S ty le = fm B a c k S ty le T ra n s p a re n t
.A u to S iz e = T ru e
.F o re C o lo r = RGB(100, 100, 100)
.M o u s e P o in te r = fm M ousePointerSizeN W SE

15.
. Z o rd e r
. = Me. In s id e H e ig h t . L e f t = Me. In s id e W id th End W ith
End Sub

501

.H e ig h t
.W id th

L a b e l ,
.
.

U s e r Form (. ).

,
.
M ouseDown M ouseM ove.

VBA U se Form
, .

,

Label ,
U s e Form.
o b j Re s i z e r L a b e l
o b jR e s iz e r _ M o u s e D o w n .
P rivate Sub o b jR e size r_M o u se D o w n (B yV a l B u tto n As I n t e g e r , _
ByVal S h i f t As I n t e g e r , B yV al X As S in g le , B yV al Y As S in g le )
I f B u tto n = 1 Then
L e ftR e s iz e P o s = X
T opR esizeP os = Y
End I f
End Sub

,
( B u t t o n 1),
obj R e s i z e r . X Y,
, : L e f t R e s i z e P o s T o p R e s iz e P o s .

MouseMove, o b j R e s iz e r _ M o u s e Move. .
P rivate Sub o b jR e s iz e r_ M o u s e M o v e (B y V a l B u tto n As I n t e g e r , _
ByVal S h i f t As I n t e g e r , B yV al X As S in g le , B yV al Y As S in g le )
I f B u tto n = 1 Then
W ith o b jR e s iz e r
.Move . L e f t + X - L e ftR e s iz e P o s , .Top + Y - _
T opR esizeP os
M e .W id th = M e .W id th + X - L e ftR e s iz e P o s
M e .H e ig h t = M e .H e ig h t + Y - T opR esizeP os
. L e f t = Me. In s id e W id th - .W id th
.Top = Me. In s id e H e ig h t - .H e ig h t
End W ith
End Sub

502

IV.

, W id t h H e ig h t
U s e rF o rm
o b j R e s i z e r L a b e l. . 15.20 U s e rF o rm
L a b e l .


.

Oeepa.jJ

6 507

8 218

8 995

6 216

7708

7 628

5 744

[~1

5 295

6 084

5 254

<1

5 542

I
i

________________________________________________________________
. 15.20. VBA Label
Width Height UserForm

, ,
U s e rF o rm
. L i s t B o x , Command
B u t t o n , .
U s e rF o rm
VBA.
o b jR e s iz e r _ M o u s e M o v e .
.
'

L is t B o x
On E r r o r R e su m e N e x t
W it h L i s t B o x l
. W id t h = M e . W id t h - 22
. H e i g h t = M e . H e ig h t - 1 0 0
E n d W it h
On E r r o r G o T o 0
'

W it h C lo s e B u t t o n
. L e f t = M e . W id t h - 70
.T o p = M e . H e ig h t - 54
E n d W it h


U s e rF o rm ( Me).

15.

503

. ,
.

. ,
.



C o m m a n d B u tto n U s e r F orm
. ,
C o m m a n d B u tto n ,
.
P riv a te Sub C o m m a n d B u tto n l_ C lic k ()
1

End Sub
P riv a te Sub C o m m a n d B u tto n 2 _ C lic k ()
'

End Sub

, ,
C om m a n d B u tto n . C l i c k
C om m an dB utton .

, , .
(C o m m a n d B u tto n l Command B u tto n 2 ) B u t t o n C l i c k .
B u t t o n C l i c k , .
P riva te Sub C o m m a n d B u tto n l_ C lic k ()
C a ll B u t t o n C l i c k (1)
End Sub
P riva te Sub C o m m a n d B u tto n 2 _ C lic k ()
C a ll B u t t o n C l i c k (2)
End Sub

U se F o rm
C om m andButton,
.
, , ,
.
, .
.

-

- m u l t i p l e b u tto n s .x ls m .

U se Form ,
. 15.21.

IV.

504

If 1

13

10

14

11

15

12

16

(
)
ButtonGroupjCkk,
Btndass,


.

. 15.21.

1.
C o m m a n d B u tto n ( - 16
C o m m a n d B u tto n ).
U s e r F o r m l.

2. ( Insert^Class
Module (^ )), B t n C l a s s
. B u t t o n G r o u p _ C li c k .
P u b lic W ith E v e n ts B u tto n G ro u p As M sForm s. CommandButton
P r iv a t e Sub B u tto n G r o u p _ C lic k ()
Msg =" " & B u tto n G ro u p . Name & v b C rL f & v b C rL f
Msg =Msg Sc " :
" & B u tto n G ro u p . C a p tio n & v b C rL f
Msg =Msg Sc " : " & B u tto n G ro u p . L e f t & v b C rL f
Msg =Msg & "
: " & B u tto n G ro u p . Top
MsgBox Msg, v b ln f o r m a t io n , B utto nG ro up .N a m e
End Sub

.
P u b lic W ith E v e n ts . ,
O p tio n B u tto n CommandButton,
:
P u b lic W ith E v e n ts B u tto n G ro u p As M sForm s. O p tio n B u tto n

3. VBA .
U s e Form .
Sub S h o w D ia lo g ()
U s e rF o rm l. Show
End Sub
4. U s e F o rm
U s e r F o r m _ I n i t i a l i z e .
I n i t i a l i z e U s e r F o r m .
, O K B u t t o n .
, O K B u t t o n
B u t t o n G r o u p _ C lic k .
Dim B u t t o n s () As New B tn C la s s
P r iv a t e Sub U serForm I n i t i a l i z e ()

15.

505

Dim B u tto n C o u n t As I n t e g e r
Dim c t l As C o n tr o l
1 B u tto n
B u tto n C o u n t = 0
F o r Each c t l I n U s e rF o rm l. C o n tr o ls
I f T y p e N a m e (c tl) = "Com m andButton" Then
1
O K B utton
I f c tl.N a m e <> "O K B u tto n " Then
B u tto n C o u n t = B u tto n C o u n t + 1
ReDim P re s e rv e B u t t o n s (1 To B u tto n C o u n t)
S e t B u tto n s ( B u tto n C o u n t) . B u tto n G ro u p = c t l
End I f
End I f
N e xt c t l
End Sub

S h o w D ia lo g ,
U s e rF o rm . (
) B u t t o n G r o u p _ C lic k . . 15.22
, .

. 15.22. B u t t o n G r o u p _ c iic k ,

( MyM sgBox).
G e tA C o lo r .
Public C o lo rV a lu e As V a r ia n t
Function G e tA C o lo r () As V a r ia n t
U s e rF o rm l. Show
G etA C olor = C o lo rV a lu e
End F u n c tio n

G e tA C o lo r , .
UserColor = G e tA C o lo r ()

IV.

506


U s e rF o rm . .
U s e r C o lo r .
. 15.23 U s e r F o rm
S c r o l l B a r (, ).

0 255.
xj

|&
124, 81, 110

jj

jJ

m t
----

2J

j
j

*1

_ J

. 15.23.
, ,

S c r o l l B a r C ha ng e. ,
S c r o l l B a r .
P r iv a t e Sub S c ro llB a rR e d _ C h a n g e ()
L a b e lR e d .B a c k C o lo r = R G B (S c ro llB a rR e d .V a lu e ,
C a ll U p d a te C o lo r
End Sub

0,

0)

U p d a t e C o lo r ,
RGB.

-
-

g e t a c o lo r f u n c t io n . x ls m .
G e tA C o lo r U s e rF o rm :
. S c r o l l
b a r Windows (
APPNAME M o d u le l) .
S a v e S e ttin g APPNAME,
S a v e S e ttin g APPNAME,
S a v e S e ttin g APPNAME,

" C o lo r s " ,
" C o lo r s " ,
" C o lo r s " ,

"R e d V a lu e ", S c r o llB a r R e d .V a lu e


"B lu e V a lu e " , S c r o llB a r B lu e .V a lu e
"G re e n V a lu e ", S c r o llB a r G re e n .V a lu e

U s e r F o r m _ I n i t i a l i z e ,
.
S c r o llB a r R e d .V a lu e = G etS etting(A P P N A M E , " C o lo r s " ,
"R e d V a lu e ", 12 8 )
S c r o llB a r G r e e n .V a lu e = G etS etting(A P P N A M E , " C o lo r s " , _
"G re e n V a lu e ", 12 8 )
S c r o llB a r B lu e .V a lu e = G etS etting(A P P N A M E , " C o lo r s " ,
" B lu e V a lu e " , 12 8 )

G e t S e t t i n g
, ,

15.

507

. , , 128 (
).
S a v e S e t t in g G e t S e t t i n g
:
HKEY_CURRENT_USER\Software\VB and VBA P rogram S e t t in g s \

. 15.24 ,
R e g e d i t . .
I

:
I

H i Spyware Terminator

REG_SZ

SSPrnt

S
i i

thriXXX

!+i Cl Trados
-C l

( )

Eii: Value

REG_SZ

195

GreenValue

REG_SZ

95

REG_SZ

169

gjR edValue

Troltech
VB and VBA Program Setbrx

f -

Power U lity Pak


C j SientTek
Get A Color

^Colors

|--(2 i Vtsioneer
i U WinRAR

WinRAR SFX
Yandex

SYSTB4
UNICODE Program Groups
& Volatile Environment
a
Windows 3.1 Mgration Status
WXP
{ HKEY_LOCAl__MACHJNE
d
Q

HKEYJUSBIS
HKEY_CURR0fT CQNRG

_________ I

, ^ _ 1 _ 5 \5 /\ and VBA Program SettmgsYfc/HKui Get A Color\fefor

. 15.24.
S c r o llB a r

e tA C o lo r


,
Excel, 30.


U s e r F o r m
, Excel
U s e rF o rm . ,
P i c t u r e Im a g e . ,
,
.
,
U serF orm . . 15.25 U s e rF o rm ,
Im a g e . ,
U s e rF o rm .

L o a d P ic t u r e , P i c t u r e
Im a g e .

IV.

508

. 15.25.
UserForm

-

- c h a r t i n u s e r f o r m . x l s m .

U se Form .
1. .
2. U se r F o r m Im age.
3. VBA, GIF-,
GIF- P i c t u r e Im age.
VBA L o a d P ic t u r e .
4. . , U se rF o r m ,
. , .

GIF-
GIF- ( t e m p . g i f )
(
).
S e t C u rre n tC h a rt = S h e e ts ("D a ta ") . C h a r tO b je c ts ( 1 ) .C h a rt
Fn am e = T h i s W o r k b o o k . P a t h & " \ t e m p . g i f "
C u r r e n t C h a r t . E x p o r t F i l e N a m e : = F n a m e , F i l t e r N a m e := " G I F "

Picture
Image
Im age, U serF orm ,
Im age 1. (
Fname) Im age.
I m a g e l. P i c t u r e

= L o a d P ic t u r e ( F n a m e )

15.

509

,
.
.


U se F orm
, . ,
.

Windows A PI. 0 ( )
255 ( ). , 0 255,
.
. 15.26 ,
, 128.
\

.......5

1
I

73
1
65
69

/
7
61
24
100
8
94
9
85
1
29
10
94
53
11
44
4
12
13
92
85
14
99
39
41
15
27
15
16
48
17
62
78
18
16
88
64
33

86
42
20
8
86

80
25
22
23
7
46
24
90
95
25
26
25
46
60
26
27
72
41
28
29
72
' , .

..

10
46
76
72
53
14
65
90
8*1
27
53

71
92
41
.
3
52
56

47
81
32
73

88
13
56
46
91
38
61
7
84
76
35
9
8
68
82
24
84
56
82
16
39
57
7
75

49
36
60
11
85
80
9
46
23
21
64
90
37
30
1
Ml
75
79
93
60
82
6
97
52

100
94
58
46
64
35
54
95
52
61
41
84
49
27
56
51
12
89
79
61
22
53
25
54

70
54
24
17
51
76
30
14
19
80
79
19
67
95
94

...
92
63
92
46
14
13
66

..

. 28
7*
73
79
15
79
94
17
76
94
94
66
15
S3
43
58
66

46
77
85
72

58

. 15.26.

-

- s e m itr a n s p a r e n t u s e r fo r m . xlsm .

U serF orm ?
,
. ,
. , - (
) .
, .
. 15.27 Excel,
. Excel , .
? U se F orm
. ,

IV.

510

U serForm ,
Excel. .
W ith Me
.H e ig h t = A p p l i c a t i o n . H e ig h t
.W id th = A p p lic a t io n . W id t h
.L e ft = A p p lic a tio n .L e ft
.Top = A p p l i c a t i o n . Top
End W ith

. 15.27.

U se Form,
Excel . (
U se Form) U se Form.
-


- e x c e l lig h t - b o x . x ls m .


UserForm ,
,
Excel (. 15.28).
Excel
. . 15.29,
, .

15.
6
























511

1170,00 .

-----

---------1

2607,15 .

741,00 .
789,75 .
780,00 .
60,00 .
200,00 .
180,00 .

BONAP

BSBEV
FRANS

248,40 .

; 551,25 .
147,00 .

524,40 .

18,40 .

- 147,00 .

92.00 .
-

1104,00 .
>.
-

. 15.28. Excel

Excel 2010 .
,
.


(Customize Quick Access Toolbar).
Excel (Excel Options) (Form)
(Commands Not in the Ribbon)
.
<=] S :

SatesReport! - MtaosoK !

<

Q ) Wifk. Enhances Data


Adobe PDf *

PUP*7

=> 0

!3

/ ] HUNGC

2
3
4
5
6

8
9
10
U
12
13

13
16
17
18
19
20
21
22
23
24
25
26
27
28

ANTON
BERGS
BOLID
ROTTM

- .
312,00 .
- .
1170.00 .

Qata

702,00 .
-

............. -

*) *

* *

^
.
insert

!
1

tee. 11 6; t
. | 0

'

.*)
JU

jj J

f
-2J

7
BONAP

BSBEV
FRANS
H1LAA
LA7YK

1 <**

- p.
551,25 .
147,00 .
- p.
.
147,00 .

_______
248,40 p.
P P- P.
92.00 .
-

P-

p.
p.
p.
.
p.
p.
.
p.
p.
.
p.
p.
p.
p.
p.
Pp.
.
p.

p.
- p.
1170,00 p.

2607,15 .

o^
'
!

* P.\
- p.
- p.
741,00 .
789,75 .
- p.
780,00 p.
60,00 p.
200,00 p.
180,00 .
-

Pp.
p.
p.

A
P-.... *.Pp.
524,40 p.
p.
- p.
p.
- p.
p.
18,40 p.
1104.00
- .
p.
- p.

. 15.29.

512

IV.


. 15.1.
1 5 . 1 .
Excel


32
-

.
!

In p u tB o x ComboBox
In p u tB o x


( VBA)
, , . -
,
-
,

-




(Undo)
, (Insert Record), - (Restore)
(Delete Record) (New Record)
, - ,

(*, ? #)
Excel

VBA,
VBA
VBA
-

(Enhanced Data Form)


. Excel 97
-.
;
.
UserForm ,
VBA ( )
- h t t p : //s p re a d s h e e tp a g e .

15.

513

E nhanced D ata Form


Enhanced
Data Form. .
1. d a ta fo rm 3 .xlam ,
-.
2. Excel <Alt+TI>
(Add-Ins).
3. (Add-Ins) (Browse)
d a t a f . xlam , . 1.
,
1^ DataForm^J-Walk Enhanced DataForm.
.


, U s e r Form (. 15.30). XIX .
, .

15

10

13

14

11

12

. 15.30.
UserForm

( C o m m a n d B u tto n )
. , ,
. Com boBox ()
(3x3, 4x4 5x5).
(New) ,
(Label) .

(. ).
VBA .
.
C o m m a n d B u tto n U s e rF o rm
, VBA.
Com boBox.

514

IV.


.
, .

, V i s i b l e
C o m m a n d B u tto n F a ls e .

(M ouseU p),
.

C om m andB utton,
( C a p tio n ) . .
-


- s l i d i n g t i l e p u z z le .x ls m .

U s e rF o rm
Excel. . 15.31
U s e rF o rm .
:

Jokers Wild Jacks Or Better;

, ( );

( );

, U s e rF o rm .

.
-


- v id e o p o k e r . x ls m .
- J o k e r 's Wild

**
***
**oi

!* 1

*
.

. 15.31.

,
. - .

...
16

Excel VBA
17


18


19

Excel
2 0


21



Excel VBA
...

Excel
VB

Text Tools
Excel

Excel.

Excel
,
.
(, , ). ,
(, ).
Excel ( ) ,
Excel, .
Excel , .
. ,
, ,
, .
.
, Excel ,
.
, .
. , , , , Excel 2010
, ( )

518

V.

. ,
Excel .
,
.
VBA,
.
Sub T o g g le P a g e B re a k s ()
W ith A c tiv e S h e e t
. D is p la y P a g e B re a k s = N ot
End W ith
End Sub

. D is p la y P a g e B re a k s

,
. ,
,
.
, Excel
.

VBA
1992 Excel 5
Microsoft, VBA. - Excel 5
VBA, Excel
(XLM) Excel
, .
VBA Excel,
VBA. ,
, .
Power Utility Excel.
VBA .

VBA ,
.

VBA.
,
.

VBA Excel,
.

Excel . ,
, .
,
.


Excel ,
, .

16. Excel VBA

519

, ?
.
- Excel.
, ,
.
.
, . ,
, ,
.
.
,
.
, Excel.
, Excel,
.

. , ,
.
.
VBA. ,
, .
.
, ,
.

Text Tools
Excel,
Power Utility . Text Tools ( )
.
, :

( ,
);
, ;
, ;
( );
( ,
, , ).
. 16.1 Text Tools .

520

V.

,
[
4 |
!

.-..I ...... I...... :.


> ] 1 , *2

? 2 .

. 16.1. Text Tools


-

Text Tools -.
,
Power Utility . t e x t t o o l s ,
x la m Excel.
: rnaBHafl^Text Tools Utilities^Text Tools.
VBA ,
, , .


Excel ,
. ,
(), ( ),
() ..
, , ,
. , Excel
. ,
, .
, ....


.
, .


, .

, Excel.
, ,
, Excel.

16. Excel VBA

521

.
(
) ,
.
,
.
, .
. ,
, .
,
.
.
.

.


Text Tools XLAM.
XLSM.
, , .
Text Tools .
. .
,
.
VBA.
. ,
. ,
, .
U serForm . . ,
, Use Form.

,
. (.
RibbonX ). ,
Excel VBA.

, t e x t
.

to o ls .x la m ,

1. ^ Excel (File^Excel Options).


2. Excel (Excel Options) (Add-ins).

V.

522

3. (Manage)
Excel (Excel Add-Ins) (Go to),
(Add-Ins).
4.
(Add-Ins Available), .
, (Browse)
x l a m x l a .
5. .
, .
. 1-3 ,
<Alt+TI> . Excel.


Text Tools RibbonX,
: =>Utilities^Text Tools.
S t a r t T e x t T o o l s , S h o w T e x tT o o ls D ia lo g .

( S t a r t T e x t
S h o w T e x t T o o ls D ia lo g )
RibbonX .

T o o ls


(Apply), .
. .
.
.
.
.
, Excel
. .


,
.
.
. 16.2 U s e rF o rm Text Tools.
, U se r F o rm .
, .
.

(Operation).
.

*!. ,
.

16. Excel VBA

523

. 16.2. UserForm Text Tools

2 . .
.
. .
(Help). CommandButton,
.
.
(Close).
.

(Apply). Command
B u tto n ,

.
. L a b e l
Frame.
. .
. 16.3
. .

Modulel
M o d u le l , ,
, , .

, M od u lel.
Public C o n s t APPNAME As S t r i n g = " T e x t T o o ls "
Public C o n s t PROGRESSTHRESHOLD = 2 0 0 0
Public U s e r C h o ic e s (1 To 8) As V a r i a n t ' ,
'
Public UndoR ange As R ange
'
Public U s e r S e l e c t i o n As R ange 1

V.

524

:_____________

17

:________________

*j

---

>

^1

-*

gj *

BBSS

*

1

XJ
|

4
5

J*]

See

17 ^'


17




______

' 1']!

*J
:

| * 3

11

2
3
5
6
7

Z
-J

. 16.3.

, ,
.
.
PROGRESSTHRESHHOLD ,
.
2000 .
U s e r C h o ic e s .
.
, R ange.
, .
ShowTextToolsDialog

S h o w T e x tT o o ls D ia lo g .
Sub S h o w T e x tT o o ls D ia lo g ()
Dim I n v a lid C o n t e x t As B o o le a n
I f V a l( A p p lic a t io n . V e r s io n ) < 12 Then
MsgBox " E x c e l 2007 ." , _
v b C r itic a l
E x i t Sub
End I f
I f A c tiv e S h e e t I s N o th in g Then In v a lid C o n t e x t = T ru e
I f T y p e N a m e (A c tiv e S h e e t) <> "W o rk s h e e t" Then _
I n v a lid C o n t e x t = T ru e
I f In v a 1id C o n te x t Then
MsgBox " .", v b C r i t i c a l , APPNAME
E ls e
U s e r F o r m l. Show vb M o de less
End I f
End Sub

, . Excel.
, Excel 2007, ,
Excel 2007 .

16. Excel VBA

525

, ,
, , Excel 2007.

Excel 2007, S h o w T e x t T o o ls D ia lo g ,
, .
, I n v a l i d C o n t e x t
T ru e . I f - T h e n - E ls e
(. 16.4) . ,
Show 0, (
Excel ).

. 16.4.
,
(
)

, .

(Apply).

( )
<Ctrl+Shift+T>. ,
, - .
.
, <Alt+F8>
(Macro). (Macro
Name) S h o w T e x tT o o ls D ia lo g
(Options). (Macro Options)
.

U n d o T e x t T o o ls
U n d o T e x tT o o ls (Undo)
<Ctrl+Z>.
.

UserForml
, U s e r
Form l. ,
, , t e x t t o o l s .x la m
- .

V.

526

U s e r F o r m _ I n itia liz e

.
, (
).
( C om boB oxO peration),
. :

C o m b o B o x O p e r a tio n _ C h a n g e


. . ,
, (
ComboBox), :

A p p ly B u tto n _ C lic k

(Apply).
, ,
CreateW orkR ange, ,
. (. .)
A p p ly B u tto n _ C lic k SaveForU ndo,
, . (.
.)
S e l e c t C ase
,
:

C hangeC ase;

A ddT ext;

Rem oveText;

R em oveSpaces;

R e m o v e C h a ra c te rs.
. , C hangeCase
T o g g le C ase S e n te n c e C a s e .

16. Excel VBA

527

C l o s e B u t t o n C l i c k

(Close).
.
H e l p B u t t o n C l i c k

.
( HTML- ).


,
.
, .
, A p p l y B u t t o n _ C l i c k C re a te W o rk R a n g e . R ange,
. ,
1:12. ,
C re a te W o rk R a n g e
(.. 1:12). ,
( ).
C re a te W o rk R a n g e .

Rng. R ange, .

T e x tO n ly . . T ru e ,

. .
P r iv a t e F u n c tio n C reateW orkR ange(R ng, T e x tO n ly )
1 Range
S e t C reateW orkR ange = N o th in g
'

If

R ng .C ou nt = 1 And R ng. H asF orm ula Then


S e t C reateW orkR ange = N o th in g
E x i t F u n c tio n
End I f
'

If

R ng .C ou nt = 1 Or Rng.Me C e lIs = T ru e Then


I f T e x tO n ly Then
I f N ot Is N u m e ric (R n g ( 1 ) . V a lu e ) Then
S e t C reateW orkR ange = Rng
E x i t F u n c tio n
E ls e
S e t C reateW orkR ange = N o th in g
E x i t F u n c tio n
End I f
E ls e
I f N ot Is E m p ty (R n g (1 )) Then
S e t C reateW orkR ange = Rng
E x i t F u n c tio n
End I f
End I f
End I f
On E r r o r Resume N e xt
S e t Rng = I n te r s e c t( R n g , R ng. P a r e n t. UsedRange)
I f T e x tO n ly = T ru e Then

V.

528

S e t C reateW orkR ange = R ng. S p e c ia lC e lls ( x lC o n s t a n t s , _


x lT e x tV a lu e s )
I f E r r <> 0 Then
S e t C reateW orkR ange = N o th in g
On E r r o r GoTo 0
E x i t F u n c tio n
End I f
E ls e
S e t C reateW orkR ange = R ng. S p e c ia lC e lls _
( x lC o n s ta n ts , x lT e x tV a lu e s + x lN u m b e rs)
I f E r r <> 0 Then
S e t C reateW orkR ange = N o th in g
On E r r o r GoTo 0
E x i t F u n c tio n
End I f
End I f
End F u n c tio n

C reateW orkR ange


S p e c ia lC e lls . S p e c ia l
C e lls ,
Excel (Go Special).
<F5> (Special)
(Go ).

.
. , ,
. ,
. C r e a t e
WorkRange , ,
.


Text Tools :
. ,
.
.
S a v e S e t t i n g s ,
.
G e t S e t t i n g s , .
.
HKEY_CURRENT_USER\Software\ VB and VBA P rogram S e t t i n g s \ _
T e x t T o o ls U t i l i t y \ S e t t i n g s

. 16.5 ( -
r e g e d i t . ).

Text Tools ,
( U serC h o ices).* B
, ,
.

529

16. Excel VBA


-|1)

ij;'

{ 1 Spyware Terminator
i ' i

SSPrint

i i

throocx

S S 3 Trados
l

' i VB and VBA Prograrr

Troltech
i ' i

Power Utility Pa*

El Q

SientTek

Q l Text Tools Utility


C l Settings

:
1*]( )

REG.SZ

( )

gjA ddTextlndex
g ] ChangeCaselndex

REG.SZ

REG.SZ

gjCharsToRem ovel...

REG.SZ

Q operation lnd ex

REG.SZ

gj RenraveCharacte...

REG.SZ

>}RemovePosibonI...

REG.SZ

[g]Remove Spacesln...

REG.SZ

gjTextToA dd

REG.SZ

' Get A
;

Colors

h f i | Voneer
S Q

iL .

WinRAR

i T iL

^-_^JJSER \Software\VB and VBA Program Settings\TextToote Uttity

. 16.5.

VBA
U s e rC h o ic e s .
1
U s e rC h o ic e s (1) = G etS etting(A P P N A M E , " ", _
" O p e r a t io n ln d e x " , 0)
U s e rC h o ic e s (2) = G etS etting(A P P N A M E , " ", _
"C h a n g e C a se ln d e x", 0)
U s e rC h o ic e s (3) = G etS etting(A P P N A M E , " ", _
"T e x tT o A d d ", " " )
U s e rC h o ic e s (4) = G etS etting(A P P N A M E , " ", _
"A d d T e x tIn d e x " , 0)
U s e rC h o ic e s (5) = G etS etting(A P P N A M E , " ", _
" C harsToR em oveIndex" , 0)
U s e rC h o ic e s ( 6 ) = G etS etting(A P P N A M E , " ", _
" R e m o v e P o s itio n ln d e x " , 0)
U s e rC h o ic e s (7) = G etS etting(A P P N A M E , " ", _
" R em oveS pacesIndex" , 0)
U s e rC h o ic e s ( 8 ) = G etS etting(A P P N A M E , " ", _
"R e m o v e C h a ra c te rs In d e x ", 0)
c b S k ip N o n T e x t.V a lu e = G etS etting(A P P N A M E , "c b S k ip N o n T e x t" ,

0)

, .
U s e rC h o ic e s ,
.
1
S a v e S e ttin g APPNAME, " ",
U s e rC h o ic e s (1)
S a v e S e ttin g APPNAME, " ",
U s e rC h o ic e s (2)
S a v e S e ttin g APPNAME, " ",
U s e rC h o ic e s (3)
S a v e S e ttin g APPNAME, " ",
U s e rC h o ic e s (4)
S a v e S e ttin g APPNAME, " ",
U s e rC h o ic e s (5)
S a v e S e ttin g APPNAME, " ",
U s e rC h o ic e s ( 6 )
S a v e S e ttin g APPNAME, " ",

" O p e r a tio n ln d e x " , _


"C h a n g e C a s e ln d e x ", _
"T e x tT o A d d ", _
" A d d T e x tIn d e x " , _
" C harsToR em oveIndex" , _
" R e m o v e P o s itio n ln d e x ", _
"R e m o ve S p a ce sIn d e x", _

530

V.
U s e rC h o ic e s (7)
S a v e S e ttin g APPNAME, " ",
U s e rC h o ic e s ( 8 )
S a v e S e ttin g APPNAME, " ",
c b S k ip N o n T e x t.V a lu e * -1

" R e m o v e C h a ra c te rs In d e x " , _
"c b S k ip N o n T e x t" , _


, Excel
VBA. , ,
. , Excel, ,
Text Tools, . ,
.

VBA.
Text Tools
.
, .
Text Tools M o d u lel
.
P u b lic UndoRange As Range
P u b lic U s e r S e le c tio n As Range

A p p ly B u tto n C lic k
SaveF orU ndo. .
S e t U s e r S e le c tio n = S e le c t io n
S e t UndoRange = WorkRange
T h is W o rk b o o k . S h e e ts ( 1 ) . UsedR ange. C le a r

U s e r S e l e c t i o n ,
, .
WorkRange R ange,
. .
.
F o r Each RngArea I n W orkR ange.A reas
T h is W o rk b o o k .S h e e ts ( 1 ) .Range _
( R n g A re a .A d d re s s ). F o rm u la = R ng A rea . F o rm u la
N e xt RngArea

WorkRange,
( ,
).

OnUndo. .
, .
A p p l i c a t i o n . OnUndo " " ,

"U n d o T e x tT o o ls "

Excel :
(. 16.6). UrrdoTextT o o ls , .

16. Excel VBA

531

r iv a t e Sub U n d o T e x tT o o ls ()

Dim a As Range
On E r r o r GoTo E r r H a n d le r
A p p lic a tio n .S c r e e n U p d a tin g = F a ls e
- | m - 1 di -
W ith U s e r S e le c tio n

. P a r e n t. P a r e n t . A c t iv a t e
. P a r e n t . A c t iv a t e
. 16.6. TextTools
. S e le c t

End W ith
For Each a I n U ndoR ange.A reas
a .F o rm u la = T h is W o rk b o o k .S h e e ts ( 1 ) .Range ( a .A d d r e s s ) . F orm ula
N ext a
A p p lic a tio n .S c r e e n U p d a tin g = T ru e
On E r r o r GoTo 0
E x it Sub
irr H a n d le r :
A p p l i c a t i o n . S c re e n U p d a tin g = T ru e
MsgBox " ", v b ln f o r m a t io n , APPNAME
On E r r o r GoTo 0
2nd Sub

U n d o T e x tT o o ls ,
, , .
, (
UndoRange),
( ).
V B A

. ,
, Excel .
, Excel 2007 16 100.
VBA ,
. ,
.

VBA .
-
, (Undo)
.
, .
. .
, ,
.

, VBA
Excel. ,
.
A p p l i c a t i o n OnUndo,
, , ,
. ,
.
^ undoMyMacro.

A p p lic a tio n . OnUndo " ",

"UndoMyMacro"

V.

532
-

- ,

VBA. s im p le undo d e m o .xlsm
, .
.


HTML- t e x t t o o I s . chm,
. ( H e lp B u t t o n ) ,
U s e rF o rm , .
P r iv a t e Sub H e lp B u tto n _ C lic k ()
A p p lic a t io n . H e lp (T h is W o rk b o o k . P a th & " \ "
End Sub

& " t e x t t o o l s . ch m ")

. 16.7 .
gp Text Tools Utility Help
^

(il J


T e x t T o o ls
The Text Tods utility provides several ways to mampuiabe text in selected celts without using formulas. You can:
Change the case of the text (UPPER CASE, lower case, Proper Case, Sentence case., and tOGGLE CASE).
Add new characters to the text (at the beginning, at the end, or at a specified position}.
Remove characters from the text by position (from the beginning, from the end, or beginning at a specified position).
Remove spaces from the text (dl extra spaces, or al spaces).
Remove characters o f a particular type from the text (non-pmtrig characters, alpha characters, non-numeric
characters, non-numeric and non-alpha characters, or numeric characters).

Note: This utility w i not preserve individual character formatting in your cels (e.g., superscript formatting). Formatting
applied to entire cels is not affected.

More
Using Text Tools
Tp s

zl

. 16.7. Text Tools

- ,
.
\h e lp s o u rc e .
HTML, 24
.

16. Excel VBA

533

R ibb on X
.
Excel 2007
.
.
RibbonX, ,
Custom UI Editor Microsoft Office.
Microsoft Office, .

Custom UI
Editor 22.

. 16.8 (Utilities),
. ,
Text Tools.

. 16.8.

Sub S t a r t T e x t T o o l s ( c o n t r o l As I R i b b o n C o n t r o l )
C a ll S h o w T e x tT o o ls D ia lo g
End Sub

. 16.9 RibbonX, Custom UI Editor.


to o h x b m * Custom Fditor for M itroioft Office
File

Edit

Insert

itfe ia i
0

text tools,xlam
1 |jjj| customUl.xml

<?xml ver s i o n = " l .0" encoding="UTF-8" standalone="yes"?>


ccustomUI xmlns*"h t t p ://schemas.microsoft.com/office/2006/01/customui">
<ribbon>
<tabs>
<tab idMso="TabHome">
<group id="Utilitiesl" label="Utilities">
(button id*"TextToolsButton"
label="Text Tools
onAction*StartTextTools"
imageMso "ControlsGallery"
size"large"
supertip=Displays a modeless dialog box that contains tools for
working with text in cells. Add-in distributed with 'Excel 2010 Power
Programming With VBA,' by John Walkenbach
</group>
</tab>
</tabs>
</ribbon>
!</customUI>

."/>

C :\theis\John\D ocum ents\W ord FilesXExcel 2010 Power Proyram m m g Examples ,Chapter 16\te xt tools.xlam

L n 20 C o ll .:j

. 16.9. Custom UI Editor

534

V.

,
, .
.
x la m ( ),
, , ,
.


Text Tools.
, .
.

. .


,
. .

,
Excel. ,
, ,
Excel. , Text Tools
,
(Apply). ,
Excel .


. .

(
)
, . .
, Ref E d it .

,
.
( Windows).

. .

. ,
, .
.

,
. .

,
. .


. .

. .

16. Excel VBA

535


,
.
,
. , , ,
, .
,
, .
, ,
( )
.
(ThisWorkbook). <F4> Properties
(), IsA d d in F a ls e .

Excel
Excel,
Power Utility Pack. 60 (
).
Power Utility Pack,
Excel.

...

Excel ,
.


Excel.
Excel 5 Excel (

). .
, (
).
,
,
. ,
. Excel VBA,
.
VBA
.
. 17.1 .
: , , .
.

V.

538

: ......

D.

33 488

3
4

47008

32128

34 736

928721

76 128

41536

23192

10

21736

44 834

32002

23 932

11
12

13

14
15
16

. 17.1.

-

s im p le
-.

p iv o t

t a b l e .x ls m


. 17.2 , .

.

. 17.2. , , . 17.1

. .

. .

. .

. , Sum
().
.
. ,
.

17.

539

Sub R e co rd e d M a cro ()
R a n g e ( " A l" ) .S e le c t
S h e e ts.A d d
A c tiv e W o rk b o o k . P iv o tC a c h e s . C re a te _
(S o u rc e T y p e : = x lD a ta b a s e , _
S o u rc e D a ta := " 1 ! R1C1: R13C4" ,
V e r s io n : = x lP iv o t T a b le V e r s io n l4 ) . C re a te P iv o tT a b le _
T a b le D e s t in a t io n : = " 2 ! R3C1" , _
TableN am e: = " P i v o t T a b l e l " , _
D e f a u lt V e r s io n : = x lP iv o t T a b le V e r s io n l4 )
S h e e ts ( " 2 " ) .S e le c t
C e lls ( 3 , 1 ) . S e le c t
W ith A c t iv e S h e e t. P iv o t T a b le s ( " P i v o t T a b l e l" ) _
. P i v o t F i e l d s ( " ")
. O r ie n t a t io n = x lR o w F ie ld
. P o s it io n = 1
End W ith
W ith A c t iv e S h e e t. P iv o t T a b le s ( " P i v o t T a b l e l" ) _
. P i v o t F i e l d s ( " ")
. O r i e n t a t i o n = x lC o lu m n F ie ld
.P o s itio n = 1
End W ith
A c tiv e S h e e t. P iv o t T a b le s ( " P i v o t T a b l e l ") _
.A d d D a ta F ie ld A c t iv e S h e e t. P iv o t T a b le s ( " P i v o t T a b l e l" ) _
. P i v o t F i e l d s ( " ") , " ", xlSum
W ith A c t iv e S h e e t. P iv o t T a b le s ( " P i v o t T a b l e l " ) . _
P i v o t F i e l d s ( " ")
. O r ie n t a t io n = x lP a g e F ie ld
. P o s it io n = 1
End W ith
End Sub

, , .
,
(2), . (
), .
,
. VBA
.


VBA, ,
. , -
(
).
P iv o tC a c h e s P iv o tC a c h e W o rk b o o k
( , - ).
P iv o t T a b le s P i v o t T a b l e W o r k s h e e t.
P i v o t F i e l d s P iv o t T a b l e .
P iv o t Ite m s .
C r e a t e P iv o t T a b le P iv o tC a c h e ,
, -.

540

V.

, ,
.
( ), .
Excel
, .
, ,
.

(Data). . ,

(Category). . ,
, _ , , _
, .

, ,
. , ( )
, .

.
.
, .
,
- n o r m a liz e d d a t a . x ls x .
,
.



,
, . ,
. , ,
. ,
, , .
Sub C r e a te P iv o tT a b le ()
Dim PTCache As P iv o tC a c h e
Dim PT As P iv o tT a b le
'

S e t PTCache = A c tiv e W o rk b o o k . P iv o tC a c h e s . C r e a t e ( _
S o u rc e T y p e : = x lD a ta b a s e / _
S o u rc e D a ta : =R ange( " A l " ) . C u rre n tR e g io n )
'

W o rk s h e e ts .A d d
1

S e t PT = A c t iv e S h e e t. P iv o tT a b le s .A d d ( _
P iv o tC a c h e : =PTCache, _
T a b le D e s t in a t io n : =R ange( "A 3 " ) )

17.

541


W ith
. P i v o t F i e l d s ( " ") . O r ie n t a t io n = x lP a g e F ie ld
. P i v o t F i e l d s ( " ") . O r ie n t a t io n = x lC o lu m n F ie ld
. P i v o t F i e l d s ( " ") . O r ie n t a t io n = x lR o w F ie ld
. P i v o t F i e l d s ( " ") . O r ie n t a t io n = x lD a t a F ie ld
'
. D is p la y F ie ld C a p tio n s = F a ls e
End W ith
End Sub

C r e a t e P iv o t T a b l e (
) : PTC ache .
P iv o tC a c h e C r e a t e .
, ( ).
P i v o t T a b l e Add P iv o t T a b le s .
,
O r i e n t a t i o n .
, ,
P iv o tC a c h e ( 1 1 ! R 1 C 1 : R13C4 '),
( 2 ). C r e a t e P iv o t T a b l e
, 1. ,
, .
, ,
. ,
.
, , .

,
, Excel,
. (
) :
D e fa u ltV e rs io n : = x lP iv o tT a b le V e r s io n l4

,
:
D e fa u ltV e rs io n : = x lP iv o tT a b le V e r s io n lO

,
, Excel 2007.
, Excel 2010 ,
Excel 2003. , .
, ,
.
Excel 2010
x l s , .

, Excel 2007.
, Excel
2007 Excel 2010.

542

V.

, Excel,
, (. ).
, .
IM icrosoft Excel -

| x jl

Excel.
Excel
.
| |

,
. Excel
.
: '1,

,
Excel 2007. Excel
, .
: '1,

1 1

Excel 97-2003

1 1
|
1 I

Excel 97-2003

,
.
.

Excel 97-2003

Zl1

___ ......

1
. ..


, .

,
P i v o t F i e l d s . ,
, . ,
P i v o t F i e l d s (1 )
P i v o t F i e l d s ( ' ' ) .

,
, .
, , .
.
,
.


VBA,
.
. 17.3 .
15840 .
;
. ,
. (
) . , .

17.
8

2

543

S3

N. A m erica

Data Processing

C om pe nsa tion

Salaries

2583

3165

3 I n .A m erica

Data Processing

C om pe nsa tion

B e ne fits

4496

2980

4 i N. A m erica

Data P rocessing

C om pe nsa tion

Bonuses

3768

N. Am erica

Data Processing

C om pensation

C om m issions

3133

2815

In. A m erica

Data Processing

C o m pe ns a tion

Payroll Taxes

3559

3770

7 N. Am erica

Data Processing

3029

C om pe nsa tion

T raining

3099

3559

N. A m erica

Data Processing

C om pe nsa tion

C onferences

2931

3199

9 IN .A m e rica

Data Processing

C om pe nsa tion

E n te rta in m e n t

2632

2633

10 I n . Am erica

Data Processing

F acility

Rent

2833

2508

11 N. Am erica

Data Processing

F acility

Lease

3450

2631

12 N. Am erica

Data Processing

F acility

U tilitie s

4111

13 ;N. Am erica

Data Processing

Facility

M ainten an ce

3070

2870

14 !N. Am erica

Data Processing

Facility

T ele ph on e

3827

4329

15 N. Am erica

Data Processing

F acility

O th e r

3843

16 ]N. Am erica

Data P rocessing

Su pp lie s & Services

General O ffice

2642

3218

17 |N. A m erica

Data P rocessing

S upplies & Services

C om pu te r Supplies

3052

4098

18 IN. Am erica

Data Processing

Su pp lie s & Services

Books & Subs

4346

3361

19|N . A m erica

Data Processing

S upplies & Services

O u tside Services

2869

3717

20 N. Am erica

Data Processing

S upplies & Services

O th er

3328

3116

21 N. Am erica

Data Processing

E q u ip m e n t

C om pu te r Hardw are

3088

2728

22 N. Am erica

Data Processing

E q u ip m e nt

So ftw a re

4226

2675

23 | n . Am erica

Data Processing

E q u ip m e nt

Ph otoco piers

780

3514

24 N. A m erica

Data Processing

E q u ip m e n t

T e le com m u nica tion s

3893

3664

25 N. A m erica

4380

3098

3322

Data P rocessing

E q uip m e nt

O th e r

2851

26 N. Am erica

Hum an Resources

C om pensation

Salaries

3604

3501!

27 sN. A m erica

H um an Resources

C om pensation

B e n e fits

2859

4493

28 |N. A m erica

H um an Resources

C om pensation

Bonuses

3020

2676h

29 N. Am erica

Hum an Resources

C om pensation

C om m issions

2759

39541

30 iN. A m erica
< ib c

H um an Resources

C om pensation

Payroll Taxes

3941

3106

r ije

< 1 .......

. 17.3.
-


- b u d g e t p i v o t t a b l e . x l s m .

. 17.4 ,
. , ,
.
.
1 [
2

()
(} 0

422455
422662
-0 207

433 317
413163
20154

420522 417964 411820


416522 420 672 431303
4 000
-2 708 -19483

419 331
420 828
-1497

417949 420 324


425437 417 310
-7488
3 014

841443
855872
-14429

427150 845 352


419 996 857288
7154 -11936

422057
438 990
16933

419659
430545
-10886

417260
424214
-6954

422848
411775
11073

425 313
429 275
-3962

418634
407053
11581

423038
429187
-6149

423514
410258
13256

842 714
842119
0595

418 530
415253
3 277

412134
417401
-5 267

420245 429454
420 856 416067
-0611 13 387

421678
417806
3 872

426602 418445
425271 420026
1 331
-1581

412078 411896
419 232 411739
-7154
0157

418093 419 999 418 752


414966 419 913 430 262
3127
0 086 -11510

423101
424492
-1391

421106 428 679


417478 408 644
3 628
20035

5 044 910;
5055 951
-11041
5 0514701;
5 049 2531
2 217!
5 053 364:
5053 649: |

427975
406 592
21383

419527 422 299


426827 418 223
-7 300
4 076

834 799
419 701 422 762 413 741 410972 422 746
5037 273!
w *
850421
422469 422252 421838 415125 417222
5 050 034:

^ 5 2 ^ - ^ 6 ^ < ) 5 1 ^ ^ ^ 0 9 ^ ^ ^ 5 ^ ^ 5 5 2 ^ ^ ^ ^ 6 1 |
i - :

415 298 827 954


425 287 412 284 414242 427521 420190
5 026107 s
431307 829551
411339 422 584 416132 424 041 426461
5028876
-16009
-1597
13948 -10300
-1890
3 480
-6271
-27691

414 507
414084
0423

415 179 417100


415476 414040
-0297
3 060

426 223 830563


396652 840 027
29571
-9464

429 880
426 644
3 236

424066 421539
419 595 427567
4 471
-6028

417440 838 325


412 038 852618
5 402 -14293

416146 429 216 410282


427949 423197 408 537
-11803
6 019
413 086 417919
424366 411557
11280
6 362

417782
421449
-3667

414 608 421044


425103 412853

419 949 419 881


423256 428113
-3307
-8232

5 019 764*
4 991444
*
>
w
1 745-10495
8191
5 037 638
5 079 222
-41 58 4*

:
:::...... M Zazr r ^ 'r T
. 17.4. , . 17.3
* | , !

28 320

544

V.

,
.
,
.


, .
Sub C r e a t e P iv o tT a b le ()
Dim PTcache As P iv o tC a c h e
Dim PT As P iv o tT a b le
A p p lic a tio n .S c r e e n U p d a tin g = F a ls e
1

On E r r o r Resume N e xt
A p p l i c a t i o n . D is p l a y A le r t s = F a ls e
S h e e ts ( " " ) .D e le te
On E r r o r GoTo 0
1

S e t PTcache = A c tiv e W o rk b o o k . P iv o tC a c h e s . C r e a t e ( _
S o u rce T yp e : = x lD a ta b a s e , _
S o u rc e D a ta : =R ange( " A l " ) . C u r r e n tR e g io n .A d d re s s )
1

W o rk s h e e ts .A d d
A c tiv e S h e e t.N a m e = " "
A c tiv e W in d o w .D is p la y G r id lin e s = F a ls e
'

S e t PT = A c t iv e S h e e t. P iv o tT a b le s .A d d ( _
P iv o tC a c h e : =PTcache, _
T a b le D e s t in a t io n : =R ange( " A l " ) , _
T ableN am e: = " ")
W ith PT
'


. P i v o t F i e l d s ( " " ) . O r i e n t a t i o n = x lP a g e F ie ld
. P i v o t F i e l d s ( " " ) . O r ie n t a t io n = x lP a g e F ie ld
. P i v o t F i e l d s ( " " ) . O r ie n t a t io n = x lR o w F ie ld
. P i v o t F i e l d s ( " " ) . O r ie n t a t io n = x lC o lu m n F ie ld
. P i v o t F i e l d s ( " " ) . O r ie n t a t io n = x lD a t a F ie ld
. P i v o t F i e l d s ( " " ) . O r ie n t a t io n = x lD a t a F ie ld

. D a t a P iv o t F ie ld . O r ie n t a t io n =
1

'

x lR o w F ie ld

,

. C a lc u la t e d F ie ld s . Add " " , " = - "
. P i v o t F i e l d s ( " " ) . O r ie n t a t io n = x lD a t a F ie ld

. D ataB odyR ange. Num berForm at = " 0 ,0 0 0 "

'

.T a b le S ty le 2
'

= "P iv o tS ty le M e d iu m 2 "

. D is p la y F ie ld C a p tio n s = F a ls e

17.


. P i v o t F i e l d s ( "
. P i v o t F i e l d s ( "
. P iv o t F ie ld s ( "
End W ith
!nd Sub

545

") . C a p tio n = " "


") . C a p tio n = " "
" ) . C a p tio n = 11 "

1
C r e a t e P iv o t T a b l e , . P iv o tC a c h e ,

P iv o tC a c h e . :

();

();

;
;
;
.
, O r i e n t a t i o n D a t a P i v o t F i e l d
x l R o w F ie l d :
.D a t a P iv o t F ie ld . O r ie n t a t io n = x lR o w F ie ld

,
(. 17.5).
, ,
.
A d d C a l c u l a t e d F i e l d s
,
.
.


^^^,
^ (PivotTable^Options^Calculations^Fields, Items &
Sets^Calculation Field)
(Insert Calculated Field).

18 3ak. 3 1 0 7

546

V.

D a t a B o d yR a n g e (
);

0
0
0

0

(
1^
1^ /1^
(PivotTable Toos^Options^Show/Hide1^
Field Headers);

,
. ,
(Sum of Budget)
(Budget). ,
. Excel
,
, , ,
, .

0
0
0


:
V



.

(
).

'

. 17.5.

,
, .
(. 17.6), 150 .
, ,
1 5 14 .
-

-
s u rv e y d a ta p iv o t

ta b le s .x ls m .

. 17.7 28 , .
*
( ,
).

547

17.

*
Bonpocl
2

13
14
15
16
17
BonpoclB
19
Bonpoc20
21
22
Bonpoc23
24
25
Bonpoc26
Bonpoc27

29
30

17.6. ,

3
4

28 40

0 ,0 % 40,0%

68

45,3%

1,3%

24,0%

1 19 16

36

15

24

0,0% 21,4% | l l , 4%

16,0%

20

0 ,0%

8 , 6% |7 ,7 %

13,3%

0,0 %

2,9%

6 14

3
9

10 0 ,0 % 27%

1 70 79

0 ,0 %

1,3%

150

10
11

12

13
14

11 13

24

0,0% 15,7% | , 5%

16,0%
1 2 ,0%

15

7 11

18

0,0% 10,0% 1 , 9%

16

30 26

56

0,0% 42,9% ,9%

37,3%

100,0% 27,1% >7,8%

28,0%

17

1 19 22

18
19

1 70 79

42
10

0 ,0%

4,3% | 8,9%

6,7%

150

20
21

22

23

24

7 14

2 1

0,0% 10,0% 17,7%

25

1 1

0 ,0% 10 ,0 % | 5,1%

7,3%

16 14

30

0,0% 22,9% 17,7%

20 , 0%

29 29

58

0,0% 41,4% , 7%

38,7%

100,0% 15,7% 2,8%

20 ,0 %

26
27

28

1 11 18

29

1 70 79

30

14,0%

150

. 17.7. 28 , VBA

VBA, .
Sub M a k e P iv o tT a b le s ()
1

2 8

V.
Dim
Dim
Dim
Dim
Dim

PTCache As P iv o tC a c h e
PT As P iv o tT a b le
SummarySheet As W orksheet
ItemName As S t r in g
Row As L on g, C ol As Long, i As Long

A p p lic a tio n .S c r e e n U p d a tin g = F a ls e


On E r r o r Resume N ext
A p p l i c a t i o n . D is p l a y A le r t s
S h e e ts ( " " ) .D e le te
On E r r o r GoTo 0

= F a ls e

S e t SummarySheet = W o rk s h e e ts .A d d
A c tiv e S h e e t.N a m e = " "
-

S e t PTCache = A c tiv e W o rk b o o k . P iv o tC a c h e s . C r e a t e ( _
S o u rc e T y p e : = x lD a ta b a s e , _
S o u rc e D a ta : = S h e e ts ( " " ) . R a n g e ( " A l" ) . _
C u rre n tR e g io n )
Row = 1
F o r i = 1 To 14
F o r C ol = 1 To 6 S te p 5 '2
ItemName = S h e e ts ( " " ) . C e l l s (1 ,
W ith C e lls (R o w , C o l)
.V a lu e = ItemName
.F o n t.S iz e = 16
End W ith

+ 2)

S e t PT = A c t iv e S h e e t. P iv o tT a b le s .A d d ( _
P iv o tC a c h e : =PTCache, _
T a b le D e s tin a tio n := S u m m a ry S h e e t. C e lls (R o w + 1, C o l) )

I f C ol = 1 Then '
W ith P T .P iv o tF ie ld s (Ite m N a m e )
. O r ie n t a t io n = x lD a t a F ie ld
.Name = " "
.F u n c tio n = x lC o u n t
End W ith
E ls e '
W ith P T .P iv o tF ie ld s (Ite m N a m e )
. O r i e n t a t i o n = x lD a t a F ie ld
.Name = " "
.F u n c tio n = x lC o u n t
. C a lc u la t io n = x lP e rc e n tO fC o lu m n
.N um berForm at = " 0 . 0 %"
End W ith
End I f
P T .P iv o tF ie ld s ( I te m N a m e ) .O r ie n ta tio n = x lR o w F ie ld
P T . P iv o t F ie ld s ( " " ) . O r ie n t a t io n = x lC o lu m n F ie ld
PT. T a b le S ty le 2 = " P iv o tS ty le M e d iu m 2 "
P T .D is p la y F ie ld C a p tio n s = F a ls e
I f C ol = 6 Then

17.
'

549


PT. ColumnGrand = F a ls e
PT. D ataB odyR ange. C o lu m n s( 3 ) . F o r m a tC o n d itio n s . _
A d d D a ta b a r
W ith p t . D ataB odyR ange. C olu m n s( 3 ) . F o r m a tC o n d itio n s (1)
. B a r F illT y p e = x l D a t a B a r F i l l S o l i d
. M in P o in t. M o d ify n e w ty p e : = x lC o n d itio n V a lu e N u m b e r, n e w v a lu e := 0
.M a x P o in t.M o d ify n e w ty p e : = x lC o n d itio n V a lu e N u m b e r, n e w v a lu e := l
End W ith
End I f
N ext C ol
Row = Row + 10
N ext i

'


W ith R a n g e ("A :A ,F :F ")
.R e p la c e " 1 " , " "
.R e p la c e " 2 " , "He "
.R e p la c e " 3 " , " "
.R e p la c e " 4 " , " "
.R e p la c e " 5 " , " "
End W ith
End Sub

,
P iv o tC a c h e .
. Col
1 6 S te p .
. :
( );
;
;
,
.
Row .
F .
, .



. , ,
? . 17.8.
B2:F14
. 1: 48 ,
. ,
.
Excel ,
VBA.
U se rF o rm , . 17.9.
, .

550

V.

. 17.8. ()
()

(1 ):

$7

RSSS[ !

: 51892

; 60

: 2 490 810 |

100%

JJsL
. 17.9.
-

-
r e v e r s e p i v o t ta b le . x ls m .
*

U serForm VBA
R e v e r s e P iv o t :
C a ll R e v e rs e P iv o t(S u m m a ry T a b le , O u tp u tR a n g e ,

c b C re a te T a b le )

17.

551

S u m m a ry T a b le . R ange, .

O u t p u t R ange. R ange,

c b C r e a t e T a b le . ( C h e c k b o x ) U s e rF o rm .

.
( - 1 ) * ( - 1 ),
.
R e v e rs e P i v o t .
Sub R e v e rs e P iv o t(S u m m a ry T a b le As Range, _
O utputR ange As Range, C re a te T a b le As B o o le a n )
Dim r As Long, As Long
Dim OutRow As Long, O u tC o l As Long
'
OutRow = 2
A p p l i c a t i o n . S c re e n U p d a tin g = F a ls e
O u tp u tR a n g e . R ange( " A l : C3") = A r r a y ( " ", " 2 ", _
" ")
For = 2 To S um m aryT able. Rows. C ount
F o r = 2 To Sum m aryTable. C olu m n s. C ount
O u tp u tR a n g e . C e lls (O u tR o w , 1) = S um m aryTable. C e l l s ( r , 1)
O u tp u tR a n g e . C e lls (O u tR o w , 2) = S um m aryTable. C e l l s (1, c)
O u tp u tR a n g e . C e lls (O u tR o w , 3) = S um m aryTable. C e l l s ( r , c)
OutRow = OutRow + 1
N e xt
N ext r
' ?
I f C re a te T a b le Then _
A c t iv e S h e e t. L is t O b je c ts .A d d x lS rc R a n g e , _
O u tp u tR a n g e . C u rre n tR e g io n , , x lY e s
End Sub

.
, ,
. O utR ow
. ,
. Add L i s t O b j e c t s .

...




VBA


ChartOb j e c t s C h a r ts

Excel .

554

V.


Excel .
.
Excel ,
. , VBA
, Excel
.
VBA, .
.
Excel.

Excel 2010 , . ,
. ,
,
. .


Excel .

.
.

.
.
^ (Insert^Charts).
VBA. .


<Alt+F1>. Excel
, ,
.
<F11>.

.
,
C h a r t . VBA A c t i v e C h a r t
C h a r t ( ). ,
( W o rk b o o k ,
A c t iv e W o r k b o o k ).
. ,
Name C h a r t :
MsgBox A c tiv e C h a rt.N a m e

,
.

18.

555

,
VBA.



, . ,
Excel 2007, ,
, :
- ,
. , Excel 2010. -,
Excel 2010 .
, , ,
Excel 2007.

. ,
.

VBA, , ,
, Excel 2007.
Excel.



. , .
, ,
. A p p l i c a t i o n (Excel). A p
p l i c a t i o n W o rk b o o k , W o r k s h e e t.
C h a r t O b j e c t , C h a r t .
C hart C h a r t T i t l e , C h a r t T i t l e T e x t,
, .
.
A p p lic a tio n
Workbook
W o rkshe et
C h a rtO b j e c t
C h a rt
C h a r t T it le

VBA , , . ,
,
VBA.
W orksheets( " 1 ") . C h a rtO b j e c t s (1) . C h a r t . C h a r t T i t l e . _
.T e x t = " "

,
W o rkb o o k.

556

V.

( C h a r tO b j e c t s ) 1 . C h a r t C h a r t ,
C h a r t T i t l e C h a r t T i t l e .
T e x t .
, ,
. ,
( (Chart Title)),
:
W o rk s h e e ts ( " 1 ") . C h a r t O b je c ts ( 1 ) . C h a r t . H a s T it le = T ru e

,
W o r k s h e e t C h a rtO b j e c t . ,
.
A p p lic a tio n
W orkbook
C h a rt
C h a r t T it le


:
S h e e ts ( " 1 " ) . C h a r t T i t l e . T e x t = " "

, C h a r t
C h a rtO b j e c t . , ,
C h a rtO b j e c t ,
W o rk b o o k .
,
.
MsgBox T yp e N a m e (S h e e ts( " 1 " ) . C h a r t O b je c ts ( 1 ) .C h a r t)
Msgbox T ype N a m e (S h e e ts( " 1 "))


C hartO b j e c t s Shapes, .
( C h a rts .)
c h a r ts s h e e ts ,


C h a rtO b j e c t S hape. ,
S h a p e s.
A d d C h a r t S h a p e s.
:
A c t iv e S h e e t . S h a p e s.A d d C h a rt

A d d C h a r t ( ).

. . ,
, .
(, x l A r e a , x lC o lu m n C lu s t e r e d ..).

18.

557

Left. (

). , Excel
.
. (
). , Excel
.
Width. ( ).

, Excel 354 .
Height. ( ).

, Excel 210 .

. ,
M yChart.
Sub C r e a te C h a r t()
Dim M yC hart As C h a rt
Set M yC hart = A c t iv e S h e e t. S h a p e s .A d d C h a r t( x lL in e M a r k e r s ) . C h a rt
End Siib

, , ,
S e tS o u rc e D a ta
. .
, . 18.1.
Sub C re a te C h a rt ()
Dim M yC hart As C h a rt
Dim DataRange As Range
Set DataRange = A c t iv e S h e e t. R ange( " A l : C7")
Set M yC hart = A c t iv e S h e e t. S h a p e s .A d d C h a rt. C h a rt
M yC h a rt. S e tS o u rc e D a ta S o u rc e : =DataRange
End Sub

652
693

975

789

906

1084

923

785 1

____________8731__________832

901

---

1200 -

723

I
J
11I 11
1I 11

------

... 1

1I
3

17

18

20

f c - l 1

--------

1----------------------------- ~ -

21

22

* ! .

2 . .

... .:

.aL_. ...

...............

L
J

mmJ

. 18.1. VBA

558

V.

A d d C h a rt shapes (
) ,
Excel 2007.
Add C hartO b j e c t s . ,
A d d C h a rt shapes,
, ,
, C ha rtT ype .
L e f t , Top, W id th H e ig h t .
Add C hartO b j e c t s
.
Sub C r e a te C h a r t2 ()
Dim M yC hart As C h a rt
Dim DataRange As Range
S e t DataRange = A c t iv e S h e e t. R an ge ( " A l : C7")
S e t M yC hart = A c t iv e S h e e t. C h a r tO b je c ts .A d d (10,
M y C h a rt. S e tS o u rc e D a ta S o u rc e : =DataRange
M y C h a rt. C h a rtT y p e = x lC o lu m n C lu s te re d
End Sub

10,

354,

2 1 0 ) . C h a rt


,
.
, A d d C h a r t s .
, ,
, .
,
.
Sub C re a te C h a r tS h e e t()
Dim M yC hart As C h a rt
Dim DataRange As Range
S et DataRange = A c t iv e S h e e t. R ange( " A l : C7")
S e t M yC hart = C h a rts .A d d
M y C h a rt. S e tS o u rc e D a ta S o u rc e : =DataRange
A c t iv e C h a r t . C h a rtT y p e = x lC o lu m n C lu s te re d
End Sub

. 18.2.

VBA
.
VBA A c t i v a t e .
VBA, ,
<Ctrl>.
A c t iv e S h e e t. C h a r t O b je c ts ( " 1 ") . A c t iv a t e

, :
S h e e ts ( " !" ) . A c t iv a t e

18.

559

. 18.2.

Shape.
A c t iv e S h e e t . S h a p e s ( " 1 " ) . S e l e c t

,
A c t i v e C h a r t . ,
. ,
.
MsgBox A c t iv e C h a r t .N a m e

VBA,
. , ,
( 1

).
, .
Sub M o d if C h a r t l ()
A c t i v e S h e e t . C h a r tO b j e c t s ( " 1 ") . A c t i v a t e
A c t iv e C h a r t . C h a rtT y p e = x lA r e a
End Sub
Sub M o d i f y C h a r t 2 ()
A c t i v e S h e e t . C h a r t O b j e c t s ( " 1 " ) . C h a r t . C h a r t T y p e
End Sub

= x lA r e a


,
( ). .
^^
(Chart Tools^Design^I^cation^Move Chart).
(Move Chart)
(New Sheet) .

VBA. , C h a r t O b je c t ,
1 , .

560

V.

Sub M o v e C h a rtl()
S h e e ts ( " 1 " ) . C h a r t O b je c ts ( 1 ) .C h a r t. _
L o c a tio n x lL o c a tio n A s N e w S h e e t, " "
End Sub

,
,
1.
Sub M o v e C h a rt2 ()
C h a r t s ( " ") _
.L o c a tio n x lL o c a t io n A s O b je c t, " 1 "
End Sub


L o c a tio n .
?

C hartO b j e c t . c h a r t
C hartO b j e c t. ,
. 1
. VBA .
? A c t iv e S h e e t. S h a p e s( 1 ) .Name
1

? A c t iv e S h e e t . C h a r t O b je c ts ( 1 ) .Name
1

? A c t iv e C h a r t . Name
1 1

? A c t iv e s h e e t . C h a r t O b je c ts ( 1 ) .C h art.N am e
1 1

, c h a r t,
c h a r t, c h a r t o b j e ct.
VBA,
Out of memory .
A c t iv e s h e e t . C h a r t O b je c ts ( 1 ) . C hart.N am e = ""

C hartO b j e c t?
, (Name) (
). , . ,
(
).
(Chart Name), ^^ (Chart Tools^Layout^Properties).
( C hartO b j ect),

C hartO b j e c t. , Excel
C hartO b j e c t. ,
, !.
? . , VBA,
, , ,
-.

18.

561


A c t i v a t e
. , .. . ?
,
D e s e le c t.
A c tiv e C h a rt.D e s e le c t

, Excel.

, .
R ange Se l e c t i o n A c tiv e Window
,
.
A ctiveW indow . R a n g e S e le c tio n . S e le c t

, ,
VBA, .



( ). , ,
.
: VBA ,
?
.
TypeName S e l e c t i o n :
T ypeN am e(S election)

= " C h a r t"

T ru e.
, C h a rt. ,
S e r i e s , C h a r t T i t l e , Legend,
PlotA rea ..
, ,
A ctiveC hart N o th in g . , ,
. ,
. .
I f A c tiv e C h a r t I s N o th in g Then
MsgBox " ."
E x it Sub
Else
1
End I f

VBA.
C h a rt I s S e l e c te d , , True,
, F a ls e , .
P rivate F u n c tio n C h a r t ls S e le c t e d () As B o o le a n
C h a r tls S e le c te d = N o t A c t iv e C h a r t I s N o th in g
End F u n c tio n

562

V.


C h a r t O b je c t s C h a r ts

C h a r t O b je c t . C h a r t O b j e c t
! :
A c t i v e S h e e t . C h a r t O b j e c t s ( " ]." ) . D e l e t e

C h a r t O b je c t
D e l e t e C h a r t O b je c t s .
A c t i v e S h e e t . C h a r tO b j e c t s . D e l e t e

S h a p e s .
1 :
A c t i v e S h e e t . S h a p e s ( " 1 " ) . D e l e t e

(
).
Dim shp as Sh ap e
F o r E a c h shp I n A c t i v e S h e e t . S h ap es
s h p . D e le te
N e x t shp

(
). 1:
C h a r t s ( " 1 " ) . D e l e t e


:
A c t iv e W o r k b o o k . C h a r t s . D e l e t e

,
. 18.3.
. ,
. ,
.
A p p l i c a t i o n . D i s p la y A le r t s = F a ls e
A c t iv e W o r k b o o k . C h a r t s . D e l e t e
A p p lic a t io n .D is p la y A le r t s = T ru e
I M icrosoft Excel


, , , , ".

. 18.3.


.
,
.

18.

563

ChartOb j e c t s
C h art.
Sub F o rm a tA l1C h a r t s ()
Dim C htO bj As C h a rtO b je c t
F or Each C htO bj I n A c t iv e s h e e t . C h a rtO b je c ts
W ith C h tO b j.C h a rt
. C h a rtT yp e = x lL in e M a r k e r s
.A p p ly L a y o u t 3
.C h a r tS t y le = 12
. C le a rT o M a tc h S ty le
. S e tE le m e n t m s o E le m e n tC h a rtT itle A b o v e C h a rt
. S e tE le m e n t m soElem entLegendNone
. S e tE le m e n t m s o E le m e n tP rim a ry V a lu e A x is T itle N o n e
. S e tE le m e n t m s o E le m e n tP rim a ry C a te g o ry A x is T itle N o n e
. A x e s (x lV a lu e ).M in im u m S c a le = 0
. A x e s (x lV a lu e ).M a x im u m S c a le = 1000
End W ith
N ext C htO bj
End Sub
-


- fo rm a t a l l c h a r ts .x ls m .

. 18.4 ,
. . 18.5
F o r m a tA llC h a r ts .

195

200

205

210

215

220

225230 235240

. 18.4.

564

V.

. 18.5.

, F o r m a tA llC h a r ts, .
Sub F o rm a tA H C h a rts 2 ()
Dim c h t as C h a rt
F o r Each c h t I n A c tiv e W o rk b o o k . C h a rts
W ith c h t
.C h a rtT y p e = x lL in e M a r k e r s
. A p p ly L a y o u t 3
.C h a r tS t y le = 12
. C le a rT o M a tc h S ty le
. S e tE le m e n t m s o E le m e n tC h a rtT itle A b o v e C h a rt
.S e tE le m e n t m soElem entLegendNone
. S e tE le m e n t m s o E le m e n tP rim a ry V a lu e A x is T itle N o n e
. S e tE le m e n t m s o E le m e n tP rim a ry C a te g o ry A x is T itle N o n e
. A x e s ( x lV a lu e ) . M inim um S cale = 0
. A x e s ( x lV a lu e ) . MaximumScale = 1000
End W ith
N e xt c h t
End Sub


ChartO b j e c t ,
( L e f t ) (W idth H e ig h t) .
VBA. Excel
( ^^ (Chart Tools^Format^Size)),
H e ig h t W idth, * L e ft.
ChartOb j e c t ,
.
ChartOb j e c t , .

565

18.
Sub S iz e A n d A lig n C h a r ts ()
Dim W As Long, H As Long
Dim T o p P o s itio n As Long, L e f t P o s i t i o n As Long
Dim C htO bj As C h a rtO b je c t
Dim i As Long, NumCols As Long
I f A c tiv e C h a r t I s N o th in g Then
MsgBox " "
E x i t Sub
End I f
1

On E r r o r Resume N e x t
NumCols = In p u tB o x ( " ? ")
I f E rr.N u m b e r <> 0 Then E x i t Sub
I f NumCols < 1 Then E x i t Sub
On E r r o r GoTo 0
'

W = A c t iv e C h a r t . P a r e n t.W id th
H = A c t iv e C h a r t . P a r e n t.H e ig h t
1

T o p P o s itio n = 100
L e f t P o s it io n = 20
For i = 1 To A c t iv e S h e e t. C h a r t O b je c ts . C ount
W ith A c t iv e S h e e t. C h a r t O b je c t s ( i)
.W id th = W
.H e ig h t = H
. L e f t = L e f t P o s i t i o n + ( ( i - 1) Mod NumCols) * W
.Top = T o p P o s itio n + I n t ( ( i - 1) / NumCols) * H
End W ith
Next i
End Sub

,
, .
I n p u tB o x .
L e f t .
-

\jjiy

s iz e and a l i g n c h a r ts .x ls m .


Excel .
-.
,
. VBA.
E x p o r t C h a r t
GIF-.
Sub SaveC hartAsG IF ()
Dim Fname as S t r in g
I f A c tiv e C h a r t I s N o th in g Then E x i t Sub

566

V.

Fname = T h is W o rk b o o k . P a th & " \ " & A c tiv e C h a rt.N a m e & " . g i f "
A c t iv e C h a r t . E x p o rt F ile N a m e := Fname, F ilte r N a m e : = "G IF "
End Sub

. 18.6. VBA

F i lt e r N a m e "JP E G " "P N G ".


GIF PNG .
, E x p o r t ,
.
Office ( Excel).



HTML. ,
GIF PNG , ,
( ^
^>() (HomeMClipboardMPasteMPaste (U)).
VBA, .
.
Sub S a v e A llG r a p h ic s ()
Dim F ileN am e As S t r in g
Dim TempName As S t r i n g
Dim DirName As S t r i n g
Dim g F i l e As S t r in g
FileN am e = A c tiv e W o rk b o o k . F ullN am e
TempName = A c tiv e W o rk b o o k . P a th & " \ " & _
A ctive W o rkb o o k.N a m e & " g r a p h ic s .h tm "
DirName = L eft(T em pN am e, Len(TempName) - 4)
'
1

& "_ "

HTML,

567

18.
A c tiv e W o rk b o o k . Save
A c tiv e W o rk b o o k . SaveAs F ile N a m e : =TempName, F ile F o r m a t: = x lH tm l
A p p l i c a t i o n . D is p la y A le r t s = F a ls e
A c tiv e W o rk b o o k . C lo se
W o rkbo oks. Open F ileN am e
'

HTML-
K i l l TempName

1 HTML, * . PNG
g F ile = D ir(D irN a m e & \ * . * " )
Do W h ile g F i l e <> " 11
I f R i g h t ( g F i le , 3) <> "p n g " Then K i l l DirNam e & " \ "
g F ile = D i r
Loop
'
S h e ll " e x p lo r e r . e x e " & D irN am e, vbN orm alF ocus
End Sub

& g F ile

.
HTML- ,
. HTML- ,
( ).
, , PNG.
, S h e l l .
/%


- e x p o rt a l l g ra p h ic s .xlsm .


S o u rc e D a ta ,
. ,
. V a lu e s
S e r ie s . S e r i e s X V alues,
.
%

v a lu e s ,
x v a lu e s (.
).

, () ,
(SERIES).
. ,
; ,
. .

=( _, _ , , , )

568

V.

_ (). , ,

. ,
.
. , Excel
, (, 1).

_ (). ,
. , Excel
, 1.
.
. .
,
( )
.

(). ,

. .
.
.
, .

(). ,
. ,
. ,
. .

( ). ,
.
.
.
, .

= ( 1 ! $ $ 1 # , 1 ! $ $ 2 : $ $7 , 1 )

. ,
, .
2: 5:7.
= (,, ( 1 ! $ $ 2 : $ $ 3 , 1 ! $ $ 5 : $ $ 7 ),1 )

.
( ), Excel
, .
= ( ! ! $ $ 1 , , b u d g e t . x l s x ! C u r r e n tD a ta , 1 )



. 18.7 , ,
. ,
.

18.

569


60%
50%
40%
30%
20%

Mouse Pads Inc.

10%

0%

_3_
4

I]

12%

14%

21%

21%

15%

18%

24%

29%

14%

9%

11%

32%

31%

17%
45%

6
7

32%

1%

5%

9%

40%

18%

32%

32%

12%

8%

2%

6%

32%

43%

17%

10

3%

4%

21%

39%

33%

11

1%

9%

18%

33%

39%

12

38%

24%

21%

12%

5%

13

16%

19%

32%

21%

12%

5%

9%

32%

38%

16%

8 -
A

14 -

. 18.7. ,

1 . S e l e c tionChange ,
.
( 1 ).
Private Sub W o rk s h e e t_ S e le c tio n C h a n g e (B y V a l T a rg e t _
As E x c e l.R a n g e )
I f C he ckB o xl Then C a ll U p d a te C h a rt
End Sub

,
W o rk s h e e t_ S e le c tio n C h a n g e . ActiveX ,
U p dateC hart, .
Sub U pd ateC ha rt ()
Dim ChtO bj As C h a rtO b je c t
Dim UserRow As Long
Set C htObj = A c t iv e S h e e t. C h a r t O b je c ts (1)
UserRow = A c t i v e C e l l . Row
I f UserRow < 4 Or Is E m p ty (C e lls (U s e rR o w , 1 )) Then
C h t O b j.V is ib le = F a ls e
Else
C h tO b j. C h a r t . S e r ie s C o l l e c t i o n ( 1 ) .V a lu e s = _
R a n g e (C e lls (U s e rR o w , 2 ) , C e lls (U s e rR o w , 6 ))
C h tO b j. C h a r t . C h a r t T i t l e . T e x t = C e lls (U s e rR o w , 1 ) .T e x t
C h t O b j.V is ib le = T ru e
End I f
End Sub

V.

570

U s e rR o w , .
I f , ,
. ( .) ,
, C h a rtO b j e c t ,
( )-
, V a lu e s S e r ie s
2-6 . C h a r t T i t l e ,
.
-

-
c h a r t a c t iv e c e l l . xlsm .


VBA
V a lu e s
S e r i e s , .
VBA ,
. ,
.
, .

F orm u la.
.
. F orm ula
.

V a lu e s .
.
, .

X V a lu e s. -
. X V a lu e s
,
. X V a lu e s .

VBA, ,
, V a lu e s
S e r ie s . , X v a lu e s
, - (
).
( ), .
V a lu e s S e r ie s
R ange . ,
. ,
R an ge S e r ie s .
, ,
, .

18.

,
. .

571

= ( 1 ! $ $ 1 , 1 ! $$2 : $$4 , 1 ! $$2 : $$4 , 1)


=(/ , 1 ! $ $ 2 : $ $ 4 , 1)
=( , 1 ! $ $ 2 : $ $ 4 , 1 ! $ $ 2 : $ $ 4 , 1 )
=( " " , , 1 ! $ $ 2 : $ $ 4 , 1 )
=( , { " " , " " , " " } , 1 ! $ $ 2 : $ $ 4 , 1 )
=(, ( 1 ! $ $ 2 , 1 ! $ $ 4 ) , ( 1 ! $ $ 2 , 1 ! $ $ 4 ) , 1 )
= ( 1! $ $ 1 , 1 ! $ $ 2 : $ $ 4 , 1 ! $ $ 2 : $ $ 4 , 1 , 1 ! $ $ 2 : $ $ 4 )

, ,
. ,
,
.
.
, , .
-.
, , 2x5,
.

VBA, ( S e r ie s )
, . .

SERIESNAME_FROM_SERIES. , ,
(,
). ,
.

XVALUES_FROM_S ER I S . ,
(, ,
). , ,
.

VALUES_FROM_SERIES. ,

( ).
.

BUBBLESIZE_FROM_SERIES. ,

(,
). ,
. .
, ,
( ).
P l o t O r d e r S e r ie s .

VBA, ,
, - g e t s e r ie s ra n g e s .x ls m .
.

572

V.

VALUE S_FROM_
SERIES. .
Sub S how V alueR ange()
Dim S e r As S e r ie s
Dim x As V a r ia n t
S e t S e r = A c t iv e C h a r t . S e r ie s C o l l e c t i o n (1)
x = VALUES_FROM_SERIES(Ser)
I f x ( l ) = "Range" Then
MsgBox R a n g e (x ( 2 ) ) .A d d re s s
End I f
End Sub

x ,
VALUES_FROM_SERIES. - , .
, ,
-.
. 18.8 . .
, , ,
.

.54.

.
. 18.8.
VBA

C o n t r a c t A l I S e r i e s .
S e r i e s C o l l e c t i o n ,
XVALUE_FROM_SERIS VALUES_FROM_SERIES
. R e s i z e .
Sub C o n t r a c t A l lS e r i e s ()
Dim s As S e r ie s
Dim R e s u lt As V a r ia n t
Dim DRange As Range
F o r Each s I n _
A c t iv e s h e e t . C h a rtO b j e c t s (1) . C h a r t . S e r ie s C o lle c t io n
R e s u lt = XVALUES_FROM_SERIES(s)
I f R e s u l t (1) = " " Then

18.

573

S e t DRange = R a n g e ( R e s u lt(2 ))
I f DRange. Rows. C ount > 1 Then
S e t DRange = DRange. R e s ize (D R a n g e . Rows. C ount - 1)
s .X V a lu e s = D range
End I f
End I f
R e s u lt = VALUES_FROM_SERIES(s)
I f R e s u l t (1) = " " Then
S e t DRange = R a n g e ( R e s u lt(2 ))
I f DRange. Rows. C ount > 1 Then
S e t DRange = DRange. R e s iz e (D R a n g e . Rows. C ount - 1)
s .V a lu e s = D range
End I f
End I f
N ext s
End Sub

E x p a n d A lI S e r ie s .
.



Excel
.
. 18.9.
, ,
Excel, (
).
, , ,
.
I
1

..

156

119

209

289

194

2 10

278

274

277

156

201

177

220

218

165

161

10
5

11
12

13

14
15
16
17

200

I1

18
19
20

. 18.9.

574

V.

D a ta L a b e ls F ro m R a n g e
.
, P o i n t s
T e x t , .
Sub D a ta L a b e lsF ro m R a n g e ()
Dim DLRange As Range
Dim C ht As C h a rt
Dim i As I n t e g e r , P ts As I n t e g e r
1

S e t C ht = A c t iv e S h e e t. C h a r t O b je c ts ( 1 ) . C h a rt
'

On E r r o r Resume N ext
S e t DLRange = A p p lic a t io n . I n p u t B o x _
(p r o m p t: = " ", T y p e := 8 )
I f DLRange I s N o th in g Then E x i t Sub
On E r r o r GoTo 0
'

C h t. S e r ie s C o lle c t io n ( 1 ) . A p p ly D a ta L a b e ls _
T y p e : = x lD a ta L a b e ls S h o w V a lu e , _
A u to T e x t: = T ru e , _
LegendK ey:= Fa1s e
'

P t 6 = C h t. S e r ie s C o l l e c t i o n ( 1 ) . P o i n t s . C ount
F o r i = 1 To P ts
C h t. S e r ie s C o lle c t io n ( 1 ) . _
P o in t s ( i) . D a t a L a b e l. T e x t = D L R a n g e (i)
N ext i
End Sub
-


- d a ta la b e ls . xlsm .

. 18.10 D a t a L a b e ls F r o m
R a n g e 2:9.

.
D a ta L a b e ls F ro m R a n g e ,
, F o r - N e x t .
C h t. S e r ie s C o l l e c t i o n ( 1 ) . P o in t s ( i) . D a t a L a b e l. T e x t = _
" =" Sc
" Sc DLRange . P a r e n t. Name & " ' ! " & _
D L R a n g e ( i) .A d d r e s s ( R e fe r e n c e S ty le : =x 1R1C1)


. ,
S e rie s . ,
, Power Utility .

575

18.

..

156

119

209

289

194

210

278

274

277

156

J L
8

201

177

220

218

165

161

11

13

<|

14

16

17

200

10
12

18
19

20

. 18.10. VBA



15
( U s e F o r m ) .
GIF,
Image, U s e r F o r m .
,
-: , ,
. . 18.11.
!

J M

12%

14%

21%

21%

15%

18%

24%

29%

14%

11%

32%

31%

17%

1%

8
9
1

___________________

12

18%
________________ 2%
3%

37%
6%
4%

24%;

1% ____________3%
38%
16%


60%

19%

5%

9%

...... 1

21%

15

6%

28%

16

3%

9%

2
2
2

50% 40% 20% -

14%

10% 0%

/
/

18
20

M4L

24%
____

18%

15%

17

19

32%

5% |---------------

24%

13 -
14

7 -

Discount MousePads

/
?

/
/

21
22

23

. 18.11. , ,

576

V.

U serF orm .
Im age Com m andButton ( ). ,
, , .
Sub S h o w C h a r t()
D im U s erR o w As Long
U serR o w = A c t i v e C e l l . Row
I f U s erR o w < 2 O r I s E m p t y ( C e lls ( U s e r R o w , 1 ) ) T h e n
MsgBox " ."
E x i t Sub
End I f
C r e a t e C h a r t (U serR o w )
U s e r F o r m l . Show
End Sub

,
, .
, Show C hart C re
a t e C h a r t .
.
C r e a te C h a r t ,
. ,
.
Sub C r e a t e C h a r t ( )
D im T e m p C h a rt As C h a r t
D im C a t T i t l e s As R ange
D im S rc R a n g e As R a n g e , S o u r c e D a ta As R ange
D im FName As S t r i n g
S e t C a t T i t l e s = A c t i v e S h e e t . R a n g e ( " A 2 : F 2 ")
S e t S rc R a n g e = A c t i v e S h e e t . R a n g e ( C e l l s ( r , 1 ) ,
S e t S o u r c e D a ta = U n i o n ( C a t T i t l e s , S rc R a n g e )

C e lls (r ,


A p p l i c a t i o n . S c r e e n U p d a t in g = F a l s e
S e t T e m p C h a rt = A c t i v e S h e e t . S h a p e s .A d d C h a r t . C h a r t
T e m p C h a r t. S e t S o u r c e D a t a S o u r c e : = S o u r c e D a ta

'


W it h T e m p C h a rt
.C h a r t T y p e = x lC o lu m n C lu s t e r e d
. S e t S o u r c e D a t a S o u r c e : = S o u r c e D a t a , P l o t B y : = x lR o w s
.H a s L e g e n d = F a l s e
. P l o t A r e a . I n t e r i o r . C o l o r l n d e x = x lN o n e
.A x e s (x lV a lu e ).M a jo r G r id lin e s .D e le te
. A p p ly D a t a L a b e ls T y p e : = x lD a t a L a b e ls S h o w V a lu e , _
L e g e n d K e y : = F a ls e
. A x e s ( x lV a lu e ) .M a x im u m S c a le = 0 . 6
. C h a r t A r e a . F o r m a t. L i n e . V i s i b l e = F a ls e
End W it h

W it h A c t i v e S h e e t . C h a r t O b j e c t s (1 )
.W id t h = 30 0
.H e ig h t = 200
End W it h

'

6 ))

18.
1

577

G IF
FName = T h is W o r k b o o k . P a th & A p p l i c a t i o n . P a t h S e p a r a t o r & _
te m p . g i f "
T e m p C h a r t. E x p o r t F i l e n a m e : =FN am e, f i l t e r N a m e : = " G IF "
A c tiv e s h e e t. C h a r tO b je c ts ( 1 ) .D e le te
A p p l i c a t i o n . S c r e e n U p d a t in g = T r u e

End Sub

C r e a te C h a r t
C hartO b j e c t .
C h a rtO b je c t , S c r e e n U p d a tin g Ap
p l i c a t i o n .
Show C hart UserForm .
U s e r F o r m _ I n i t i a l i z e .
GIF, C h a r tO b je c t
GIF Image.
P r iv a te Sub U s e r F o r m _ I n i t i a l i z e ()
Dim FName As S t r i n g
FName = T h is W o r k b o o k . P a th & _
A p p li c a t io n . P a th S e p a ra to r & " te m p .g if"
U s e r F o r m l. I m a g e l . P i c t u r e = L o a d P ic tu r e (F N a m e )
End Sub


- c h a r t i n u s e r f o r m . x l s m .


Excel , . ,
A c t iv a t e . C a l c u l a t e
, .
VBA, , .

19.
. 18.1 .
1 8 .1 . C h a r t

Activate


.


.


BeforeDoubleClick

BeforeRightclick

C a lc u la te

19 . 3 1 0 7

578

V.
. 18.1

D e a c t iv a t e


,
,

MouseDown
MouseMove
Mouseup
Res i ze
S e le c t
S e rie s C h a n g e

c h a r t
,
, VBA C h a r t .
, C h a r t .
C h a r t
P r o c e d u r e ,
(. 18.12).

,
. ,
,
, .
.

,
, .
, ,
.

579

18.

C h a rt_ A c t i v a t e . .

C h a r t_ D e a c t iv a t e . .

C h a r t_ S e l e c t . .
-


- e v e n ts - c h a r t s h e e t , x ls m .
C h a r t_ A c ti v a t e .
P r i v a t e Sub C h a r t _ A c t i v a t e ()
Dim msg As S t r i n g
msg = " , " & A p p l i c a t i o n . U serN am e & v b C r L f & v b C r L f
msg = msg & " 6 "
msg = msg & " 1 - 3 . " & v b C r L f
& v b C rL f
msg = msg & _
" , ."
MsgBox msg, v b l n f o r m a t i o n , A c t iv e W o r k b o o k . Name
E n d .Sub

,
(. 18.13).

800
700

600

2
3

1 500
z 400

z8

300
200
100

. 18.13.

C h a r t_ A c tiv a te ,

C h a r t_ D e a c t iv a t e ,
, .
P r iv a t e Sub C h a r t _ D e a c t i v a t e ()
Dim msg As S t r i n g

580

V.

msg = " ."


M sgBox m sg, , A c tiv e W o rk b o o k .N a m e
End Sub

C h a r t_ S e l e c t , ,
.
P r i v a t e Sub C h a r t _ S e le c t ( B y V a l E le m e n tID As L o n g , _
B y V a l A r g l As L o n g , B y V a l A rg 2 As L o n g )
D im I d As S t r i n g
S e le c t Case E le m e n tID
Case x l A x i s : I d = " "
Case x l A x i s T i t l e : I d = " "
Case x lC h a r t A r e a : I d = " "
Case x l C h a r t T i t l e : I d = " "
Case x l C o r n e r s : I d = " "
Case x l D a t a L a b e l : I d = " "
Case x lD a t a T a b le : I d = " "
Case x lD o w n B a r s : I d = " "
Case x l D r o p L i n e s : I d = " " .
Case x l E r r o r B a r s : I d = " "
Case x l F l o o r : I d = " "
Case x l H i L o L i n e s : I d = " / "
Case x lL e g e n d : I d = " "
Case x l L e g e n d E n t r y : I d = " "
Case x lL e g e n d K e y : I d = " "
Case x l M a j o r G r i d l i n e s : I d = " "
Case x l M i n o r G r i d l i n e s : I d = " "
Case x l N o t h i n g : I d = " "
Case x l P l o t A r e a : I d = " "
Case x lR a d a r A x is L a b e ls : I d = " "
Case x l S e r i e s : I d = " "
Case x l S e r i e s L i n e s : I d = " "
Case x lS h a p e : I d = " "
Case x l T r e n d l i n e : I d = " "
Case x lU p B a r s : I d = " "
Case x l W a l l s : I d = " "
Case x l X E r r o r B a r s : I d = " "
Case x l Y E r r o r B a r s : I d = " "
Case E l s e : : I d = " "
End S e le c t
M sgBox " :" & I d & v b C r L f & A r g l & v b C r L f & A rg 2
E nd Sub

,
. S e l e c t , E lem entID
, . A rg l Arg2
(
). S e l e c t C ase
.

, C h a rt.
Case E ls e .

18.

581


, C h a rt
, , .
, ,
.

VBE Project () Inserts Class


Module (1^ ).
. ,
(, c l s C h a r t ) Properties ().
, .
C h a r t

,
. C h a r t
W ith E v e n ts . W ith E v e n ts,
.
.
P u b lic W ith E v e n ts

c ls C h a r t As C h a r t

,
.
c l s C h a r t ( ).
, VBA
( ). .
Dim M y C h a rt As New c l s C h a r t

, c l s C h a r t .
.
Set M y C h a r t. c l s C h a r t = A c t i v e s h e e t . C h a r t O b je c t s ( 1 ) . C h a r t

c l s C h a r t
. ,

.

,
. , .
P u b lic W ith E v e n ts

c ls C h a r t As C h a r t

W ith E v e n ts
Object () .
Object,
Procedure () .
,
.

582

V.

, C h a r t (
C h a rtO b j e c t) .
P r i v a t e Sub c l s C h a r t _ A c t i v a t e ()
MsgBox c l s C h a r t . P a re n t.N a m e & " !"
End Sub
-

- (
e v e n ts - em bedded c h a r t . x ls m ) ,
.

Chart

, , ,
. . 18.14 ,
. .
,
.

. 18.14.
.
. , .
1:4 ,
. .
,
.
, Em bC hartC lass,
VBA M o d u lel.
( (Forms)).
C h e c k B o x l_ C lic k , /
.

18.

583

, ,
R e tu rn to M a in , .
M o d u lel.
Dim S u m m aryC ha rt As New E m b C h a rtC la s s
Sub C h e c k B o x l_ C lic k ()
I f W o r k s h e e ts ( " " ) . C h e c k B o x e s ( " 1 " )

R a n g e ( " A l " ) . S e le c t
S e t S u m m a ry C h a rt.m y C h a rtC la s s = _
W o r k s h e e t s ( 1 ) . C h a r t O b je c t s ( 1 ) . C h a r t
E ls e
'
S e t S u m m a ry C h a rt.m y C h a rtC la s s = N o th in g
R a n g e ( " A l " ) . S e le c t
End I f
End Sub
Sub R e tu rn T o M a in ()
1
S h e e ts ( " " ) . A c t i v a t e
End Sub

= x lO n T hen

Sum m aryC hart,


E m b C h a rtC la ss ( , ).
(Enable Chart Events),
Sum m aryC hart,
.
Em bC hartC lass.
P u b lic W ith E v e n ts m y C h a rtC la s s As C h a r t
P r iv a te Sub m y C h a rtC la s s _ M o u s e D o w n (B y V a l B u t t o n As L o n g , _
B y V a l S h i f t As L o n g , B y V a l X As L o n g , B y V a l Y As L o n g )
Dim IDnum As L o n g
Dim a As L o n g , b As L o n g
'
IDnum, b
m y C h a r tC la s s . G e tC h a r tE le m e n t X, Y, ID num , a ,
1 ?
I f IDnum = x l S e r i e s T h e n
S e le c t Case b
Case 1
S h e e ts ( " ") . A c t iv a t e
Case 2
S h e e ts ( " " ) . A c t iv a t e
Case 3
S h e e ts ( " ") . A c t iv a t e
End S e le c t
End I f
R a n g e ( " A l " ) . S e le c t
End Sub

MouseDown, ,
, m yChartClass_M ouseDow n.
G etC hartE lem ent ,
. G e tC h a rtE le m e n t

584

V.

X Y (
myCha t 1 a s s_Mou s Down).
-


- c h a r t im a g e m a p . x ls m .


,
. ,
. , ,
.



^ (File =>Print).
( ),
. ,
.
Sub P r in t E m b e d d e d C h a r t s ()
D im C h tO b j As C h a r t O b j e c t
F o r E a c h C h tO b j I n A c t i v e S h e e t . C h a r t O b j e c t s
C h tO b j. C h a r t . P r i n t
N e x t C h tO b j
End Sub

/
Excel ,
. , . 18.15,
/ .
, .

ActiveX CheckBox . . 18.16
.
: Product_A, Product_B
.. C lic k .
, ,
.
P r i v a t e Sub C h e c k B o x l_ C l ic k ()
A c t i v e S h e e t . R a n g e ( " P r o d u c t _ A " ) . E n t ir e C o lu m n .H id d e n
N o t A c t iv e S h e e t .O L E O b je c ts ( 1 ) .O b je c t .V a lu e
End Sub

= _


- h id e a n d u n h id e s e r i e s , x ls m .

585

18.


Bl ;





300
150
00
350

300

-*
-

250

-
-

200

150

100
50
0

. 18.15.

[ |




-
-
-

. 18.16.


, Excel , .

.
(
). , ,

V.

586

,
.
.

.
^ 1^
(Home^Clipboard^Copy^Copy As Picture). ,
, (Copy Picture).
^ ^ (Home^Clipboard1^ Paste). ,
.

.
, . <F9>
.
.


X valu es V a lu e s S e r ie s . .

(. 18.17) ,
, .
, (SERIES) , .

- !

1
2

JL
4
5

6
7

JL
10

12

13
14
15
16
17
18
19
20
21
22

N V , ! ,

..................................... ........................................... R < |..............

......~~

..................

.::

. 18.17. (
)
Sub C r e a t e U n l i n k e d C h a r t ()
D im M y C h a rt As C h a r t
S e t M y C h a rt = A c t i v e S h e e t . S h a p e s .A d d C h a r t . C h a r t
W it h M y C h a rt
. S e r i e s C o l l e c t i o n . N e w S e rie s

587

18.
. S e r i e s C o l l e c t i o n ( 1 ) .Name = ""
. S e r i e s C o l l e c t i o n ( 1 ) .X V a lu e s = A r r a y ( " " , _
" ", " ")
. S e r i e s C o l l e c t i o n ( 1 ) .V a l u e s = A r r a y ( 1 2 5 , 1 6 5 , 1 8 9 )
.C h a r t T y p e = x lC o lu m n C lu s t e r e d
.S e t E le m e n t m s o E le m e n tL e g e n d N o n e
End W it h
End Sub

Excel ,
.
,
( ).
.
Sub C o n v e r t C h a r t T o P i c t u r e ()
Dim C h t As C h a r t
I f A c t i v e C h a r t I s N o t h in g T h e n E x i t Sub
I f T y p e N a m e ( A c t iv e S h e e t ) = " C h a r t " T h e n E x i t
Set C ht = A c tiv e C h a r t
C h t . C o p y P ic t u r e A p p e a r a n c e : = x l P r i n t e r , _
S i z e : = x lS c r e e n , F o r m a t: = x l P ic t u r e
A c t iv e W in d o w . R a n g e S e le c t i o n . S e l e c t
A c t i v e S h e e t . P a s te
End Sub

Sub

,
^^ (Picture Tools'^
Formats Picture Styles). . 18.18.

. 18.18.

588

V.
-

, ,
- u ni inked c h a rt s . x l sm.


.
,
. (
) . C h a rt
.

/
=> Excel (File^Excel Options)
Excel (Excel Options).
(Advanced) (Display).
(Show Chart Element
Names on Hover)
(Show Data Point Values on Hover).
. . 18.19
, M ouseOver.

.

. 18.19. ,

589

18.

,
.
P r i v a t e Sub C h a r t_ M o u s e M o v e (B y V a l B u t t o n As L o n g , _
B y V a l S h i f t As L o n g , B y V a l X As L o n g , B y V a l Y As L on g )
Dim E l e m e n t ld As Long
Dim a r g l As L o n g , a r g 2 As Long
Dim N e w T e x t As S t r i n g
On E r r o r Resume N e x t
A c t i v e C h a r t . G e t C h a r t E le m e n t X , Y , E l e m e n t ld , a r g l , a r g 2
I f E l e m e n t ld = x l S e r i e s T h e n
N e w T e x t = S h e e ts ( "JIh c t I " ) . R ange ( " " ) . O f f s e t _
(a rg 2 , a r g l)
E ls e
N e w T e x t = ""
End I f
A c t iv e C h a r t . S h a p e s ( 1 ) .T e x tF ra m e . C h a r a c te r s .T e x t = N ew Text
End Sub

.
X Y, .
B utto n S h i f t .
, G e tC h a r
tElem ent. E le m e n tld x l S e r i e s ,
. ,
(. 18.20). , .
A
1

3 245151

1434 343

5546 523

1238 709

5 083 204

3 224 855

5
6


1, =

2, = $1434343,000

$3245151,000
7

... ....

...
....
~' ~
1, =

~~

1 2, = $1238709,000

$5546523,000

.
1, = $5083204,000

2, = $3224855,000
-

3 .

10

. 18.20. 7:9
,
C h a rt A c t iv a t e ,
, C h a r t_ D e a c tiv a te ,
. C h a r t_ A c tiv a te .
P r i v a t e Sub C h a r t _ A c t i v a t e ()
A p p l i c a t i o n . S h o w C h a rtT ip N a m e s = F a l s e
A p p l i c a t i o n . S h o w C h a r t T ip V a lu e s = F a l s e
End Sub

590

V.
-

-
( m o u s e o v e r e v e n t - e m b e d d e d . x l s m )
( m o u s e o v e r

e v e n t - c h a r t

s h e e t . x l s m ) .


Excel (
). , .
, . 18.21.
|

FG I

i|' L !

3,96

31 5,

4 |

0|

v
0

5 I 3,96

-0,7

6
7

7,91
11,9

1
-0,6

15,8

19,8

0,8

10

23,7

-1

1 1 1 27,7 0,56
12; 31,6 0,22
13 i 35,6

-0,9

14

39,6 0,96

15

43,5

-0,5

11 47,5

-0,3

17

51,4 0,91

18

55,4

19

59,3 0,36

-0,9

20 ] 63,3 0,43
2 ! j 67,2

-1

. 18.21. VBA

X ( ) , 1.

1. ,
SIN .
.
1, X Y.
Sub A n i m a t e C h a r t ()
Dim i As Long
R a n g e ( " A l" ) = 0
F o r i = 1 To 15 0
D o E v e n ts
R a n g e ( " A l" ) = R a n g e ( " A l" )
D o E v e n ts
Next i
R a n g e ( " A l" ) = 0
End Sub

+ 0 .0 3 5

18.

591


D o E v e n t s . ,
,
Excel. ,
.
-

- ,
,
.
a n im a te d c h a r t s . x l s m .


. 18.22 , 5218
. :

F1;

F2;

F3 ( );

:
=(1!$$1, ,0 , ,1)
:
=(1!$$1, ,0 , ,1)

:
=(1!$$1, ,0 , ,1)
(SERIES)
. _ (
).
=($$1, ,_,1)
_:
=($$1, , _,2)

, .
-

- ,
,
. s c r o l l i n g c h a r t . xls m .

. , .
P u b lic A n i m a t i o n l n P r o g r e s s As B o o le a n
Sub A n i m a t e C h a r t ()
Dim S t a r t V a l As L o n g , r As Long
I f A n im a t i o n l n P r o g r e s s T h e n

592

V.

A n im a tio n ln P r o g r e s s = F a ls e
End
End I f
A n im a tio n ln P r o g r e s s = T ru e
S t a r t V a l = R a n g e ( " ")
F o r r = S t a r t V a l To 5 2 1 9 - R a n g e ( " " )
S te p R a n g e ( " ")
R a n g e ( " ") = r
D o E v e n ts
N ext r
A n im a t i o n l n P r o g r e s s = F a l s e
End Sub
1

:
13-M ar 1986

45,83;

160,32

14-M a r-1986

45,32

160,30

17 - -1986

46,46

156,89

45,77

153,32

1,10

149,87

20--198;

44,10

148,47

21 - -1986

42,08

152,61

24- -1986

43,15

150,71

25--1986

41,71

152,99

26- -1986

43,48

156,45

27 - -1986

43,13

156,02

31 - -1986

41,76

1 - -1986

39,43

18 - -1986
19-

1986

F
274
____ 180

158,27
162,72
161,27

"
28--1986
29--1986
30-

1986

42,31

163,60

42,92

163,83

41,70

160,21

. 18.22. F ,
A n im a te C h a rt ( A n i m a t i o n l n
P r o g r e s s ) . ,
.
,
. .
End (
E x i t Sub). ,
E x i t Sub Excel.


, ,
, (
). , . 18.23, -

18.

593

. , ,
.
.
1
2
3

<

S
5 M
<J

: 830
:825
t:5 2 9

8
9

10

12

'

13

: 2

14
15
16
17
18
19

2
21

22
23
24
25

. 18.23.
-

- hypocy clo id -an im ate,x lsm .

,
( ).
, .
, , ,
. ,
.
,
, .
, . 1


. 18.24 , ,
. , , , .
,
.

594

V.

1
2

. 18.24.

-

-
v b a c l o c k c h a r t , x ls m .
, ,
, . 18.25. ,
, .
, -,
.

C h a r tO b je c t C lo c k C h a rt D ig it a l C l o c k .

(Forms).
( S t a r t C l o c k S to p C lo c k ).

C heckbox () ( cbC lo ck T y p e)
(Forms),
(Control Toolbox).
c b C lo c k T y p e _ C lic k ,
V i s i b l e C lo c k C h a rt. ,
.

S e r ie s .
, , ,
12 .

U p d a te C lo c k .
OnTime A p p l i c a t i o n .

18.

595

. U p d a te C lo c k
OnTime, .
, U p d a te C lo c k .

. 18.25. ,
,
,
.
VBA
V a lu e s X V alues S e r i e s .

VBA,
.
, VBA
, ,
.



(. 18.26) ,
( 284 )
, ,
.

596

V.

100,0

90,0

80,0

70.0

60.0
50.0

40.0
TUCSON, AZ

30.0
MISSOULA,
20.0
10,0

0,0

TUCSON, AZ

MISSOULA,

. 18.26. ,

,
VBA.
Excel. ,
( ),
.
.
,
.
-


- c l i m a t e d a t a . x l s x .
, .


,
.
(National Climatic Data Center).
, Excel .
13 , c i p i t a t i o n D a t a , T e m p e ra tu re D a ta , S u n s h in e D a ta W indData.
, ( D ata).

597

18.


,
.
(OptionButton)
(Forms). ,
03. 1
4 .

03.
, 04, .
=(03 7 " T e m p e r a t u r e D a t a " , " P r e c i p i t a t i o n D a t a " , " S u n s h in e D a ta "
" W in d D a ta " )

, 0 4
.
.


,
.
Excel.
. J11:M11
C i t y l . J13:M 13 C i t y 2.
C i t y L i s t ,
P r e c i p i t a t i o n D a t a .
.
1. J11:11. ( , .)
2. 1^ (Data^Data Validation)
Excel (Data Validation).
3.

(Settings).

4. (Allow)

(List).

5. (Source) = C i ty L i s t.

6. .
7. J11:11 J13:M13.

.
. 18.27.
. 18.27.

TUCSON, AZ
TUCSON, AZ
TULSA, OK
UNALAKLI
VALDEZ, AK
VALENTINE, NE
VERO BEACH, FL
VICTORIA, TX

598

V.

:
.
,
(VLOOKUP), . 18.28.

20

21
22

23^ TUCSON, AZ

55,0

59,2

66,0

74,5

84

86,5

84,9

80,9

70,5

58,7

24 MISSOULA

29,0

37,6

45,2

52,7

60,2

66,9

66,3

56,1

44,4

32,0

23,4

28,21 26,0

21,6

20,8

21,8

23,9

19,6

18,6

24,8

26,1

26,7

28,5

25

51,9

26

. 18.28. ,
23:24
23 ,
C ity l.
= ( C i t y l , ( D a t a T a b l e ) , ( ) ,)

24 24, ,
C ity 2 .
= ( C i t y 2 / ( D a t a T a b l e ) , ( ) ,)

12 .

,
(COLUMN).
, .
, , ,
.
, , ,
.
() ,
.
,
D a ta T a b le .
= "A v e ra g e

" & ( D a t a T a b l e , ( D a t a T a b l e ) - 4 )



.
, 22:24.
21. 22:24
.

599

18.


, Excel 2010. ,
. ,
.
.
. 18.29 , Excel.

, "... ....

F.....

98,92

88,12

86,34

75,58

71,2

212,74

218,7

202,18

198,56

190,12

181,74

75,74

73,68

69,86

60,34

64,92

59,46

6 W -31

91,78

95,44

98,1

99,46

98,68

105,86

7 -

324,48

309,14

313,1

276,24

276,24

260,9

3 -13

103,98

4 -09
5 -88

------- 1

8
9

10

12 -09

212,74

218,7

202,18

198,56

190,12

13 -88

75,74

73,68

69,86

60,34

64,92

59,46

9868
276,24

105,86

14 W-31

___91,78

95,44

98,1

99,46

15 -

324,48

309,14

313,1

276,24

71,2

181,74

75,58

86,34

88,12

98,92

103,98

11 -13

__________


~ _ _ ___ _____

__________ ___

260,9

16
17

18

19 -13

103,98

20 -09
21 -88

98,92

88,12

86,34

75,58

212,74

218,7

202,18

198,56

190,12

75,74

73,68

69,86

60,34

64,92

22 W -31

91,78

95,44

98,1

99,46

98,68

324,48

3094

313,1

276,24

276,24

23

71,2

5 9 ,4 |^ |^ ^ ^ ^
i o

s , 8

260,91

" *
i

24
25

. 18.29.
, Microsoft , , Excel.
VBA.
S p a r k l i n e G roups, S p a rklineG roup. S p a rk lin e G ro u p S p a r k lin e .
S p a r k lin e G r o u p s Range,
Worksheet. :
MsgBox A c t i v e S h e e t . S p a r k lin e G r o u p s . C o u n t

C e l l s ( ).
MsgBox C e l l s . S p a r k l in e G r o u p s . C o u n t


, .

600

V.

Sub L i s t S p a r k l i n e G r o u p s ()
D im sg As S p a r k lin e G r o u p
D im i As Lon g
F o r i = 1 To C e l l s . S p a r k l i n e G r o u p s . C o u n t
S e t sg = C e l l s . S p a r k l i n e G r o u p s ( i )
MsgBox s g . L o c a t io n .A d d r e s s
Next i
End Sub

F or Each
S p a rk l in eG roups. .
,
VBA. S p a r k l in e R e p o r t ,
.
Sub S p a r k l i n e R e p o r t ()
D im sg As S p a r k lin e G r o u p
D im s i As S p a r k l i n e
D im SGType As S t r i n g
D im S L S h e e t As W o r k s h e e t
D im i As L o n g , j As L o n g ,

r As Long

If

C e l l s . S p a r k lin e G r o u p s . C ount = 0 Then


MsgBox " ."
E x i t Sub
End I f

'

'

S e t S L S heet = A c tiv e s h e e t

W o r k s h e e ts .A d d

W it h R a n g e ( " A l" )
. V a l u e = " : " & S L S h e e t.N a m e
& S L S h e e t . P a r e n t . Name
. F o n t . B o ld = T r u e
. F o n t . S i z e = 16
End W it h
W it h R a n g e ( " A 3 :F 3 " )
. V a l u e = A r r a y ( " # " , " _
" , "# " , " " , _
" S p a r k l i n e # " , " " )
. F o n t . B o ld = T r u e
End W it h
r = 4

F o r i = 1 S L S h e e t . C e l l s . S p a r k l in e G r o u p s . C o u n t
S e t sg = S L S h e e t . C e l l s . S p a r k l i n e G r o u p s ( i )
S e l e c t C ase s g .T y p e
C ase 1 : SGType = " "
C ase 2 : SGType = " "
C ase 3 : SG Type = " /"
End S e l e c t

F o r j = 1 s g . C o u n t
S et s i = s g .Ite m (j)

& " " _

iaea 18.
C e l l s ( , 1)
C e l l s ( , 2)
C e l l s ( r , 3)
C e l l s ( r , 4)
C e l l s ( r , 5)
C e l l s ( , 6)
r = r + 1
N ext j
r = r + 1
N ext i
id Sub

=
=
=
=
=
=

601

i '#
s g . L o c a tio n .A d d r e s s
s g .C o u n t
SGType
j '#
s i . S o u r c e D a ta

. 18.30 , .
-


-.

s p a r k l in e

r e p o r t , x ls m

'

: /11 sparkline report.xlsm

2
3

U #

1 $N$22:$N$31

10

1 22:22

1 $N$22:$N$31

10

2 23:23

6
7

1 $N$22:$N$31

10

3 24:24

1 $N$22:$N$31

10

4125:25

1 $N$22:$N$31

10

5 26: 26

1 $N$22:$N$31

10

6 27:27

1 $N$22:$N$31

10

7 28:28

11

1 $N$22:$N$31

10

8 29:29

12
13

1 $N$22: $N$31

10

9 :

1 $N$22:$N$31

10

10 31:31

15

2 $N$9:$N$18

10

1 9:9

16

2 $N$9:$N$18

10

2 10:10

17

2 $N$9:$N$18

10

3 11:11

18

2 $N$9:$N$18

10

4 12:12

14

19

2 $N$9:$N$18

10

5 13:13

.20

2 $N$9:$N$18

10

6 14:14

21

2 $N$9:$N$18

10

7 15: 15

22

2 $N$9:$N$18

10

8 1:1

23

2 $N$9: $N$18

10

9 17:17

24

2 $N$9:$N$18

10

10 18:18

. 18.30. S p a rk l in e R e p o rt



Excel
...
Excel
W orkbook
W o rk sh e e t
C h a rt
A p p l i c a t i o n
U serF orm
,

Excel ,
, , .

Excel
VBA,
.
,
. C o m m an d B u tto n l_ C lick ,
, Com
mandButtonl,
.
Excel ,
.
.
Workbook. .
Open (

604

V.

), B e fo re S a v e (
) N ew Sheet ( ).

W o r k s h e e t. .
C hange (
), S e le c tio n C h a n g e ( ) C a l
c u l a t e ( ).

C h a r t. .
S e l e c t ( ) S e rie s C h a n g e (
).
(. 18).

A p p l i c a t i o n . Excel.
NewWorkbook ( ), W orkbookBef o r e C lo s e (
) S h e e t Change (
). A p p l i c a t i o n
.

U se r F o r m .
U serF orm . ,
Use Form I n i t i a l i z e (
U serForm ). Com mandButton,
U serForm , C l i c k (
).

, .
( A p p l i c a t io n ) ,
On-: OnTime . , .

.
,
.


.
,
A p p l i c a t io n :

W orkbookN ewSheet ;

S h e e tD e a c t iv a t e , ;

S h e e t A c t i v a t e , ()
.

,
.
A p p l i c a t i o n .
W o rkb o o k W o r k s h e e t.

605

19. Excel

.
.
,
( A p p l i c a t i o n ).


VBA- ,
.
, .
VBE Projects ().
, . 19.1.
Project - VBAProject

J J
-AcrobatPDF M aker (PDFMaker.xla)
& Data Form (da taform Jocla)

D ataForm (dataform 3.xlam )


PUP7TRIAL (pup7.xlam )
TextToolsVBA ( te x t toolsodam )
* Modulel
@ Sheet 1 (Sheet 1)
30 ThisWorkbook
m UserForml
VBAProject (PERSONAL.XLSB)
VBAProject (!)
Classl
Modulel
UserForml
@ 1 (1)
@ 2 (2)
()
-

. 19.1. VBA
Projects
.
(, 1, 2 ..).
, .
(.. ).
, .
(ThisWorkbook).
, .
VBA .
( ).

V.

606

.
,
.
,

. , ,
, W orkbookS etup,
VBA .
P r i v a t e Sub W o rk b o o k _ O p e n ()
C a l l W o rk b o o k S e tu p
End Sub

Excel

Excel 97 ,
.
, A u to _ O p e n ,
VBA , >
. Excel 97 A u to _ O p e n
W o rkb o o k_O p en , .
A u to Open.
Excel 97 . ,
, ,
:
S h e e t s ( " 1 " ) . O n E n tr y = " V a l i d a t e E n t r y "

Excel , V a l i
, . Excel 97
w o r k s h e e t_ c h a n g e ,
1 .
Excel 97
(
). ,
Excel 97 , ,
.
d a te E n try


.
VBA:
A p p lic a tio n .E n a b le E v e n ts

= F a ls e

:
A p p lic a t io n .E n a b le E v e n t s

= T ru e

,
u s e rF o rm , c l i c k ,
( CommandButton),
U s e rF o rm .

19. Excel

607

, ?
.
, 1 ,
[ 12. , ,
. C hange W o rk sh e e t,
, W o rk sh eet_ C h an g e.
, 12, , . ,
VBA Change, . ,
[ .
[ , ( .
1 ( S t a t i c
B o o le a n ) . :
S ta tic A b o r t P r o c As B o o le a n

, ,
A b o r tP ro c T ru e ( ,
F a ls e ) . .
I f A b o r tP r o c T h e n
A b o r tP r o c = F a l s e
E x i t Sub
End i f

, T ru e
A b o r tP ro c
. , A b o rtP ro c F a ls e .


,
.

Excel
. , ,
, W o rk b o o k Open, .


.
:
W o rk s h e e t_ S e le c tio n C h a n g e ;
Workbook_Open;

608

V.

C h a r t_ A c ti v a t e ;

C la s s _ In itia liz e .

,
VBE.
. 19.2 (ThisWorkbook).
, Workbook
. .
, End Sub.
*
fat

s*t

I S S -

Vl*

JniMt

Format >f*us

Sun

fools

-) a i


J.
tobrttf1
1^ Dataform (datafomOjda)
Oataform (datatornO.xiam)
I
PUP7TR1AL (pup/.xiam)
t* TextToolsVBA (text
Modulel
Sheetl (Sheetlj

Add-Ins

1.101xt

Window g*tp

-- ------------

Private Sub Workbook_Open()


End Sub

s<

VBAProject (-al)
ffi Qassl
J ? Modiel
/Vcrl (!)
2(2}
()

. 19.2. VBE

, W orkbook,
Open, VBE () .
Private Sub Wo r k b o o k _ O p e n ()
End Sub

VBA .

,

. ,
SheetA c t i v a t e . ,
, VBE .
Private Sub Workbook_SheetActivate(ByVal Sh As Object)
End Sub

(Sh),
. Sh O b je c t, W orksheet.
, .

609

19. Excel

, ,
.
.
TypeName Name , .
P r i v a t e Sub W o r k b o o k _ S h e e t A c t iv a t (B y V a l Sh As O b j e c t )
MsgBox T y p e N a m e (S h ) & v b C r L f & S h.N am e
End Sub

. 19.3 ,
1.
A

. 19.3. s h e e tA c tiv a te
C a n c e l
B o o le a n . , B e f o r e P r i n t
:
P riv a te

Sub W o r k b o o k _ B e f o r e P r in t ( C a n c e l As B o o le a n )

C a n c e l, , F a ls e .
T ru e, .
.
P riv a te Sub W o r k b o o k _ B e f o r e P r in t ( C a n c e l As B o o le a n )
Dim Msg As S t r i n g
Dim Ans As I n t e g e r
Msg = " ?"
Ans = M sg B o x(M s g , v b Y e s N o , " . . . " )
I f Ans = vbNo T h e n C a n c e l = T r u e
End Sub

W o rk b o o k _ B e fo re P rin t
?
.
, . 19.4.
I__ !__ I
, C a n c e l
T ru e, .
. 19.4.
, Excel Bef o r e
Print . , Cancel
, .
, A c tiv e S h e e t.
, .
I 203. 3107

V.

610

B e f o r e P r i n t
.

W orkbook
W orkbook .
. 19.1 ,
. W orkbook
T hisW orkbook ().

1 9 .1 .

w orkbook

A c tiv a te



,



( )






(
)
(

)
( )








A d d in ln s ta ll
A d d in U n i n s t a l l
A f t e r Save
B e fo r e C lo s e
B e f o r e P r in t
B e fo re S a v e
D e a c t iv a t e
N ew C hart
New Sheet
Open
S h e e t A c t iv a t e
S h e e tB e fo r e D o u b le C lic k
S h e e tB e f o r e R ig h t C lic k

S h e e tC a lc u la t e
S h eetC hang e
S h e e t D e a c t iv a te
S h e e tF o llo w H y p e r lin k
S h e e tP iv o tT a b le U p d a te
S h e e tS e le c tio n C h a n g e
W in d o w A c tiv a te
W in d o w D e a c tiv a te
W in d o w R e size

, ,
A p p l i c a t i o n (.
A p p l i c a t i o n ). -

19. Excel

611

W orkbook. , ,
(ThisWorkbook).
, .

Open
Open WorkBook.
( ).
W orkbook_Open. ,
:
;
;
;
;
(,
);
(,
; . );
Sc 11 A re a (
);
U s e r I n t e r f a c e O n l y ,
(
P r o t e c t ).

<Shift>
, w o rk b o o k Open .
, ,
.
W orkbook_Open.
W eekday .
, ,
.
, .
P r iv a te Sub W orkb o o k_ O p en ()
I f W eek d a y(N o w ) = v b F r i d a y T h e n
Msg = " . "
Msg = Msg & " !"
MsgBox M sg, v b l n f o r m a t i o n
End I f
End Sub

Activate
.
.

612

V.

P r i v a t e Sub W o r k b o o k _ A c t i v a t e ()
A c t iv e W in d o w . W in d o w S ta te = x l M a x i m i z e d
End Sub

SheetActivate
,
. ,
1. , .
VBA TypeName , ,
( ).
P r i v a t e Sub W o r k b o o k _ S h e e t A c t iv a t e ( B y V a l Sh As O b j e c t )
I f T yp eN a m e (S h ) = " W o r k s h e e t" T h e n _
R a n g e( " A l" ) . S e le c t
End Sub


.
P r i v a t e Sub W o r k b o o k _ S h e e t A c t iv a t e ( B y V a l Sh As O b j e c t )
On E r r o r Resume N e x t
R a n g e (" A l " ) . S e le c t
End Sub

NewSheet
,
. .
, ,
. ,
1.
P r i v a t e Sub W o rk b o o k _ N e w S h e e t(B y V a l Sh As O b j e c t )
I f T yp eN a m e (S h ) = " W o r k s h e e t" T h e n
S h . C e l l s . C o lu m n W id th = 3 5
S h .R a n g e ( " A l " ) = " " & N o w ()
End I f
End Sub

BeoreSave
B e fo re S a v e .
, ^ (File^Save)
(Save As). ,
.
W orkbook_Be f o r e S ave
(SaveA sUI),
. .
P r i v a t e Sub W o r k b o o k _ B e fo re S a v e _
(B y V a l S a v e A s U I As B o o le a n , C a n c e l As B o o le a n )
I f S aveA sU I Then
MsgBox " , _
J . "
End I f
End Sub

19. Excel

613

, W orkbook_
Be f o re Save.
, SaveAsUI T ru e.
SaveA sU I,
, .
C a n c e l T ru e .

Deactivate
D e a c ti v a te .
( ) .
.
D e a c t i v a t e
.
P riv a te Sub W o r k b o o k _ D e a c t iv a t e ()
M e .A c tiv a te
MsgBox " ,
End Sub

..."

,
Excel, .
. .

. , ,
, .
D e a c tiv a te :
;
;
.
, ,
.
, ,
.
, .

BeforePrint
B e f o r e P r i n t ,
,
. C a n c e l,

C a n c e l T rue. , ,
B e f o r e P r i n t
, .

V.

614

Excel
,
Excel.
W o rk b o o k _ B e fo re P rin t
.

, 1 1.
P r i v a t e Sub W o r k b o o k _ B e f o r e P r in t (C a n c e l As B o o le a n )
D im s h t As O b je c t
F o r E a c h s h t I n T h is W o r k b o o k . S h e e ts
s h t . P a g e S e tu p . L e f t F o o t e r = _
W o r k s h e e t s ( " 1 " ) . R a n g e ( " A l ")
N ext sht
End Sub

,
L e f tF o o te r P ag eS etu p 1 1.

W orkbook_Be f o r e P r i n t
B:D 1 .
P r i v a t e Sub W o r k b o o k _ B e f o r e P r in t ( C a n c e l As B o o le a n )
1
B :D 1
W o r k s h e e t s ( " 1 " ) . R a n g e ( " : D " ) . E n t ir e C o l u m n . H id d e n = T r u e
End Sub


. , Excel A f t e r P r i n t ,
, ... .
:
. OnTime,
U nhideC olum ns
.
P r i v a t e Sub W o r k b o o k _ B e f o r e P r in t ( C a n c e l As B o o le a n )
'
B :D 1
W o r k s h e e t s ( " 1 " ) .R a n g e ( " : D " ) . E n t i r e C o l u m n . H i d d e n = T r u e
A p p li c a t io n .O n T i m e Now + T im e V a lu e ( " 0 : 0 0 : 0 5 " ) , " U n h id e C o lu m n s "
End Sub

U nhideC olum ns VBA.


Sub U n h id e C o lu m n s ()
W o r k s h e e t s ( " 1 " ) .R a n g e ( " : D " ) . E n t i r e C o l u m n . H i d d e n
End Sub

= F a ls e

h id e

c o lu m n s b e f o r e p r i n t i n g . x l s m .
aft-


O n T im e.

O nTim e

19. Excel

615

BeforeClose
B e f o re C lo s e .
W orkbook_Open. ,
W orkbook_Open ,
, W orkbook_B ef o r e C lo s e
. ,
.
, W orkbook_Bef o r e C lo s e .
, Excel ,
,
. 19.5. ,
W orkb o o k _ B efo reC lo se .
, .
*

Microsoft Excel
j

' i.xls?

. 19.5.
W orkbook_Beforeclose

.
.
W orkbook_Open ,
W orkbook_B ef o r e C lo s e
. .
, .
P r iv a te Sub W o r k b 6 o k _ 0 p e n ()
C a l l C r e a te S h o r t c u t M e n u It e m s
End Sub
P r iv a te Sub W o r k b o o k _ B e f o r e C lo s e (C a n c e l As B o o le a n )
C a l l D e le t e S h o r t c u t M e n u I t e m s
End Sub

, Excel . . .
, W orkbook_B ef o r e C lo s e .
, ,
!

W o rk b o o k _ B e fo re c lo s e . ,
.
P riv a te Sub W o r k b o o k _ B e fo r e C lo s e (C a n c e l As B o o le a n )
Dim Msg As S t r i n g
I f M e .S a v e d = F a l s e T h e n
Msg = " ? "
Msg = Msg & M e.Nam e & "?"
Ans = M sg B o x(M s g , v b Q u e s t io n + v b Y e s N o C a n c e l)
S e l e c t C ase Ans

V.

616

C ase v b Y e s
M e. Save
C ase v b C a n c e l
C a n c e l = T ru e
E x i t Sub
End S e l e c t
End I f
C a l l D e le t e S h o r t c u t M e n u It e m s
M e . Saved = T ru e
End Sub

S av ed W orkbook
. ,
D e le te S h o r tc u tM e n u I te m s , .
.
, Excel.
.
, , .

S aved Workbook T ru e (
), .

. Be f o r e c l o s e ,
.

, , - w o r k b o o k _ b e f o r e c l o s e w o r k a r o u n d . x ls m .

W o rk s h e e t
W o rk sh e e t .
,
.
. 19.2 ,
.
1 9 .2 . w o r k s h e e t

A c tiv a te




( )





B e fo r e D o u b le C lic k
B e f o r e R i g h t C li c k
C a lc u l a t e
Change
D e a c t iv a t e
F o llo w H y p e r lin k
P iv o tT a b le U p d a te
S e le c tio n C h a n g e

19. Excel

617

,
.

(View Code).

Change
C hange
VBA-. Change ,
.
W o rk sh eet_ C h an g e T a r g e t
Range. ( ),
.
, , T a r g e t.
P riv a te Sub W o r k s h e e t_ C h a n g e (B y V a l T a r g e t As E x c e l.R a n g e )
MsgBox " " & T a r g e t . A d d r e s s & " ."

End Sub
,
Change ,
W o rk sh eet. Excel
, .
Change , .
:
, ,
, , ,
C h an g e!
Change,
1^^^
(Home^Editing^Clear^Clear Formats), , .

(Paste Special).
,
Change.
<Del> Change
, .
, Excel, ,
Change. ,
, .
I VBA ,
Change.
, ,
Change .

618

V.

C hange .
,
. Works h e e t_ C h a n g e , Range.
,
Change.
, I n p u t Range,
, .
Change Range,
W o rk sh eet_ C h an g e.
P r i v a t e Sub W o r k s h e e t_ C h a n g e (B y V a l T a r g e t As E x c e l.R a n g e )
D im MRange As R ange
S e t MRange = R a n g e ( " In p u t R a n g e " )
I f N o t I n t e r s e c t ( T a r g e t , M Range) I s N o t h in g T h e n _
MsgBox " ."
End Sub

Range, VRange.
,
. VBA I n t e r s e c t ,
T a r g e t (
) VRange. I n t e r s e c t ,
, . I n t e r s e c t
N o th in g , . Not
, T ru e ,
VRange. ,
. ,
.

.
P r i v a t e Sub W o r k s h e e t_ C h a n g e (B y V a l T a r g e t As E x c e l.R a n g e )
Dim c e l l As R ange
F o r Each c e l l I n T a r g e t
c e l l . F o n t . B o ld = c e l l . H a s F o r m u l a
N ext c e ll
End Sub

W orksheet_C hange
, ,
T a r g e t. ,
. , B old F a ls e .
, . ,
?- T a r g e t
. F o r Each
, .

T a r g e t ,
T a r g e t , .

19. Excel

619

, T a r g e t N o th in g ,
, .
P r iv a t e Sub W o r k s h e e t_ C h a n g e (B y V a l T a r g e t As E x c e l.R a n g e )
Dim c e l l As Range
S e t T a r g e t = I n t e r s e c t ( T a r g e t , T a r g e t . P a r e n t .U s e d R a n g e )
I f N o t T a r g e t I s N o t h in g T h e n
F o r E ac h c e l l I n T a r g e t
c e l l . F o n t . B o ld = c e l l . H a s F o rm u la
Next c e ll
End I f
End Sub

- make
f o r m u la s b o l d .x ls m .

w o r k s h e e t_ c h a n g e
Excel.
.
W o r k s h e e t c h a n g e
.

Excel ,
, .
, , ,
, , ! ,
.
Change
Worksheet .

-
. ( v a l i d a t e e n t r y l . x l s m )
E n a b le E v e n t s
c h a n g e ; ( v a l i d a t e
e n t r y 2 . x ls m ) (.
).

W o rk sh eet_ C h an g e, , ,
. I n p u t Range.
1 12.
P riv ate Sub W o r k s h e e t_ C h a n g e (B y V a l T a r g e t As R a n g e)
Dim VR ange As R a n g e , c e l l As R ange
Dim Msg As S t r i n g
Dim V a l i d a t e C o d e As V a r i a n t
Set VRange = R a n g e ( " In p u t R a n g e " )
I f I n t e r s e c t ( V R a n g e , T a r g e t ) I s N o t h in g T h e n E x i t
For E ac h c e l l I n I n t e r s e c t ( V R a n g e , T a r g e t )
V a lid a te C o d e = E n t r y l s V a l i d ( c e l l )

Sub

620

V.
If

T y p e N a m e (V a lid a t e C o d e ) = " S t r i n g " T h e n


Msg = " " & c e l l . A d d r e s s ( F a l s e , F a l s e ) &
Msg = Msg & v b C r L f & v b C r L f & V a l i d a t e C o d e
M sgBox M sg, v b C r i t i c a l , " "
A p p lic a t io n .E n a b le E v e n t s = F a ls e
c e l l . C le a rC o n te n ts
c e ll.A c tiv a te
A p p lic a tio n .E n a b le E v e n ts = T ru e
End I f
N ext c e ll
End Sub

W o rk sh eet_ C h an g e Range. VRange


.
T a r g e t,
. ,
, , ( E n tr y I s V a lid ) , T ru e .
,
E n t r y l s V a l i d , .
(. 19.6).
, . ,
. ,
Change .

. 19.6. ,

E n t r y l s V a l i d .
P r i v a t e F u n c t i o n E n t r y l s V a l i d ( c e l l ) As V a r i a n t
' T r u e ,
' 1 1 2 .
' ,
1

?
I f N o t W o r k s h e e t F u n c t io n .Is N u m b e r ( c e l l )
E n t r y l s V a l i d = " ."
E x i t F u n c tio n
End I f

.
~

Then

19. Excel
'

621

?
I f C l n t ( c e l l ) <> c e l l T h e n
E n t r y l s V a l i d = " ."
E x i t F u n c tio n
End I f

?
I f c e l l < 1 O r c e l l > 12 T h e n
E n t r y l s V a l i d = "
1 1 2 . "
E x i t F u n c tio n
End I f
1
E n t r y ls V a lid = T ru e
End F u n c t io n

,
.
Excel ,
, .
.
P r iv a te Sub W o r k s h e e t_ C h a n g e (B y V a l T a r g e t As R an g e)
Dim VT As Long
1
' ?
On E r r o r Resume N e x t
VT = R a n g e ( " In p u t R a n g e " ) . V a l i d a t i o n . T y p e
I f E r r .N u m b e r <> 0 T h e n
A p p 1 i a t i o n . Undo
MsgBox " ." & _
" ." , v b C r i t i c a l
End I f
End Sub

(
In p u tR a n g e ),
. VT , ,
In p u tR a n g e .
,
. Undo
A p p l i c a t i o n , , .
, . 19.7.


.
-


- v a l i d a t e e n t r y 3 . x ls m .

622

V.

, ,
1 12.
.

__]______

j ___

xj

. ,

I <* I
. 19.7. W orksheet

change

SelectionChange
S e le c tio n C h a n g e .
, .
P r i v a t e Sub W o r k s h e e t _ S e le c t io n C h a n g e ( B y V a l T a r g e t As E x c e l.R a n g e )
C e l l s . I n t e r i o r . C o l o r ln d e x = x lN o n e
W it h A c t i v e C e l l
. E n t ir e R o w . I n t e r i o r . C o l o r = RGB( 2 1 9 , 2 2 9 , 2 4 1 )
. E n t ir e C o l u m n . I n t e r i o r . C o l o r = RGB( 2 1 9 , 2 2 9 , 2 4 1 )
End W it h
End Sub

,
.
, -
. . 19.8 (, ).
, .
, ,

. , W o rk s h e e t_ S e le c tio n C h a n g e
,
Excel.
-

-
a c tiv e

shade

ro w an d c o lu m n .x ls m .

BeoreDoubleClick
VBA,
. (
S h e e t)

623

19. Excel

( " Good", )
( "N orm al").
P r iv a t e Sub W o r k s h e e t _ B e f o r e D o u b le C lic k _
(B y V a l T a r g e t As E x c e l.R a n g e , C a n c e l As B o o le a n )
I f T a r g e t . S t y l e = "Good" T h e n
T a r g e t . S t y l e = " N o rm a l"
E ls e
T a r g e t . S t y l e = "Good"
End I f
C ancel = T ru e
End Sub
A

-1

......... ................... ~~

-2

-3

-4

-S

-6

-2007

2158

1527

3870

4863

3927

39

-2007

4254

28

4345

2108

412

28

-2007

3631

1240

4208

452

3443 N

29

2007

724

4939

1619

1721

3631

34

-2007

3060

1034

1646

345

978

-2007

394

1241

2965

1411

3545

5
44<

-2007

2080

3978

3304

1460

4533

33

-2007

4 1 l|

732

1207

1902

401

10

-2007

2711

95

2267

2634

1944

39

11

-2007

2996

4934

3932

2938

4730

11

12

-2007

2837

1116

3879

1740

1466

36

13

-2007

300

2917

321

1219

841

35'

14

-2008

1604

768

2617

3414

4732

8<

15 -2008

1662

1380

4590

531

4143

111

16 -2008

1001

3454

4611

4852

456

17

-2008

4407

46

4185

4868

2313

IS

-2008

3948

1292

1462

1977

2418

18

19 -2008

160

2908

3834

2396

4120

22

75|

_______T rtrtO

l< 4 j S h e e tl t

................1 1 ............

.............

......................

271

< 1

. 19.8.

C a n c e l T rue, ,
. ,
Excel .

BeforeRightClick
, Excel
. -
, B e
fo re R ig h tC lic k . C a n c e l
T rue, B e f o r e R ig h tC lic k .
.
P riv a te Sub W o r k s h e e t _ B e f o r e R ig h t C l ic k _
(B yV al T a r g e t As E x c e l.R a n g e , C a n c e l As B o o le a n )
C a n c el = T r u e
MsgBox " ."
1 End Sub

624

V.

, -
, <Shift+F10>.
Excel .

<Shift+F10>,
. 23
.

, f o r e R i g h t C li c k . ,
. ,
(Format Cells),
(Number), C a n c e l T ru e (
). ,
.
P r i v a t e Sub W o r k s h e e t _ B e f o r e R ig h t C l ic k _
(B y V a l T a r g e t As E x c e l.R a n g e , C a n c e l As B o o le a n )
I f I s N u m e r i c ( T a r g e t ) And N o t I s E m p t y ( T a r g e t ) T h e n
A p p l i c a t i o n . D i a l o g s ( x l D i a l o g F o r m a t N u m b e r ) .Show
C an cel = T ru e
End I f
End Sub

, ,
. , VBA
.

c h a r t
,
. ,
.

C h a r t
18.
, .

. 19.3 , ,
.
1 9 .3 . ,

A ct iv a te



( ,
)

B e f o r e D o u b le C lic k

19. Excel

625
. 19.3

BeforeRightClick


(
, )


,

Calculate
Deactivate
MouseDown
MouseMove
MouseUp
Resize
Select
SeriesChange

Object Browser ( ) ,
,
. ,
. , , ,
M ouseM ove. VBE <F2>
Object Browser. , <
Libraries> (< >), MouseM ove
(. ).

: i i -

faff
A

IrKt

Qrbug gun Jeofr -k apndo*

* A*

>

B*eam eonpoc

-_

!<* Librane
d

-----

I Cum
Chart
, .ne-J-fcc

CommandBirtton
Frame
a mage
a Label
austSo*
a MuMPage
OptionButton
JN TabStno

\ Excel
MSFonns
\ MSForma
\ MSForma
MSForms
H\ MSForms
|H\ MSFonns
I l \ MSFonns
l \ MSForms
l \ MSForms
4 UoFwrni

IV

i
^
||*
jef
W
W
jsf
;

Members of Charr
Classes
atculatedMember jjfclFGapOepet
GetChartElement
C3lculatedMembers.
Caiouformat
HasAs
CeWormat
HasOataTable
CertrtcateDetart
HasLegend
HasTme
Hetghpercent
Characters
"y
HyperSnks
Chart
A Cnarwea
Legend
CbartFormal
Location
ChartGroup
MailErwelope
ChartGroups
ChartObted
ChartObjects
MouseUp
Charts
Move
ChartTMe
ChartView

A
X
&
rf

a
J.*
a
jdf
a
1 I/O
".
a
a
I9
a

a
a
i t IT
EventMouceMo
)6<AiAtLong-SMIAtLong,AlLong,Aslone)

| Membet
MouseMove
MouseMove
MouseMove
MouseMove
MouseMove
MouseMove
MouseMove
MouseMove
MouseMove
MouseMove
MouseMove

0
f
0
f
f
0
0
0
0
0
0

^11

Object Browser .
. , ,
MouseMove.
, MSForms,

626

V.

U s erF o rm .
Excel C h a r t.
, : Library (),
Class () Member (). , ,
. ,
, ,
.
, Object Browser,
, . ,
.

A p p l i c a t i o n
W orkbook W o rk sh eet.

.
,
A p p lic a tio n .

A p p l i c a t i o n

.
. 19.4 A p p l i c a t i o n
. Excel 2010 ,
.
.
1 9 .4 . , A p p l i c a t i o n

A f t e r C a lc u l a t e



(
, )
(
,
)
( )





,

NewWorkbook
Sheet A c tiv a te
S h e e tB e f o r e D o u b le C lic k
S h e e tB e fo r e R ig h tc lic k

S h e e t C a lc u l a t e
S h e e tc h a n g e
S h e e tD e a c t i v a t e
S h e e tF o llo w H y p e r lin k
S h e e t P i v o tT a b le U p d a te
S h e e t S e le c tio n C h a n g e

627

19. Excel

. 19.4

WindowAct i v a t e

W in d o w D e activa te
WindowResize
W o rk b o o k A c tiv a te
W o rk b o o k A d d in ln s ta ll
W o rk b o o k A d d in U n in s ta ll
WorkbookBef o r e C lo s e
WorkbookBef o r e P r i n t
WorkbookBef o re S a v e
WorkbookDeact i v a t e
WorkbookNewSheet
WorkbookOpen

Application
A p p l i c a t i o n
.
1. .
2. Properties () .
VBA
1, 2 ..
, , clsA p p .
3. A p p l i c a t i o n
W ith E v e n ts , .
P u b lic

W it h E v e n t s

XL As A p o l i c a t i o n

4. ,
A p p l i c a t i o n . ,
VBA ( ).
Dim X As New c ls A p p

5. A p p l i c a t i o n .
W orkbook_Open, .
S e t X . XL = A p p l i c a t i o n

6. - XL .


(. 18).


, ,
( CSV).

628

V.

,
c lsA p p . .
P u b lic

W it h E v e n t s A p p E v e n ts As A p p l i c a t i o n

P r i v a t e Sub A p p E v e n ts _ W o rk b o o k O p e n _
(B y V a l Wb As E x c e l.W o r k b o o k )
C a l l U p d a te L o g F ile (W b )
End Sub

A p p l i c a t i o n , A p p E v en ts
. A ppE vents_W orkbookO pen
.
U p d a te L o g F ile Wb,
. VBA,
.
D im A p p O b je c t As New c ls A p p
Sub I n i t ( )
'
W o rkb o o k_ O p en
S e t A p p O b je c t.A p p E v e n ts = A p p l i c a t i o n
End Sub
Sub U p d a t e L o g F ile (W b )
Dim t x t As S t r i n g
Dim Fname As S t r i n g
t x t = W b .F u llN a m e
t x t = t x t & " , " & D a te & 11, " & T im e
tx t = tx t &
& A p p li c a t io n .U s e r N a m e
Fname = A p p l i c a t i o n . D e f a u l t F i l e P a t h & " \ l o g f i l e . c s v "
Open Fname F o r A p p en d As #1
W r ite # 1 , t x t
C lo s e #1
MsgBox t x t
End Sub

A p p C la ss (
). I n i t W orkbook_Open,
. W orkbook_Open
.
P r i v a t e Sub W o rk b o o k _ O p e n ()
C a ll I n i t
End Sub

U p d a te L o g F ile ( ,
)
: , , , .
W orkbook_Open I n i t . ,
I n i t .
-


- l o g w o rk b o o k o p e n . x ls m .

629

19. Excel

Application
,
, .
, ( Use Form) ,
A p p l i c a t i o n (. 19.9).
.

~ 1 .

Application

.. L

^ l_ 1 .

"l

J L

133

IN K

21.10.2010
SheetSdecbonChange: K5:L9o 1

JL

^ 1

WorkbookOpen: ChtSVaSdEritry.jdsm
vVmdowOeactJvate: appScabon event tracker xJsm appfccaSon event tracter.xbm
WorkbookDeactivate: appfcaton event tracker.xtem
WorkboakActrvate: Oi t9VafcdEntry.)den
WindowActivate: Chl9Va)tdEnfry.xfem ChlSVabdEnfry.xfem
WorttsoofcOpen: ..
WorkbookActr/ate: Ch 19VaidErttry.xJam
SheetSeiectionOiange: 36NL8 1
-; i

T
7
8
9
10
U
13

N ..... j

KJ

------- :-----

JL
j

14

J
6

' M L r v '&."

JL
16

17

f t

JL8
4 ^

19
20

.*

y w .f JL*

-d -
'*>****

22

24

, "<*
, ?:1- * *'

* *

25
1 1 1 1 1 1 1 1 1

26
27

28

i---------------

_________1
________ T

____ 1
_________
: .... ; .

'

. _>
.......... ....
. 19.9. ,
A p p lic a tio n
< * * 1 /* F I I Z ! * ct2 .


- a p p l i c a t i o n e v e n t t r a c k e r . x ls m .

21 ( ,
A p p l i c a t i o n ) . .
P riv a te Sub X L _ N e w W o rk b o o k (B y V a l Wb As E x c e l . W o rkb o o k)
L o g E ve n t "N e w W o rk b o o k : " & Wb.Name
End Sub

L o g E v e n t
. L o g E v e n t .
Sub L o g E v e n t ( t x t )
EventNum = E ven tN um + 1
W ith U s e r F o r m l
W ith . l b l E v e n t s
.A u to S iz e = F a ls e
.C a p tio n = .C a p tio n & v b C rL f & t x t
.W id t h = U s e r F o r m l . F r a m e E v e n t s .W id t h
.A u to S iz e = T ru e

20

630

V.

End W it h
. F r a m e E v e n ts . S c r o l l H e i g h t = . l b l E v e n t s . H e ig h t
. F r a m e E v e n ts . S c r o l l T o p = E ven tN um * 2 0
End W it h
End Sub

+ 20

L ogE vent U serForm ,


C a p tio n L a b e l, l b l E v e n t s . ,
S c r o l l H e i g h t S c r o llT o p
Fram e, F ra m e E v e n ts. L a b e l
Frame.
.
U serF orm .
, 15.

U s e rF o rm
U serForm ,
, ,
. . 19.5 U serForm ,
VBA.
1 9 .5 . , U se rF o rm

A c tiv a te
A d d C o n tro l
B e fo re D ra g O v e r
B e fo r e D r o p O rP a s te
C lic k
D b l C l ic k
D e a c t iv a t e
E rro r
In itia liz e
KeyDown
K e y P re s s
KeyUp
Layout
MouseDown
MouseMove
MouseUp
Q u e ry C lo s e
R e m o v e C o n tro l

U serFo rm

(
)
(
)
,

,

U serF o rm
,

U serFo rm

,

U serF o rm



U s erF o rm

19. Excel

631
. 19.5

Resize

U serFo rm
U serF o rm
U s erF o rm
U serFo rm

S c ro ll
Term inate
Zoom

13-15
.

,
, ,
(A p p lic a tio n , W orkbook, S h e e t ..).
, : OnTime .
A p p l i c a t i o n .

, ,
,
VBA .
O nTim e

OnTime
OnTime .
Excel , 15:00
.
Sub SetAlarmO
A p p l i c a t i o n . O nTim e T im e V a lu e (" 15 : 00 : 0 0 11) ,
End Sub

" D is p la y A la r m "

Sub DisplayAlarm ()
Beep
MsgBox " .
End Sub

!"

S e tA la rm
. !
OnTime A p p l i c a t i o n
OnTime. :
1.... 2 .....I
( 3:00 p.m., 15:00)
, ( . 19.10.
I D isplayA larm ).
S e tA larm D isp la y A la rm
15:00,
, . 19.10.

1(, 20 ), .

632

V.

A p p li c a t io n .O n T i m e
" D is p la y A la r m "

Now + T im e V a lu e (" 0 0 :2 0 : 0 0 " ) , _

OnTime ,
. D i s p l a y
A larm 1 2010 12:01,
A p p l i c a t i o n . O nTim e D a t e S e r i a l ( 2 0 0 8 , 4 , 1)
T i m e V a lu e ( " 0 0 : 0 0 : 0 1 " ) , " D is p la y A la r m "

+ _

O nTim e .
,
.

. 1
. U p d a te C lo ck
1, .
S to p C lo c k . , N e x tT ic k
, .
-


- o n tim e e v e n t d em o . x ls m .
Dim N e x t T i c k As D a te
Sub U p d a t e C lo c k ()
'
A l
T h is W o r k b o o k . S h e e t s ( 1 ) .R a n g e ( " A l " ) = T im e
1

N e x t T ic k = Now + T im e V a lu e ( " 0 0 : 0 0 : 0 5 " )
A p p l i c a t i o n . O nTim e N e x t T i c k , " U p d a te C lo c k "
End Sub
Sub S t o p C lo c k ()
1
O nTim e ( )
On E r r o r Resume N e x t
A p p l i c a t i o n . O nTim e N e x t T i c k , " U p d a t e C lo c k " , , F a l s e
End Sub

O nTim e ,
. ,
S t o p C lo c k ,
( Excel ).
w o rk b o o k _ B e f o r e C lo s e , :
C a ll

S t o p C lo c k

O nTim e
, 18.

633

19. Excel


Excel
. ( ),
. ,
.

, , , .
. ,
, ,
.
W o r k b o o k B e f o r e C lo s e .

.
<PgUp> <PgDn>.
Setup_O nK ey <PgDn>
PgDn_Sub, <PgUp> PgUp_Sub.
<PgDn>
, <PgUp> .
Sub S e tu p _ O n K e y ()
A p p l i c a t i o n .
A p p l i c a t i o n .
End Sub

" {P g D n }" ,
"{P g U p }" ,

Sub P g D n _S u b ()
On E r r o r Resume N e x t
A c t iv e C e l l . O f f s e t (1 ,
End Sub
Sub PgUp_Sub ()
On E r r o r Resume N e x t
A c tiv e C e ll. O f f s e t (-1 ,
End Sub

/ N

"PgD n_Sub"
"PgU p_Sub"

0 ) .A c tiv a te

0 ) .A c tiv a te


- o n k e y e v e n t d e m o .x ls m .
On E r r o r Resume N ext,
. ,
,
. , ,
, , .
,
.
Sub 1 _ ()
A p p l i c a t i o n . " {P g D n }"

634

V.

A p p l i c a t i o n .
End Sub

" {P g U p }"


. Excel
. ,
Excel,
<Alt+F4> ( <Alt>).
A p p l i c a t i o n . " % { F 4 } " /

""


,
(Macro Options). 9.

, , <PgDn>
. . . 19.6
, , .
1 9 .6 .

<Backspace>
<Break>
<Caps Lock>
<Delete> <Del>

{BACKSPACE} {BS}

< i>

{DOWN}

<End>
<Enter>
<Enter> ( )
<Escape>
<Home>
<lns>

{break}
{ capslock}
{DELETE} {DEL}
{END}

~ ()
{ENTER}
{e s c a p e }

{e s c }

{home}
{ in s e r t }

< < ->

{le f t }

<NumLock>
<Page Down>
<Page Up>

{num lock}

< -> >

{ r ig h t }

<Scroll Lock>
<Tab>
<T>
<F1> <F15>

{ scro lllock}

{PGDN}
{PGUP}

{t a b }
{UP}

{ F

I}

{ F15 }

<Shift>, <Ctrl>
<Alt>.
:

635

19. Excel

<Shift> (+);
<Ctrl> ();
<Alt> (%).
, <Ctrl+Shift+A>
:
A p p l i c a t i o n . " + " ,

"S ubN am e:"

<Alt+Fll> (
VB Editor) :
A p p l i c a t i o n .

" ^ { F ll} " ,

"SubName"

W o rk s h e e t_ B e f o r e R ig h tC lic k ,
.
(ThisW orkbook).
P r iv a te Sub W o r k s h e e t _ B e f o r e R ig h t C l ic k _
(B y V a l T a r g e t As E x c e l.R a n g e , C a n c e l As B o o le a n )
C ancel = T ru e
MsgBox " - , ."
End Sub

-
<Shift+F10>. VBA
.
Sub S e t u p N o S h i f t F 1 0 ()
A p p l i c a t i o n . " + { F 1 0 } " ,
End Sub

" N o S h if t F lO "

Sub T u r n O f f N o S h i f t F 1 0 ()
A p p l i c a t i o n . OnKey " + { F 1 0 } | "
End Sub
Sub N o S h if t F lO ()
MsgBox " ."
End Sub

S e tu p N o S h if tF l0
<Shift+F10> , . 19.11. ,
W o rk sh e e t_ B ef o r e R ig h t C lic k
, . , ,
<Shift+F10>, .

,
.
<Windows> <Ctrl>. ,
<Shit+F10>
.

636

V.
_

I... D

*:
F
1 <Shift+flO>

Us.

2
3
4

12

43

43

34

45

565

45

32

43

565

43

43

656

6565

4343

2332

323

2332

10

3232

323

11

__ 2

32

12

__ 2

434
\------

112
___

ZEE

---------------

, .
1
L .
2332

< _ 1

32

---------

13
14
15

16

< [ / te c r l/

,............. } .

I1

. 19.11.
<Shift+F10>
-

- ,
.
s h o r t c u t m e n u s . x ls m :
w o rk b o o k _ 0 p e n s e t u p N o S h if tF io , w o rk b o o k _ B e f o r e C Io s e T u r n O f f N o S h if tF 1 0 .

...

Excel
Excel

Outlook
Excel
SendK eys

Excel
. , .

Excel
Excel,
,
DOS.
.

shell
S h e l l .
S tartC alc Windows.
Sub S t a r t C a l c ()
Dim P ro g ra m As S t r i n g

638

V.

Dim T a skID As D o u b le
On E r r o r Resume N e xt
Program = " c a l c . e x e 11
T a skID = S h e ll( P r o g ra m , 1)
I f E r r <> 0 Then
MsgBox "
End I f
End Sub

" & P rogram , v b C r i t i c a l ,

""

. 20.1.

. 20.1. Windows Excel

S h e l l .
. S h e l l
(
1).
.
S h e l l ,
. , On E r r o r
, .


S h e ll ,
Windows. , ,
( ).
I f A c tiv e W o rk b o o k . P a th <> " " Then _
S h e ll " e x p lo r e r . e x e " & A c tiv e W o rk b o o k . P a th , vb N o rm a lF o cus

, VBA ,
S h e l l . , S h e ll* "
. S h e l l
, .

20.

639

(,
), Excel , .

S h e l l , VBA ,
, VBA.
, , ,
,
. , ,
, S h e l l , .
Declare F u n c tio n O penProcess L ib " k e r n e l3 2 " _
(ByVal d w D e sire d A cce ss As Long, _
ByVal b ln h e r it H a n d le As Long, _
ByVal d w P ro c e s s Id As Long) As Long
Declare F u n c tio n G e tE x itC o d e P ro c e s s L ib " k e r n e l3 2 " _
(ByVal h P ro c e s s As Long, _
Ip E x itC o d e As Long) As Long
Sub S t a r tC a lc 2 ( )
Dim T a skID As Long
Dim h P ro c As Long
Dim lE x itC o d e As Long
Dim ACCESS_TYPE As I n t e g e r , STILL_ACTIVE As I n t e g e r
Dim Program As S t r i n g
ACCESS_TYPE = &H4 00
STILL_ACTIVE = &H103
Program = 11 C a lc .e x e "
On E r r o r Resume N e xt

1
TaskID = S h e ll( P r o g ra m ,

1)

1
hProc = OpenProcess(ACCESS_TYPE, F a ls e ,

T askID )

I f E r r <> 0 Then
MsgBox " " & P rogram , v b C r i t i c a l ,
E x i t Sub
End I f

""

Do 1

'

G e tE x itC o d e P ro c e s s h P ro c ,

lE x itC o d e

D oE vents
Loop W h ile lE x itC o d e = STILL_ACTIVE

' ,
MsgBox Program & " "

End Sub


G e tE x itC o d e P ro c e s s Do L o o p .
lE x it C o d e . , lE x i t C o d e

, , VBA .

640

V.
-

- s t a r t c a l c u l a t o r . x ls m .

A PI- ShellExecute
Windows API S h e l l E x e c u t e .
, ,
. ,
S h e l l E x e c u t e -
, . , ,
, .
API- ( Excel 2010).
P r iv a t e D e c la re P trS a fe F u n c tio n S h e llE x e c u te L ib " s h e l l 3 2 . d l l " _
A l i a s " S h e llE x e c u te A " (B yV al hWnd As Long, _
B yV al lp O p e r a tio n As S t r i n g , B yV al l p F i l e As S t r i n g , _
B yV al Ip P a ra m e te rs As S t r i n g , B yV al l p D i r e c t o r y As S t r i n g , _
B yV al nShowCmd As Long) As Long

S h e llE x e c u t e .
,
JPG.
32, .
Sub S h o w G ra p h ic ()
Dim F ileN am e As S t r in g
Dim R e s u lt As Long
F ileN am e = T h is W o rk b o o k . P a th & " \ f l o w e r . j p g "
R e s u lt = S h e llE x e c u t e ( 0&, v b N u llS t r in g , F ile N a m e , _
v b N u llS t r in g , v b N u llS t r in g , vb N o rm a lF o cus)
I f R e s u lt < 32 Then MsgBox ""
End Sub


.
Sub O p e n T e x tF ile ()
Dim F ileN am e As S t r in g
Dim R e s u lt As Long
FileN am e = T h is W o rk b o o k . P a th & " \ t e x t f i l e . t x t "
R e s u lt = S h e llE x e c u t e ( 0&, v b N u llS t r in g , F ile N a m e , _
v b N u llS t r in g , v b N u llS t r in g , vb N o rm a lF o cus)
I f R e s u lt < 32 Then MsgBox ""
End Sub

, URL-
.
Sub OpenURL()
Dim URL As S t r in g
Dim R e s u lt As Long
URL = " h ttp ://s p r e a d s h e e tp a g e .c o m "
R e s u lt = S h e llE x e c u t e ( 0&, v b N u llS t r in g , URL, _
v b N u llS t r in g , v b N u llS t r in g , vb N o rm a lF o cus)
I f R e s u lt < 32 Then MsgBox ""
End Sub

20.

641

.
,
.
.
Sub S ta r tE m a ilO
Dim A d d r As S t r in g
Dim R e s u lt As Long
Addr = " m a ilto :b g a te s @ m ic r o s o ft.c o m "
R e s u lt = S h e llE x e c u te ( 0 & , v b N u llS t r in g , A d d r, _
v b N u llS t r in g , v b N u llS t r in g , vb N o rm a lF o cus)
I f R e s u lt < 32 Then MsgBox ""
End Sub

-
s h e lle x e c u te exam ples . x ls m .


Excel

. : ,
S h e l l .
.
, .

AppActivate
S t a r t C a l c u l a t o r A p p A c tiv a te
(
). .
A p p A c tiv a te ,
. .
Sub S t a r t C a lc u la t o r ()
Dim A p p F ile As S t r in g
Dim C a lc T a s k ID As D ou ble
A p p F ile = " C a lc .e x e "
On E r r o r Resume N e xt
A p p A c tiv a te " C a lc u la t o r "
I f E r r <> 0 Then
E rr = 0
j
C a lc T a s k ID = S h e ll( A p p F ile , 1)
I f E r r <> 0 Then MsgBox " "
End I f
End Sub

- s t a r t c a lc u l a t o r .x ls m .

213ak. 3107

642

V.

M ic ro s o ft O ffic e
Microsoft Office,
A c t i v a t e M i c r o s o f t A p p A p p l i c a t i o n . ,
Word.
Sub S t a r t W o r d ()
Application.ActivateMicrosoftApp xlMicrosoftWord
End Sub

Word ,
. :

x lM ic r o s o ftP o w e r P o in t;

x lM ic r o s o ftM a il

x lM ic r o s o ftA c c e s s ;

x lM ic r o s o ftF o x P r o ;

x lM ic r o s o ftP r o je c t;

x lM ic r o s o ftS c h e d u le P lu s .

( a c tiv a te s

O u tlo o k ) ;



Windows
,
(Control Panel). Excel
. ,
: (Windows Date and Time Properties),
. 20.2.
-U *l
J | |

. .
1 2
4 5 6 7 8 9
11 12 13 14 15 16
18 19 20
22 23
25 26 27 28 29 30

3
10
17
24
31

_
1 2 2 :3 9 :1 8

: ()

"

-------*

. 20.2. VBA

,
r u n d l l 3 2 . S h e l l .

20.

643


(Windows Date and Time Properties).

Sub S how D ateT im eD lg()


Dim A rg As S t r in g
Dim T a skID As D ou ble
Arg = " r u n d ll3 2 . e x e s h e l l 3 2 . d l l , C o n tro l_ R u n D L L t im e d a t e . c p l "
On E r r o r Resume N e x t
TaskID = S h e ll( A r g )
I f E r r <> 0 Then
MsgBox (" .")
End I f
End Sub

r u n d l l 3 2 . .
r u n d ll3 2 .e x e s h e l l 3 2 . d l l , C o n tro l_R u n D L L _ . c p l , ,

_ . c p l * . CPL ;

* . CPL ( );

t ( , ).

-
, 12
, . 20.3, c o n t r o l p a n e l d i a l o g s . x l s m .
X]

1
_

:
: ( )
: ( )
: ()

( *
()
()
:

. 20.3. ,
,

Excel, Microsoft Word.


, Excel Word
. Excel ,
aWord . , Visual Basic,
Excel.
OLE-, .
.
, ,
, C h art

V.

644

. .
Access .

, Excel, ,
, .
VBA
, ,
. Microsoft Word,
,
(
).


Excel 1^ (Insert^Text^Object)
(, Word) . ,
VBA. (
.)
. ,
. ,
, , .
VBA, ,
, .


.
.
, ,
, .



VBE Tools^References (^).
, . 20.4. ,
, .
Object
Browser ( . 20.5) , .
<F2> VBE.

. , Microsoft Word 10.0 Object Library
( Word 2002), Microsoft Word 11.0 Object Library ( Word 2003) Microsoft
Word 14.0 Object Library ( Word 2010).
:
Dim WordApp As New W o r d .A p p lic a tio n

20.

645

References - VBAProject

-si

Available References;
0 Visual Base For Applications
0 Microsoft Excel 14.0 Object Library
0 OLE Automation________________

Cancel

------------------

AcrobatPDFMaker
AdobePDFMakerX
DataForm
DataForm
Microsoft Forms Z 0 Object Library
PUP7TRIAL
TextToolsV B A
UNSAVED: VBAProject
IAS Helper COM Component 1.0 Type Ubrary
. IAS RADIUS Protocol 1.0 TvDe Library

Microsoft Office 14.0 Object Lforary--------------- ---


Location:

I
Priority

Help

.................

Cp rog ra m FilesVZommon FilesV^ croso ft Shared=14^

Language:

Standard

. 20.4.
'1$Hi

-d

Qtbug

y>ew jnsert

gun

Jooft

ftde-ins

* < J v
I >1 ttelH I

Windmv

*|

~3

........
At

m Global
M Documents
& Document

m conftd
ConMcts
ententeontrol
ContentContfolListE _J

t t DataTable
DefaultWebOptions
Dialog
S Dialogs
Dictionanes
nonary

______

Documents
DownBars
DropCap
0 OropDown
DfopUnes _____

....-p --" -
eff Actr/eDocument
i f f AcSveOocument
AddBlogDoajment
ApplyDocumenfTheme
. 8>>1

1 ListParagraphs
1 Lists
1 UsJTemptates

f NoUneBreakAflet
eff NoLineBreakSetore
e f OMathBreakBm
b91 OMathBreakSub
ef OMathFontName
OMathJc
P OMathLeftMargin
P OMathNarySupSubUm
f OMathRighiMargm
OMattis

Ptooem ttenre As svmj


iMd-orty
D**K>Smembec of Wort} Document

. 20.5. Object Browser ,



,
.
,
. , ,
.
,
, . , Word (
Excel) ,
VBA. -

646

V.

. ,
, .

Object Browser Auto List Members ( )
VBE .
,
.


C r e a t e O b je c t
, G e t O b j e c t .
O b je c t .
.

G e t O b j e c t C r e a t e O b j e c t
VBA, G e tO b je c t C re a te O b je c t, ,
-.
C re a te O b je c t
. ,
. , .
, Excel
XLApp E x c e l . A p p lic a t io n .
S e t XLApp = C r e a te O b je c t( " E x c e l . A p p l ic a t i o n " )

G e tO b je c t , ,
. ,
, Excel M y f i l e . x l s .
w o rkb o o k ( M yf i l e . x ls x ) .
S e t XLBook = G e tO b je c t( " :\ M y f i l e . x l s x " )

,
, . , ,
Word 97 , Word.
Dim WordApp As O b je c t
S e t WordApp = C r e a te O b je c t( " W o r d . A p p lic a t io n " )

Word,
. Word 2003.
S e t WordApp = C r e a te O b je c t( " W o r d . A p p lic a t io n . 1 1 ")

Windows A u t o m a t io n Word,
A p p l i c a t i o n V B A : W o rd . A p p l i c a t i o n .
.
As W o rd . A p p l i c a t i o n As New W o rd . A p p l i c a t i o n ,
A p p l i c a t i o n Word. C r e a t e
O b je c t ( " W o r d . A p p l i c a t i o n " ) , ^
Word Windows.
,
Office 2010. Word 2003 Word 2010,
C r e a t e O b je c t ( " W o r d . A p p l i c a t i o n " )

20.

647

. Word 2010, C r e a t e
O b je c t ( "W o rd . A p p l i c a t i o n . 1 4 "), Word 2010,
.
C r e a t e O b je c t , ,
W o r d . A p p lic a t io n E x c e l . A p p l i c a t i o n ,
, .. . ,
, ,
.

, G e tO b j e c t .

Office

, . ,
Word 2003, Word 2007 Word 2010,
Word 2003
. ,
, Word.


Word
. , ,
Word ( ).
Sub G e tW o rd V e rs io n ()
Dim WordApp As O b je c t
Set WordApp = C r e a t e O b je c t( " W o r d . A p p lic a t io n " )
MsgBox W ordApp. V e rs io n
W ordA pp.Q uit
Set WordApp = N o th in g
End Sub

Word
. ,
, v i s i b l e T rue, .
W o r d A p p .V is ib le = T ru e

.
Tools'^References (^)
Word.
.
Sub G e tW o rdV ersio n ()
Dim WordApp As New W o r d .A p p lic a tio n
MsgBox W o rd A p p .V e rs io n
WordApp. Q u it
Set WordApp = N o th in g
End Sub

648

V.

W ord E x ce l
, ,
Word Excel. MakeMemos Word,
. ,
, . 20.6.

. 20.6. Word Excel

MakeMemos WordApp.
1
Word .
M essa g e ( 6) , .
Word .
Sub MakeMemos()
1 Word
Dim WordApp As O b je c t
Dim D ata As Range, message As S t r in g
Dim R eco rd s As I n t e g e r , i As I n t e g e r
Dim R e g io n As S t r i n g , S alesA m t As S t r i n g , SalesNum As S t r in g
Dim SaveAsName As S t r i n g
'
Word ( )
S e t WordApp = C r e a t e O b je c t( " W o r d . A p p lic a t io n " )
1
S e t D ata = S h e e ts ( " 1 " ) . R an ge ( " A l ")
Message = S h e e ts ( " 1 " ) . R an ge ( "M e s s a g e ")
'
'
'

'
'

1
R eco rd s = A p p lic a tio n .C o u n t A ( S h e e ts ( " 1 ") .R a n g e ( " A : A " ))
F o r i = 1 To R eco rd s

A p p l i c a t i o n . S ta tu s B a r = " " & i

R e g io n = D a ta . C e l l s ( i , 1 ) .V a lu e
SalesNum = D a ta . C e l l s ( i , 2 ) .V a lu e
S alesA m t = F o rm a t(D a ta . C e l l s ( i , 3 ) .V a lu e , " # ,0 0 0 " )

SaveAsName = A p p l i c a t i o n . D e f a u lt F ile P a t h & _
" \ " & R e g io n & " .d o c x "
Word
W ith WordApp

**

20.

649

. D o cu m e n ts. Add
W ith . S e le c t io n
.F o n t. S iz e = 14
.F o n t. B o ld = T ru e
. P a ra g ra p h F o rm a t.A lig n m e n t = 1
.T y p e T e x t T e x t:= "M "
. T yp e P a ra g ra p h
. T yp e P a ra g ra p h
.F o n t. S iz e = 12
. P a ra g ra p h F o rm a t.A lig n m e n t = 0
. F o n t. B o ld = F a ls e
.T y p e T e x t T e x t : =" : " & vbTab & _
F o rm a t(D a te , "d mmmm, y y y y " )
. T yp e P a ra g ra p h
.T y p e T e x t T e x t := ":" & vbTab & _
", " & R e g io n
. T y p e P a ra g ra p h
.T y p e T e x t T e x t : = ":" & vbTab & _
A p p lic a tio n .U s e rN a m e
. T y p e P a ra g ra p h
. T y p e P a ra g ra p h
.T y p e T e x t Message
. T y p e P a ra g ra p h
. T y p e P a ra g ra p h
.T y p e T e x t T e x t : = " :" _
& vbTab Sc SalesNum
. T yp e P a ra g ra p h
. T y p e T e x t T e x t : = " : " & vbTab & _
F o rm a t(S a le s A m t, " $ # ,# # 0 " )
End W ith
.A c tiv e D o c u m e n t. SaveAs F ile N a m e := SaveAsName
End W ith
N ext i

1
W o rdA pp .Q u it
Set WordApp = N o th in g

1
A p p lic a t io n . S t a t u s B a r = " "
MsgBox R eco rd s & " " & _
A p p l i c a t i o n . D e f a u lt F i l e P a t h
End Sub

. 20.7 , MakeMemos.

-

- make memos . x ls m .

. Word.
,
, ! Word
Word.
Excel. , W it h - E n d W ith . 1
W it h E nd W it h . ,
Word ( ) .
Documents .Add

V.

650
I *)*

ft

ie


g l,

&

ft> ;

!)

*
^ 1(^

Mmosott Word

13

[ ,
ia
*
! ,
11
;
.
ft

*
j^ y

*1
^
"

----.

. ^--------------------------!
--------------------------. H i *
. 1
.<*J

'

: 22 , 2010
: ,
: Alex
.
.
.
1 - .
: 477
:
$881 466|
***: 1 * 1 ( , ;sj>

. ................................... ^ J

Z Z Z ^ ^ Z Z

.... - , J

. 20.7. Word Excel

.
W ith WordApp
. D ocu m e n ts. Add
1

End W ith

, Word, .
, ,
. (Immediate)
VBE Word.

E x ce l
Excel (
Visual Basic Word); ,
Excel, Word.
Excel :

A p p l i c a t i o n C r e a t e O b je c t ( " E x c e l . A p p l i c a t i o n " );

W o rk b o o k C r e a te O b j e c t ( " E x c e l . S h e e t" );

C h a r t C r e a te O b j e c t (" E x c e l . C h a r t 11) .

, VBA Word 2010.


Excel W o r k s h e e t ( " E x c e l . S h e e t ") Word.
Sub M a ke L o a n T a b le ()
Dim XLSheet As O b je c t

-------

20.

651

Dim LoanAmt
Dim Wbook As S t r in g

1
LoanAmt = In p u tB o x ( " ? ")
I f LoanAmt = " " Then E x i t Sub

1
T h is D o c u m e n t. C o n te n t. D e le te
'

S h ee t
Wbook = T h is D o c u m e n t. P a th & " \ m o r t g a g e c a lc s . x l s x "
Set XLSheet = G e tO b je c t(W b o o k , " E x c e l. S h e e t" ) .A c tiv e S h e e t

1
X L S h e e t. R a n g e ( " LoanA m ount")

= L oanA m tX LS heet. C a lc u la te

1
S e le c t io n . S t y le = ""
S e le c tio n .T y p e T e x t " : " & _
F o rm a t(L o a n A m t, " $ # ,# # 0 " )
S e le c t io n . T y p e P a ra g ra p h
S e le c t io n . T yp e P a ra g ra p h

1
X L S h e e t. R an ge ( "D a ta T a b le " ) . Copy
S e le c t io n . P a ste
S e le c t io n . T yp e P a ra g ra p h
S e le c t io n . T yp e P a ra g ra p h

1
X L S h e e t. C h a rtO b j e c t s (1) . Copy
S e le c t io n . P a s te S p e c ia l _
L in k : = F a ls e , _
D a ta T y p e : = w d P a s te M e t a file P ic tu r e , _
P la c e m e n t: = w d In L in e

1
Set XLSheet = N o th in g
End Sub

-

-. Word a u to m a te e x c e l.d o c m ,
Excel m o rtg a g e c a lc s . x ls x .
Word M akeLoanTable,
BcTaBKa^Mortgage^Get Mortgage Amount (^^ ).
Excel, Word, . 20.8.
M a k e L o a n T a b le
7 ( L o a n A m o u n t).
F2:I12
( D a t a T a b le ) , . D a t a
Table Excel Word.
. 20.9.

652

V.

. 20.8. Word VBA


[Vfl J

automate excel [ ] - Microsoft Word

I I

i i
I f B l

I T
jj j

j j j *

S3

, , ,

3
Get Mortgage
Amount
Mortgage

!
: $250

6,00%

$1499

$539 595

$289 595

6,25%

$1 539

$554 145

$304 145

6,50%

$1580

$568 861

$318 861

6,75%

$1621

$583 738

$333 738

7,00%

$1663

$598 772

$348 772

7,25%

$1 705

$613 959

$363 959

7,50%

$1 748

$629 293

$379 293

7,75%

$1 791

$644 771

$394 771

8,
00%

$1834

$660 388

$410 388

$2 000
$1 800
$1600
$1 400

$1200
$1000
$800
$600
$400

$200
$0

: 1 I

74 , j g j

() . 3 j , ' Ig I

. 20.9. VBA Word Excel

20.

653


Outlook
Microsoft Outlook.
. 20.10 , :
, . S e n d M a il
()
( Msg).
A

jjones@zx-prrtgfw.com

$20 00

bsmith@zx-prr1gfw.com

$3 500

fsimpson@zx-prrtgfw.com

$1250

3
4

a J
14
! ! . ZJ

LJI
[ill

1
~ .... ~

----------

R< i

____ t o

. 20.10. Outlook

Sub S e nd E m a ilO
' .
' O u tlo o k
Dim O u tlo o k A p p As O u t lo o k . A p p lic a t io n
Dim M Item As O u tlo o k .M a illte m
Dim c e l l As Range
Dim Subj As S t r i n g
Dim E m a ilA d d r As S t r in g
Dim R e c ip ie n t As S t r in g
Dim Bonus As S t r i n g
Dim Msg As S t r i n g

1 O u tlo o k
Set O u tlo o k A p p = New O u t lo o k . A p p lic a t io n

'

For Each c e l l I n C o lu m n s ( " B " ) .


C e l l s . S p e c ia lC e lls ( x lC e llT y p e C o n s t a n ts )
I f c e ll . V a l u e L ik e
Then

S ubj = " "
R e c ip ie n t = c e l l . O f f s e t (0, - 1 ) .V a lu e
E m a ilA d d r = c e ll . V a l u e
Bonus = F o r m a t ( c e ll . O f f s e t (0, 1 ) .V a lu e ,

"$ 0 ,0 0 0 .")


Msg = " " Sc R e c ip ie n t & v b C rL f & v b C rL f
Msg
= Msg & " "
Msg
= Msg Sc Bonus & v b C rL f & v b C rL f
Msg
= Msg & " "
& v b C rL f
Msg
= Msg & " "


S e t M Item = O u tlo o k A p p . C r e a t e lte m ( o lM a illte m )
W ith M item
.To = E m a ilA d d r

V.

654

.S u b je c t = Subj
.B ody = Msg
. Send
End W ith
End I f
N e xt
End Sub

. 20.11 , Outlook.
0

|v

*
4j

- (HTML}

Catibri ( * 11

| := IE - I f iW
& w : %

sergeev@diatektika.com

-'

fsimpsonigzx-iyrtqfw.com

!
, $1250.

W indow s .

. 20.11. Outlook , Excel

,
Outlook. ,
: O u tlo o k Mai l i t e m . :
S e t O u tlo o k A p p = New O u t lo o k . A p p lic a t io n

M a il Ite m .
S e t M item = O u tlo o k A p p . C r e a t e lte m ( o lM a illte m )

, Subj e c t Body,
S end .

(Draft)
save Send.
.
,
, . 20.12.
Outlook 1^

20.

655

Outlook^ (Office^Outlook Options1^


Trust Center).
(Trust Center Settings).
(Trust Center) (Programmatic Access)
(
) (Never Warn Me about Suspicious Activity (Not Recommended)).
, .
-2J-2SJ

M ic ro s o ft O ffice O u tlo o k


. ,
"
.
,
,
".

. 20.12. Excel
Outlook

-
-
personalized emai 1- out l o o k .xlsm.
Microsoft Outlook. -
,
, personalized email-outlook (late binding).xlsm.


Excel.

Excel
, Excel
. , VBA
.
( ) jo e b lo w @ z x -p r r tg fw .c o m .
.
Sub SendWorkbo o k ()
ActiveWorkbook.SendMail

"joeblow@zx-prrtgfw.com", " "

End Sub

SendMail , .
,
() .

656

V.

. 1
.
Sub S e n d a s h e e t()
A c tiv e W o rk b o o k . W o rk s h e e ts ( " 1 " ) . Copy
A c tiv e W o rk b o o k . S e n d M a il " jo e b lo w @ z x - p r rtg fw .c o m " ,
A c tiv e W o rk b o o k . C lo s e F a ls e
End Sub

" "


(, 2 . x l s x ) . ,
, ,
. 1
. x l s x .
VBA K i l l .
Sub S endO neS heet()
Dim F ile n a m e As S t r i n g
F ile n a m e = " .x l s x "
A c tiv e W o rk b o o k . W o rk s h e e ts ( " 1 " ) . Copy
A c tiv e W o rk b o o k . SaveAs F ile n a m e
A c t iv e W o rk b o o k . S e n d M a il " j o 'e b lo w @ z x -p rrtg fw . com" , " "
A c tiv e W o rk b o o k . C lo s e F a ls e
K i l l F ile n a m e
End Sub

, Excel
PDF-
.
. SendSheetAsPDF,
PDF-,
, (
PDF-).
(Send).
Sub SendSheetAsPD F()
C om m andBars.ExecuteM so
End Sub

( " F ile E m a ilA s P d fE m a ilA tta c h m e n t")

Excel , Outlook.
PDF-, Outlook
, PDF-.
Sub SendAsPDF()
1
1 O u tlo o k
Dim O u tlo o k A p p As O u t lo o k . A p p lic a t io n
Dim M Item As O b je c t
Dim R e c ip ie n t As S t r i n g , S ubj As S t r in g
Dim Msg As S t r i n g , Fname As S t r in g
'


R e c ip ie n t = " m ybo ss@ xre d iyh .co m "
S ubj = " "
Msg = " , PDF- ."
Msg = Msg & vbN ew Line & vbN ew Line & "- "
Fname = A p p l i c a t i o n . D e f a u lt F ile P a t h & " \ " & _

**

20.

657

A ctive W o rkb o o k.N a m e & " . p d f "


A c tiv e S h e e t. E x p o rtA s F ix e d F o rm a t _
T y p e : = xlT ype P D F , _
F ile n a m e := Fname

O u tlo o k
Set O u tlo o k A p p = New O u t lo o k . A p p lic a t io n

1
Set M Item = O u tlo o k A p p . C r e a t e lte m ( o lM a illte m )
W ith M item
.To = R e c ip ie n t
.S u b je c t = S ubj
.B ody = Msg
.A tta c h m e n ts .A d d Fname
.Save 1 ( D r a fts )
1 . Send
End W ith
Set O u tlo o k A p p = N o th in g

'
K i l l Fname
End Sub

-
-
send p d f v i a o u t lo o k . xlsm .

SendKeys
He .
. Excel S e n d K e y s ,
.
S e n d K e y s
, .
,
. ,
, S e n d K e y s , . ,
S e n d K e ys .
S e n d K e y s
Windows Calculator (). T e s tK e y s
( ^ (View^Scientific)).
Sub TestK eys ()
S h e ll " c a lc . E x e " , vb N o rm a lF o cus
A p p lic a t io n . SendKeys "%vs"

End Sub

<Alt+V> (
<Alt>), <S>.
S e n d K e y s ,
(,
<Alt> <Ctrl>).

V.


T e stK e ys
Windows 7. Windows 7
, Windows ,
.
, Windows 7 SendKeys,
(
). , SendKeys
.

...

Excel


XLAM XLSM
VBA

,

.
, Excel.


Excel, ,
.
,
.
, ,
. , Excel
.
(Analysis ToolPak).
, Excel .

660

V.

,
.
, .


Excel
Excel.
. ,
. Excel
XLSM ( ).

I s A d d in T h is W o r k b o o k ()
T ru e . F a ls e .

,
^^ (View^Window^Unhide).
,
, .

W orkbooks
A d d in s.
W orkbooks (. ).


(Add-Ins). 1^
Excels (File>=>Excel Options1^ Add-Ins).
Excel (Excel Options) (Manage)
Excel (Excel Add-Ins) (Go).
Excel.

, ,
(Macro). ^
^ (Developer^Code^Macros) 1^ ^ (ViewO
Macros^Macros).

, ,
.

Excel
. Excel 2007 ,
, x l a x l a m ,
(. 21.1).
,
Excel.
. ,
? \

. ?

IL

. 21.1. Excel ,

21.

661


,
Excel .
.
, .
,
.
.
, , ,
, .
, .
.
, ,
. , N e w fu n c s
MOVAVG,
:
= N e w fu n cs. x ls m ! MOVAVG(A l :A5 0)

,
, .
=MOVAVG(Al: 5 0 )

.
, (Add-Ins)
.
.
Excel ,
.
.
?.


,
(Trust Center).
^^ (Developer*^Macros
Security). (Developer) ,
^ ^
(File^Excel Options^Trust Center)
(Trust Center Settings).

Excel COM (Component Object Model).
.d l l ..
, Office,
.
, . XLAM,

V.

662

Excel.
Visual Basic 5 ( ), Visual Basic .NET.
.

Excel

(Add-Ins), ^
^ (File1^ Excel Options ^Add-Ins).
Excel (Excel Options) (Manage)
Excel (Excel Add-Ins) (Go).

Excel (Add-Ins)
<Alt+TI>. Excel 2010
(Add-Ins),
(Developer).
Excel (Add-Ins) . 21.2.
,
. ^
.
I

............. ::

.... i

7 Enhanced Data Form v3a


7 Enhanced Data Form v3b
17 export charts.xlsm
Power Utility Pakv6
[ 7 Power Utility Pakv7

17 Text Tools Utftty


...

...

- VBA
"!

Demonstrates how to determine if an add-in ts installed


properly, or opened directly.

. 21.2.

^
(File^Open).
, 1^ (File^
Close). Excel
VBA, ,
.
W o rk b o o k s ( "m y a d d in . x la m " ) . C lo s e

21.

663

^ (File^Open)
, .
Excel.
, :
. ,
(Analysis ToolPak) :
1^ ^ (Data^Analysis^Data Analysis).
Excel (Euro Currency Tools)
(Formulas) (Solutions).
,
(Insert Function)
(Function Library).

, Excel 2007,
,
.
, (
), ^ (Add-lns^Menu
Commands) ^ (Add-Ins^
Custom Toolbars).


, ,
. (
).
,
. , , ,
, , .
, ,
, .
.
.
1. , .

2. ( )
.
.
Excel 22 23.
3. Visual Basic Editor (VBE)
Project ().

4. Tools^xxx Properties (1^ ),


. Protection ().
Lock Project for Viewing ( )
. .

664

V.
,
U se Form .

5. Excel ^
(Developer^Modify1^Document Panel)
(Document Properties).
6. (Title)
(Comments).
,

(Add-Ins).

7. ^ (File^Save As).
(Save As).
8. (Save As)
(Save as ) Excel (Add-In (*.xlam)).
9. (Save).
( . xlam ), .

10.
.
11. , .
, .
.

, ,
. ,
Excel 5/95, Excel
.
,
^ (File^Save As).


.
,
.
^ (Chart Tools^Design).
. 21.3. ,
, .

-
x ls m Export Charts ( e x p o r t c h a r ts .x ls m )
-.
.

21.

665
*1



Chart 1

chart_l.gif

0 | Chart 2

chart_2.gif

Chart 3

chart_3.gif

(IgpgHHgHQB

D:\wofk\yoKeH6axpisk\Chapter 21

W .

. 21.3. Export charts


,
. .
1. ,

.
U s e r F o r m UserForml.
.
.
U s e r F o r m UserForm2.
(Rename)
.
U s e r F o r m UserForm3.
.
Export Charts.
(Dont Show This Message Again).
VBA Modulel. ,
, U s e rF o rm
U s e r F o r m l.
T h i s W o r k b o o k ().
W o rk b o o k Open,
.
XML-, .
Excel. 22
RibbonX.


^
^ (Developer^Modify^Document Panel).
(Document Properties), .

V.

666

(Title) .
(Add-Ins).
(Comments) .
.
, .


Microsoft Excel
. Excel
.
Excel 2002 ,
.
, Excel
.


.
1. VBE ,
, Project ().

2. Debug'MCompile (^).
VBA,
, .
, Excel ,
.

3. Tools^xxx Properties (** ),


, Project Properties (
). General () .
VB V B P r o je c t .
E x p C h a r ts . ,
.
4. * . XLSM. ,
, XLSM ( )

XLAM.

5. Project Properties ( ) Pro


tection (). Lock Project for Viewing (
) .
- ,
.

6. .
, . 5 6.

7. Excel ^ (File^Save As).


Excel (Save As).

21.
8. (Save as )
Excel (Excel Add-In (*.xlam)).

667

9. (Save).
, (XLSM-)
.
.

Excel

(Add-Ins) Excel. 1^
Excel ^ (File^Excel Options^Add-lns).
Excel (Excel Options) (Manage)
Excel (Excel Add-Ins) (Go).
. .
VBA, (Add-Ins)
T i t l e A d d in A d d in s .
, , i n s t a l l e d ,
T ru e .
.
,
. (Browse),
.
(Add-Ins) :
xlam Excel 2007, x l s m ;
x la Excel, , Excel 2007,
XLS-;
x l l DLL.
(Automation), Excel 2002
, .
, (Automation Servers)
, ,
Excel.
A d d in s Add
VBA A d d in s, VBA.
VBA, i n s t a l l e d A d d in
True. F a ls e , .

Windows Excel. ,
Excel.


XLSM
.
.

V.

668

1. ^ E x cels (File1^ Excel Options^


Add-Ins).

2. Excel (Excel Options)


(Manage) Excel (Excel Add-Ins)
(Go) <Alt+TI>.
Excel (Add-Ins).
3. (Browse),
.

(Add-Ins). . 21.4,
(Add-Ins)
, Properties.
4. .
Export Charts
^ (Chart Tools1^Design) Export Charts
( ) .
(Export Charts),
. ,
1^ ,
( ).


.
Export Charts.
, .
, , -.
- (
). , File^
Save (^) VBE.



XLAM ( XLSM )
. ,
.


, , VB, . VBE
Project ().
.
VBE ( File^Save (^)).
, ,
Excel I s A d d ln F a ls e .

21.

669

T h is W o r k b o o k ()

Properties

() (. 21.5).
I s A d d ln T ru e .
I s A d d ln F a ls e , Excel XLAM.
| P ro p e rtie s - T h isW o rk b o o k

|T h is W o rk b o o k Workbook
Alphabetic

jCategorized j

ChangeHistor yDura ton

ChedcCompatibility

pFzfec___

Con flictResokj bon

11 - xlUserResolution

Date1904
i*DisplayDr awingObjects
DtsplaylnkComments
<DoNotPromptForConvert
Enable AutoRecover

False
-4104 - xtt>splayShapes
True
False
True

lEncryptionProvider

XI ill

False

Final

False

ForceFuBCalcula bon

False

HtghlightChangesOnScreen

^-1
Enhanced Data Form v3a

JTrue________

IsAddln

|False

iListChangesOnNewSheet
Power Utility Pak v6
7 Power Utility Pak v7
|7 Text Tools Utility

"
" - VBA

...

(Password
PersonalVtewListSettmgs

,..

False

4 :InactiveLisffiorderVisible
jKeepChangeHtstory

7 Enhanced Data Form v3b

jI

Envelope Visible

M PersonalViewPrintSettings
PrecisionAsDisplayed
ReadOnlyRecommended

Jd

Tru&
False
********
[True

- 1

jiFafae
False

IRemovePersonallnformabon False

Saved_________________ [True______ SaveUnkValues


< ShowConflictHistory

[True

|1|
____________

llru e
1False

IShowPivotChartAcbveFields False
ShowPivotTableFieldList
charts, xlsm - ........

----------------

--------

GIF, PNG, P G TIF

. 21.4.

Aj remplateRemoveExtData
11 UpdateUnks

11

(True
[False______________ ~

1 - xRjpdateLrnksUserSetting

UpdateRemoteRefierences

True

WntePassword
1

I********

. 21.5.

,

.
Excel?
VBA ?
VBProject. .
?

(Add-Ins)?
VBA,
, P r iv a te ?
,
(Insert Function).

670

V.
Debugs Print ( ) ?
,
?
?
? .
.

x l a m

xlsm

XLAM
XLSM. ,
, ,
, ,
.
XLSM , .
VBA XLAM ,
.


A d d in s,
W orkbooks.
W orkbooks A p p l i c a t i o n , ,
. ,
M y a d d in . xlam .
Dim T e s tA d d in As W orkbook
S e t T e s tA d d in = W o rk b o o k s ( "m y a d d in .x la m " )

Work
b o o k s. ,
M yad d in . xla m .
Dim w as W orkbook
F o r Each w i n A p p l i c a t i o n . W orkbooks
MsgBox w . Name
N e xt w

, F or N e x t
M y a d d in .x la m (, , Excel )
(Add-Ins).
Dim a as A d d in
F o r Each a i n A p p lic a t io n . A d d in s
MsgBox a . Name
N e xt a

x s l m x l a m

. ,
.
MsgBox A c tiv e W o rk b o o k . W indow s. C ount

21.

671


^1^ (View^Window^Hide) V i s i b l e .
.
Dim Win As Window
For Each Win I n A c tiv e W o rk b o o k .W in d o w s
W in . V is ib le = F a ls e
Next Win

,
(). , ^1^
(View^Window^Switch Windows) .
M y a d d in . x la m , 0.
MsgBox W o rk b o o k s ( "m y a d d in . x la m " ) . W indow s. C ount

x l s m x l a m
, ,
. , , XLSM
, .
VBA ,
, . ,
W orkbooks,
, . ,
1 M y a d d in . x la m ,
.
MsgBox W o rk b o o k s ( " m y a d d in .x la m " ) .W o rk s h e e ts ( 1 ) . R a n g e ( " A l" ) .V a lu e

, ,

.
,
( ).
Sub C opySheetFrom Addin ()
Dim A d d in S h e e t As W o rksh e e t
Dim NumSheets As Long
Set A d d in S h e e t = W o rk b o o k s ( "m y a d d in .x la m " ) . S h e e ts (1)
NumSheets = A c tiv e W o rk b o o k . S h e e ts . C ount
A d d in S h e e t. Copy A f t e r : = A c tiv e W o rk b o o k . S heets(N um S heets)

End Sub

, , VBA .
.
Sub CreateNewW orkbook ()
W orkbooks( "m y a d d in . x la m " ) . S h e e ts ( 1 ) .Copy
End Sub

, ,
. VBA
T h isW o rkb o o k ()
. ,

672

V.
VBA .
1 1.
MsgBox ThisWorkbook. S h e e ts ( " 1 " ) . R ange("A l").V alue

V B A -
VBA, ,
XLSM.
1^ ^ (View^Macros^Macros),
(Macro) , .
Excel .

,
(Macro) (Run)
. Sub
, .

, ,
(Macro), .
(
, ),
( ).
ime, .
R un A p p l i c a t i o n
, .

A p p lic a tio n . Run "myaddin.xlam !DisplayNam es"


Tools ^References
(^) VBE, .
VBA,
. R un :
, P r i v a t e .
D is p la y N a m e s ,
, Tools'^ References.

C a ll DisplayNames


(Macro).
, , , ,
XLSM.
, Excel (Insert
Function), (User Defined), .
, ,
P r i v a t e , .
P r i v a t e , VBA,
.

21.

673

,
P r iv a t e , (Lookup Wizard).
Excel,
- Microsoft.
(Insert Function).
(User Defined) (Insert Function)
,
(. 21.6).
, ,
P r iv a t e .
I - 1 2

:
[ ,
[, ""
: j

:
SetValueEx
TransJatEStringToPDFtncodmg
TwoCharStrToInt
Utiiities.GetVersion

WaitforFfleModify Access
|WaitForFileWnteAccess

z i

W a it f orFrteAccess(friefta m e; m a x R e try T im e )
.

~j

. 21.6.
P riv a te ,

, ,
, . ,
MOVAVG n e w fu n c s .x ls m ,
, :
=newfuncs. x ls m ! MOVAVG(A l : A5 0)

,
, :
=MOVAVG (A l : 5 0)


(Macro) ,
. ,
(
). Object Browser.
(Euro
Currency Tools). Excel ,
. 22 . 3107

V.

674

Solutions (), (Formulas).


Euro Conversion ( )
Euro Conversion ( ). .
1. VBE eurotool . x la m Project
().
2. <F2> Object Browser.
3. Libraries () E u ro T o o l.
eurotool . x l a m ,
.

liJ iU lJ j
- a jjf r

4 31

( . )

It
(*durtudl)
I f pup
I f TextToohVBA(text tooh.xUm)
VMPnqcct (ptso
| f VWrotect (cbcdi ad

eg ddSetecledHem

fmoConvetaoo

SfteetH
SheedS
& Sheene

&

SheettO
Sheet?12
Siwet24
SheeUS

F^oiecifiifoTooi
cwsottteoaitff
}

4. Classes (),
.
3 U serForm , 6 VBA 19 . Excel
,
.
Immediate .
W o rkb o o ks( " e u r o t o o l. x la m " ) .S h e e ts ( 1 ) .Copy

,
.
W o rk b o o k s ( " e u r o t o o l . x la m " ) . Is A d d in = F a ls e

,
eurotool . x l a m . ( ) ,
.
, , ,
.
. ,
.
. , ThisW orkbook,
E u ro C o n ve rs io n W iz a rd .
. :
A p p l i c a t i o n . Run " e u r o t o o l . x la m ! T h is W o rk b o o k . E u ro C o n v e rs io n W iz a rd "

21.
1 -.......
2 Accelerator

;
Caption

ftS S
g(S):

a te

S3<):
aitfCD:

10

11

12

675

|0|

g < p):

* 5 4 0 ):

S o u

13
14

<unused>

- !
Euro Conversion.
, VBA
Euro Conversion ( ).

VBA
VBA,
.
A d d in s , Excel.
, .
(Add-Ins) A d d in s.
, .

Vffijgp

Excel 2010 A d d in s 2 .
A d d in s ,
File^Open (^).
XLM.

Addins
, A d d in s ,
. Excel , ,
Windows. Excel 2010
:
HKEY_CURRENT_USER\Sof t w a r e \M ic r o s o f t \ O f f ic e \ 1 4 . 0 \E x c e l\ A d d - in M anager

Windows (Regedit.exe)
. ,
, Excel, .
, , ,
( ).
cAprogram F i le s \ M i c r o s o f t O f f i c e \ O f f i c e l 4 \ L i b r a r y

A d d in A d d in s ,
VBA.

V.

676

, (Add-Ins),
(Browse) .
A d d in s Add
A d d in s.
A p p lic a tio n .A d d in s .A d d

" : \ f ile s \ n e w a d d in . x la m "

A d d in s
, (Add-Ins)
. ,
, .
(,
-), Excel Add.
M y a d d in . x lam
A d d in s. ( T rue)
. ,
.
A p p lic a tio n .A d d in s .A d d

" e : \ m y a d d in . x la " ,

T ru e

A d d in s .
i n s t a l l e d True.

Windows , Excel
. Excel
( ),
, A d d in s
Excel.

Addins
,
A d d in s. A d d in s D e l e t e Remove.
(Add-Ins)
(
regedit.exe).
Excel. ,
.
A d d in s ,
XLAM ( XLA),
.
, . 21.7.
A d d in s.

. 21.7. Addins

21.

677

A d d i n
A d d in A d d in s . ,
, , A d d in s , :
gbox A d d in s ( 1 ) .Name

A d d in 14 , . . ,
.
Name

. Name ,
;
Name.
Pat h

, , ,
.
Full name

, ,
. , Name P a th .
' .
jgBox A d d in s ( 1 ) .P a th & " \ "
jgBox A d d in s ( 1 ) .F u llN a m e

& A d d in s ( 1 ) .Name

Title
, . T i t l e ) (Add-Ins).
, (Document Properties). ^^ (Developer^
[odify1^Document). XLSM- ( 5 ).
Windows
(Properties).
)etails) . ,
Excel.
, Name,
A d d in s . Name
T i t l e . Analysis ToolPak ( ),
n a ly s 3 2 . x l l , T i t l e Analysis ToolPak.
ub ShowName ()
MsgBox A d d in s ( " A n a ly s is T o o lp a k " ) .Name
nd Sub

V.

678

, , ,
^.
Name.

C om m ents
,

(Add-Ins), . Comments
.
(Properties)
. 255 ,
100.
Comments ,
, .

I n s t a l l e d
I n s t a l l e d T ru e , (..
(Add-Ins) ).
I n s t a l l e d T r u e .
F a ls e
. (.. ) Analysis ToolPak
( ) VBA.
Sub I n s t a ll A T P ()
A d d in s ( " A n a ly s is T o o lP a k " ) . I n s t a l l e d
End Sub

= T ru e

(Add-Ins)
Analysis ToolPak (
). , I n s t a l l e d
T r u e - .
(), I n s t a l l e d F a ls e .

^
(File^Open), .
, I n s t a l l e d F a ls e .
L i s t A l l A d d l n s , ,
A d d in s , Name, T i t l e , I n s t a l l e d , C om m ents P a th .
Sub L i s t A l l A d d i n s ()
Dim a i As A d d in
Dim Row As Long
Dim T a b le l As L is t O b je c t
C e l l s . C le a r
R a n g e ( " A l:E l" ) = A r r a y ( "N am e", " T i t l e " ,
"C om m ents", " P a th " )
Row = 2
On E r r o r Resume N e x t
F o r Each a i I n A d d in s
C e lls (R o w , 1) = a i.N a m e
C e lls (R o w , 2) = a i . T i t l e
C e lls (R o w , 3) = a i . I n s t a l l e d

" I n s t a lle d " ,


**

21.

679

C e lls (R o w , 4) = a i.C o m m e nts


C e lls (R o w , 5) = a i. P a t h
Row = Row + 1
N e xt a i
On E r r o r GoTo 0
R a n g e ( " A l" ) . S e le c t
A c t iv e S h e e t. L is t O b je c ts .A d d
A c t iv e S h e e t. L i s t O b j e c t s ( 1 ) .T a b le S ty le = _
" T a b le S ty le M e d iu m 2 "
End Sub

. 21.8 .

>;]dataform3.xla

Enhanced Data Form v3b


export charts xlsm___

Demonstrates how to determine if an add-in is ins D:\work\Yc


______ _____________
C:\Oocuments and Settlngs\Alex\Appltcation Data\Microsoft\Addins

Enhanced Alternative to Excels Data Form


(Version 3.0b)
Copyrifht 1997-2010, J-Walk && Associates.......... *\$\(* lS\dataform
&, PNG. JPG TIF D:\work\yoKeH6ax\Plsk\Chapter 21

Power Utility Pak v7

C:\Program Files\pup7

f EUROTOOLXLAM


VBA

C:\MSOffice2Q10\Officel4\Library
C:\MSOffice20W\Officel4\tibrary\Analyste
C.\MSQffice?010\Officel4\Ubrary\Analysis

. 21.8 . Addins

-
-
lis t

a d d - in in f o r m a tio n .x ls m .

, ,
is A d d in .
, ,
Is A d d in T rue.
,
is A d d in F a ls e .
Excel, VBA .


, :
(Add-Ins) ^ (File^Open).
.
: ^
I n s t a l l e d True. ,
.

VBA. , :
Workbooks ( "m y a d d in . x la m " ) . C lo se

V.

680

c lo s e
, i n s t a l l e d
F a ls e . (Add-Ins)
.
i n s t a l l e d
F a ls e .
, , Excel
.
.

Addin
A d d in : A d d l n l n s t a l l (
) A d d l n U n i n s t a l l ( ).
,
T h is W o r k b o o k (), .
,
.
P r iv a t e Sub W o r k b o o k _ A d d In In s t a ll()
MsgBox ThisW orkbook.N am e & " ."
End Sub

He A d d l n l n s t a l l Open. A d d ln
l n s t a l l ,
, .
, w o rk b o o k _ 0 pen.

19.


,
, .
.

VBA,
.

A p p li c a t i o n .S c r e e n U p d a t i n g
F a l s e ,
, .

,
.

21.

681

O p tio n E x p l i c i t ,
.

,
. , S e r i e s ,
.
Dim S I As S e r ie s
S et S I = A c tiv e W o rk b o o k . S h e e ts ( 1 ) . C h a r t O b je c ts ( 1 ) . _
C h a r t . S e r ie s C o l l e c t i o n (1)

.
As Ob j t .

W ith -E nd W ith
, .

, .

, VBA,
.
, .
.
.

,
.
.
:
A p p l i c a t i u o n . C a lc u la t io n = x lC a lc u la tio n M a n u a l


,
.

.
,
.

.
.
, .
,
.


,
(Add-Ins), ^
(File^ Open). , ,
,
, .

V.

682

,
(. 21.9). (Yes) .
(No) , ,
.
check addin.xlam

*1

. ?

J /
- .
- ,
-

. 21.9.

, (Cancel). ,
T h is W o r k b o o k ().
, A d d l n l n s t a l l O pen
.
Dim I n s t a ll e d P r o p e r l y As B o o le a n
P r iv a t e Sub W o r k b o o k _ A d d in In s ta ll()
I n s t a ll e d P r o p e r l y = T ru e
End Sub
P r iv a t e Sub W orkbook_O pen()
Dim a i As A d d in , NewAi As A d d in
Dim M As S t r i n g
Dim Ans As I n t e g e r
'
?
I f I n s t a ll e d P r o p e r l y Then E x i t Sub

A d d in s ?
F o r Each a i I n A d d in s
I f a i.N a m e = ThisW orkbook.N am e Then
I f a i . I n s t a l l e d Then
MsgBox " ." , _
v b ln f o r m a t io n , ThisW orkbook.N am e
E x i t Sub
End I f
End I f
N ext a i

'

A d d in s , .
= " . ? "
= & vbN ew Line
= & vbN ew Line & " - .
"
= & vbN ew Line & " - , _
. "
= & vbN ew Line & " - "
Ans = MsgBox(M, v b Q u e s tio n + vb Y e sN o C a n ce l, _
T h i sW o rkb o o k. Name)
S e le c t Case Ans
Case vbYes
' A d d in s .
S e t NewAi =

21.

683

A p p lic a tio n .A d d in s .A d d ( T h is W o r k b o o k . F ullN am e)


N ew A i. I n s t a l l e d = T ru e
Case vbNo

1 ,
Case vb C a n ce l
T h is W o rk b o o k . C lo se

End S elect
End Sub

.
,
(Add-Ins). .

(Addins). .

( ^ (File1^
Open). A d d in s.
, .
( ^ (File1^
Open). A d d in s.
, .
,
- .
( Excel)
. ,
.

-
-
ch e ck a d d in . xlam .
( (Add-Ins)
^ (File^Open)).


,
.
, .
.
Path , .
, ,
, , .
.
Sub GetHelp ()
A p p lic a tio n .H e lp T h is W o rk b o o k . P a th & " \ u s e r h e l p . chm "

End Sub

API- Windows,
, Windows .
DLL,

684

V.

W in d o w s\S y stem ( -).


S y ste m Windows API G e tS y s te m D ir e c to r y .

Ex cel
Excel Excel 2007 (
) Compatibility Pack,
Microsoft. ,
Excel 2007 Excel 2010,
Excel. .
Sub C h e c k V e rs io n ()
I f V a l( A p p lic a t io n . V e r s io n ) < 12 Then
MsgBox " E x c e l 2007 _
"
T h is W o rk b o o k . C lo se
End I f
End Sub

V e r s io n A p p l i c a t i o n . ,
12 . 0. VBA V a l,
, .


26 .

...
22


23


24


25

22


...

VBA

Excel 2007
. XML,
VB.


Excel 2007
, .
,
.
Excel ,
. ,
.
.

. Microsoft
.
Office .
. Excel 2007
Excel 2003.
, , ,
. ,

, .

VI.

688

,
.
.
. Excel.

(File). ,
(, , ..).

(). Excel
. ,
, /,
.

(Insert).
, , ..

(Page Layout). ,
,
.

(Formulas). ,
, , Excel.

(Data). ,
Excel.

(Review). ,
, ,
.

(View). ,
.
.

(Developer). .
, .
^ Excel (File^Excel Options)
(Popular).
(Show Developer Tab in the Ribbon).

(Add-Ins). ,
,
( Com m andBar).
Excel 2010 ,
.

Excel.
, .
. 22.1 (),
. .
. ,
, . , .
.
, , ,
.

22.

689

. 22.1.


, .
( ),
. ,
, .
, .
/
<Ctrl+F1> ,
Excel.
C om m andBar Excel 2 010

Excel 97
. CommandBar.
CommandBar.
.
, .
. (Worksheet)
(Chart).
.
.
, Excel 2007 Excel 2010 -
CommandBar,
( ).
VBA, , CommandBar (.
). ,
CommandBar Excel 2007 Excel 2010 .
,
(Add-Ins). ,
, .
.
Excel 2003
Excel 2007 Excel 2010.
Excel 2007 Excel 2010,
, .
, VBA ,
.

690

VI.


CommandBar (.
).
CommandBar
.
Excel 2010 ,
23.

VBA
, , : , VBA?
, .

22.

691

, VBA:

, ;

, ;

, (
);

,
( );

, ;

,
VBA ( ):

, ;

;
;
;

Excel 2010
(Customize Ribbon),
Excel (Excel Options). ,
VBA .


, Excel 1700
. ,
VB .
, ,
E n a b le d () V ie w C u s to m V ie w s . (
,
^ (View1^ Workbook Views).)
MsgBox A p p l i c a t i o n . CommandBars. G e tE n a b le d M so ( "V ie w C u s to m V ie w s ")

, .
( ^^ (Inserts
Tables^Table)), V ie w C u s to m V ie w s .
.
(Customize Ribbon) ,
^ Excel (File^Excel Options).

692

VI.

.
(. 22.2).

IS

JJXJ

6 :

~3

03
EJ

pi
[ jj

41

I I
SI G7 ------ -------------------
--------------------------------------------------
! ' | | (ViewCustomViewsi

j
:

CPynny j

Cfepoc ^

..

. 22.2. Excel

, VBA,
, .

-
- ,
Excel.
,
, . . 22.3
( r ib b o n c o n t r o l names, x ls x ) .


G e tE n a b le d M s o
Com m andBar. Com m andBar,
. id M s o ,
.

E x e c u te M s o .

G e tE n a b le d M s o T ru e ,

G e tlm a g e M s o .

22.

693

D l
Access Toolbar
Access Toolbar
None (Quick Access 1
Access Toolbar

FllePrintPrevlew
Spelling_________

None (Quiet Access


None (Quiet Access
None (Quiet Access

I, SortAscendingExcel
BsoftDescgndlngExcel
FlleOpenRecentFlle
14 TabHome
15 GroupClipboard
16; PasteMenu_____

None (Quiet Access


None (Quiet Access Too
None (Quiet Access

j
j

!
j

:k Access Toolbar
Access Toolbar
t Access Toolbar
Access Toolbar
Access Toolbar
Access Toolbar
jt Access Toolbar
t Access Toolbar

19 PasteUsmgT&xtlmportWuard
jsteRefreshableWtebQuery
I] PasteSpecialDialog
23 CopySplit Button __
25 copy
26 CopyA-jPicturp
FormatPainter
(f ShowCllpboard

GroupClipboard
GroupClipboard
GroupClipboard
GroupClipboard
GroupClipboard
GroupClipboard
GroupClipboard CopySplitButton
GroupCI i pboard CopySplitButton

18046

10
190b/

bcodano /

. 22.3. ,

G e tL a b e lM s o .

G e tP re s s e d M s o T ru e ,

( ).

G e t S c r e e n t ip M s o

(, ).

G e t S u p e r t ip M s o

( ,
).
. ,
VBA ?
, .
VBA (Selection ) ,
Excel 2007, .
Application.C o m m a n d B a r s .E x e c u t e M s o ("SelectionPane")


(Paste Special).

Application.CommandBars.E x e c u t e M s o ("PasteSpecialDialog")

,
. , ,
(Formula ), .
MsgBox A p p l i c a t i o n .Co m m a n d B a r s .Get P r e s s e d M s o ("ViewFormulaBar")

,
( ) .
D is p la y F o r m u la B a r A p
p lic a t io n .
Application.DisplayFormulaBar = True

VI.

694

T rue,
(Merge & Center). (
, .)
MsgBox A p p l i c a t i o n . CommandBars. G e tE n a b le d M s o ( "M e rg e C e n te r")

VBA ActiveX Im age


, G etlm ageM so ,
(Find & Select),
(Editing) ().
Sub Im ageO nS heet()
Dim Mylmage As O LE O bject
S e t Mylmage = A c t iv e s h e e t . O L E O b je c ts .A d d _
(C la s s T y p e : = "F o rm s . Im a g e . 1 " , _
L e f t : =50,
T o p :=50)
W ith M ylm age. O b je c t
.A u to S iz e = T ru e
.B o r d e r S ty le = 0
. P ic t u r e = A p p l i c a t i o n . CommandBars. _
G e tlm a g e M s o ( "F in d D ia lo g ", 32, 32)
End W ith
End Sub

Im age (
Image 1), ,
.
P r iv a t e Sub U s e r F o r m _ I n i t i a li z e ()
W ith Im a g e l
. P ic t u r e = A p p lic a tio n .C o m m a n d B a rs . _
G etlm a ge M so ( " F in d D ia lo g " , 32, 32)
.A u to S iz e = T ru e
End W ith
End Sub


VBA
. , SendK eys.
. ()
<Alt>, <>.
. <F6>. ,
, () :
A p p l i c a t i o n . SendKeys "% h{F 6 } "

Sen dK eys,
:

(Insert): " %n{ F6} ";

(Page Layout): " %{ F6} ";

(Formulas): " %{ F 6 } ";

(Data): " % { F6}";

(Review): " %r { F6} ";

22.

(View): " %w{ F 6 } M;

(Developer): " %1 { F 6 }";

(Add-Ins): " % { F 6 } " .

695


VBA .
RibbonX .
XML-. VBA.
VBA,
.
RibbonX , , XML-, ,
. , ,
.
RibbonX .
, ,
Excel.


Excel 4.
x l s x .

R ib b o n X
Excel.
( Custom (
)), (Data).
Hello World ( ) Goodbye
World ( ).
VBA.

,
.
.

Excel 2010
. ,
. Excel ?
, ,
Excel . o f f i c e u i . . ,
:
: \Users\<HMir_noj7b30BaTej7.ff>\AppData\Local\Microsof t\Of f ice

E x c e l. o f f i c e u i 4.

VI.

696

SendKeys .
,
, UserForm, .

,
, RibbonX. 1^
Excel (File^Excel Options) Excel,
(Advanced)
(General).
(Show Add-in User Interface Errors).
RibbonX (
) .
, RibbonX, ,
.
1. Excel, VBA
.
,
.
Sub H e llo W o r ld ( c o n t r o l As IR ib b o n C o n tr o l)
MsgBox " "
End Sub
Sub G o o d b y e W o rId (c o n tro l As IR ib b o n C o n tr o l)
T h is W o rk b o o k . C lo se
End Sub

2. , r ib b o n m o d i f i c a t i o n . xlsm .
3. .
4. , r ib b o n m o d i f i c a t i o n .x l s m ,
cu stom U I.
5. , (, Windows
Notepad) custom U I .xm l,
XML- RibbonX.
<custom U I x m ln s = "h t t p : / / s c h e m a s . m ic r o s o f t . c o m / o f f ic e / 2 0 0 6 / 0 1 / _
c u s to m u i">
< rib b o n >
< ta b s >
< ta b id M s o = "T a b D a ta ">
< g ro u p id = " G r o u p l" l a b e l = " C u s to m ">
< b u tto n id = " B u t t o n l"
l a b e l = " "
s iz e = " n o r m a l"
o n A c tio n = " H e llo W o rld "
im ageM so="H appyFace" />
< b u tto n id = " B u tto n 2 "
**
l a b e l = " "
s iz e = " n o r m a l"
o n A c tio n = "G o o d b y e W o rId "
im a g e M s o = " D e c lin e ln v ita tio n " />

22.

697

</ g r o u p >
< /ta b >
< /ta b s >
< /r ib b o n >
< /c u s to m U I>

6. Windows . z i p r ib b o n
m odi f i c a t i o n . x lsm . r ib b o n m o d i f i
c a t i o n . x l s m . z ip .
7. cu stom U I, . 4, r ib b o n m o d i f i c a
t i o n , x ls m . z ip . Windows ZIP- ,
.
8. r ib b o n m o d i f i c a t i o n . x l s m . z i p
. . 22.4 ZIP-. ,
.

'! 1 (G:) ribbon modfficatton.xlsm.zip 1

| +*
.as -


>
> $
* jfiP
!>

()

!>

([>}

*)

_rets

customUI

i|| docProps

id

S i {Content_Tpes].xmi

XML

j. ribbon modificattonjdsmj:ip

_re*5
customUI
jjjg docProps

>

xl

>

. 22.4. Excel, ZIP-

9. _ r e l s , ZIP-.
. r e l s .
10.
).

. r e l s

ZIP- (,

11. . r e l s ( , XML-)
, .
12.

. r e l s

< /R e la tio n s h ip s > .

R e l a t i o n s h i p T y p e = "h t t p : //s c h e m a s . m ic r o s o f t . c o m /o f f ic e / 2 0 0 6 /
r e l a t i o n s h i p s / u i / e x t e n s i b i l i t y " T a rg e t= _

VI.

698
" /c u s to m U I/c u s to m U l.x m l"
I d = "1 2 3 4 5 " />

13. . r e l s ,
ZIP-, .
14. . z i p . :
r ib b o n m o d i f i c a t i o n .x l s m .
Excel. ,
(Hello World Goodbye World),
(Data), . 22.5.
'r

f*p

j
" j

Hello World
X Goodbye World

________ ____________ faj____ Custom____________________

. 22.5. RibbonX
,

-

- r ib b o n m o d if ic a t i o n , x ls m .
,
, RibbonX .
,
Excel.


RibbonX
.
,
, . ,
.

R ib b o n X
,
, .
Custom UI Editor Microsoft Office.
RibbonX, .
. ,
VBA,
VBA.
Custom UI Editor Microsoft
Office :
h t t p : //o p e n x m ld e v e lo p e r . o r g / a r t i c l e s / c u s t o m u i e d i t o r . a spx

Custom UI Editor (
) .

iaea 22.

699

1. Excel,
( XLSM).
2. .
3. Custom UI Editor Microsoft Office.

4. File^Open (^) ,
. 1.

5. Inserts Office 2007 Custom UI Part (^


Office 2007).

Excel 2007 Excel 2010.
6. RibbonX, . 22.6.
j* nbbontest.xlsm - C u stom UI Editor for M icrosoft Office
File

Edit

ki

IPs i B

Sample

m 2
ccustomUI
customUl.xml

x m l n s = " h t t p :/ / s c h e m a s . M i c r o s o f t . c o m / o f f i c e / 2 0 0 6 / 0 1 / c u s t o m u i ">

<ribbon>
<tabs>
<tab i d M s o = " T a b D a t a " >
<group
id= " G r o u p I l a b e l 51" C u s t o m ' ^
c b u t t o n id " B u t t o n l "
label="Hello World"
size*"normal"
onAction"HelloWorld"
i m a g e H s o = " H a p p y F a c e " />
cbutton id="Button2"
label="Goodbye World"
size="normal"
onAct ion="GoodbyeWorId"
i m a g e H s o = "Dec line I n v i t a t i o n " />
</group>
</tab>
</tabs>
</ribbon>
</customUI>

C:\Users\John\Desktop .ribborrtest.xisrn

Ln

21 C o ll

. 22.6. Custom UI Editor Microsoft Office

7. .

8. Generate Callbacks (
) .
Custom UI Editor VBA
(. . 22.7). ;
VBA .
9. c u sto m U I. xml.

10. File^Save (^), File^Close ( ^).


11. Excel .
12. <Alt+l 1> VB Editor.

VI.

700

13. VBA, , . 8.
14. MsgBox VBA,
.

,
_ n bbontest.*ism
Fite

Edit

l i i f a i a

-%

- Custom If! Editor fo r M icro so ft O ffice

...... .......a

Sample
U g ]

ribbontestxlsm

'Callback: f o r

j 1

Sub

Buttonl

H e l l o W o r Id ( c o n t r o l

onAction
As

IRibbonControl)

E n d Sub
' Callback for
Sub

Button2

onAction

GoodbyeorId(control

As

IRibbonControl)

E n d Sub

C;\Users\John\Desktop\ribbontest.xism

L n 2 i Col 1 ::

. 22.7. Custom Ul Editor


VBA

, Custom UI Editor ,
RibbonX .

CUSTOM UI
. 5 Office 2007 CustomUl
Part. Excel 2007 Excel 2010.
Insert Office 2010 Custom UI Part.
RibbonX Office 2010 Custom UI Part,
Excel 2007.
,
Excel 2010, Office 2007 Custom UI Part.
, ,
Office 2007 Office 2010. ,
RibbonX,
Excel. , RibbonX
Backstage, Excel 2010. Excel 2007
, ,
Office Excel 2007.
RibbonX,
Office 2010 Custom UI Part.
.
<customUI x m ln s = ' h ttp : / / s c h e m a s . m ic r o s o f t . c o m /o ffic e /2 0 0 9 /0 7 /c u e to m u i'>

, cu stom U I
Custom UI Editor .

22.

701

V B A

, VBA: H ello W o rld Good


bye World. o n A c tio n RibbonX.
o n A c tio n RibbonX VBA.
VBA c o n t r o l ,
I R i b b o n C o n t r o l . ,
VBA.

C o n t e x t . , ,
. ,
, RibbonX:
c o n t r o l . C o n t e x t . C a p tio n

I d . , Id.

Tag.

, .

VBA .
. r e l s

, RibbonX,
. XML-
. r e l s , _ r e l s .
, .
R e l a t i o n s h i p T y p e = "h t t p : / / s c h e m a s . m ic r o s o ft. c o m / o ffic e /2 0 0 6 /
r e l a t i o n s h i p s / u i / e x t e n s i b i l i t y " T a r g e t= " /c u s to m U I/c u s to m U I. x m l"
I d = "1 2 3 4 5 " />

T a r g e t c u s t o m U I . x m l,
RibbonX. I d , .
, ,
(.. ,
< R e l a t i o n s h i p > , I d ) .
R ib b o n X

XML-,
. ,
RibbonX.
, .
im a g eM so

Microsoft Office 2010 1000 ,


. ,
.
,
imageMso.
50 ( ),
, . mso image
b ro w s e r. x ls m -.

VI.

702

%
[~

fnP 0 & 0
3 0 % %


42 j#
2

12

13

14

15

16

17

18

22

23

24

25

26

27

28

34

35

36

37

38

45

46

47

48

32

33

43

44


S 0
1

10

11

19

20

21

29

30

31

39

40

41

49

50

51

[7
3DBeveiOptionsDialog
_3DBevelPictureTopGaI1
3DDirectionGalleryClassic
3DEffectColorPickerClassic
3DEffectColorPickerMoreClassic
3DEffectsGalleryClassic
3DEffectsOnOffClassic
_3DExtrusionDepthGalleryClassic
_3DxtrusionParaIlelClassic
.3DExtrusion PerspectiveClassi
3DLightingOimlassic
_3DLightingFiatClassic
_3DLightingGaIleryClassic
_3DLightingNormalClassic
.3DRotationGa Ilery
_3DRotationOptionsDialog
_3DSurfaceMateria(Classic
_3DSurfaceMaterialGalleryClassic
_3DSurfaceMatteClassic

50
,
. ,
, ,
.
,
, 32x32.
. <Ctrl+F>

,
.

1 . / W 7 ~ '

image
UserForm . imageMso
R eview A cceptC hanges P ic t u r e U serF orm Image
im a g e l. 32x32 .
Im a g e l. P ic t u r e = A p p l i c a t i o n . CommandBars. _
G etIm ageM so( "R e v ie w A c c e p tC h a n g e ", 32, 32)

, , , , imageMso
1000 ,
, .

imageMso .

R ib b o n X
RibbonX
. -

iaea 22.

703

(Page Layout),
, .

Excel 1700 ,
, .
,
Excel
(Excel Options). .

, , 1 . , -

, , ). , ,
) , .

R ib b o n X

RibbonX ( )

(Page Layout).
:ustom U I

x m ln s = "h t t p : / / s c h e m a s . m ic r o s o f t . c o m /o ffic e /2 0 0 6 /0 1 / c u s to m u i"


onLoad=" I n i t i a l i z e " >
ribbon >
tabs>
tab id M s o = "T a b P a g e L a y o u tE x c e l">
<group id = " G r o u p l" la b e l= " C u s to m " >
cch eckB o x id = " C h e c k b o x l"
la b e l= " P a g e B re a k s "
o n A c tio n = "T o g g le P a g e B re a k D is p la y "
g e tP re s s e d = "G e tP re s s e d "
g e tE n a b le d = " G e tE n a b le d "/ >
</g r o u p >

/tab>
/tabs>
/rib b o n >
/cu sto m U I>

RibbonX VBA,
:

In itia liz e

T o g g le P a g e B r e a k D is p la y

G e tP re s s e d

);
G e t E n a b le d

|=> '

Page Breaks


L4
( &

).
______________________________ |
Custom
. 22.8 - . 22.8.

'

704

VI.

< C u s to m U I> o n L o a d ,
VBA, .
P u b lic M yRibbon As IR ib b o n U I
Sub I n i t i a l i z e ( R i b b o n As IR ib b o n U I)
1

S e t M yRibbon = R ib b o n
End Sub

I n i t i a l i z e I R ib b o n U I , M y R ib
b o n . , M y R ib b o n ,
.
,
. , T h i s
W o rk b o o k (), C h e c k P a g e B r e a k D is p la y .
P r iv a t e Sub W o rk b o o k _ S h e e tA c tiv a te (B y V a l Sh As O b je c t)
C a ll C h e c k P a g e B re a k D is p la y
End Sub

C h e c k P a g e B r e a k D is p la y .
, , .
Sub C h e c k P a g e B re a k D is p la y ()
'

M y R ib b o n . In v a lid a te C o n tr o l
End Sub

( " C h e c k b o x l" )

G e tP r e s s e d G e tE n a b le d .
Sub G e tP r e s s e d ( c o n tr o l As IR ib b o n C o n tr o l,
'

ByR ef r e tu r n e d V a l)

On E r r o r Resume N e xt
r e tu r n e d V a l = A c t iv e s h e e t . D is p la y P a g e B re a k s
End Sub
Sub G e tE n a b le d ( c o n tr o l As IR ib b o n C o n tr o l, ByRef r e tu r n e d V a l)
'

r e tu r n e d V a l = T y p e N a m e (A c tiv e s h e e t) = "W o rk s h e e t"


End Sub

, r e t u r n e d V a l
(B y R e f). ,
. G e tP r e s s e d r e t u r n e d V a l
, D is p la y P a g e B r e a k s
. P r e s s e d
T r u e ( ). .
F a ls e , .
G e tE n a b le d r e t u r n e d V a l
T ru e , ( ).
, ,
.
**
VBA o n A c t io n
T o g g le P a g e B r e a k D is p la y , ,
.

22.

705

Sub T o g g le P a g e B r e a k D is p la y ( c o n tr o l As IR ib b o n C o n tr o l, _
p re s s e d As B o o le a n )
'

On E r r o r Resume N e xt
A c t iv e s h e e t . D is p la y P a g e B re a k s = p re s s e d
End Sub

P r e s s e d T ru e, ,
F a ls e .
D is p la y P a g e B r e a k s .
-


- ( page b re a k d is p la y .x ls m ).
, (page b re a k
d is p la y a d d - i n . xlam ),
. .

.
19, 29.



. 22.9 My Stuff,
. RibbonX,
VBA.

Hello Alex
Today is 27.10.2010
Number:

ribbon controls demo - Microsoft Excel

o*

Ills

i u y y ic

j
i
; M on th

4a Copy
I

W\ &

More Stuff

PUP v7

Paste

j stuff j

Pick a Month:

P Switch W ind ow *

Me
Stuff

Checkbox

Banjo
Players

Built In Stuff

Galleries

. 22.9.
-


- r ib b o n c o n t r o ls demo. xlsm .

RibbonX, .
<ribbon>
< tabs>
< ta b id = "C u sto m T a b " la b e l= " M y S t u f f ">
< /ta b s >
l< /rib b o n >

233ak. 3107

VI.

706


s ta r tF r o m S c r a tc h < rib b o n > .
T ru e , .
c r ib b o n s ta r t F r o m S c r a tc h = " tr u e "

>

r ib b o n c o n t r o l s demo .x ls m
My Stuff. , .
< g ro u p id = " G r o u p l"
</ g r o u p >
< g ro u p id = "G ro u p 2 "
< / g ro u p >
< g ro u p id = "G ro u p 3 "
< / g ro u p >
< g ro u p id = "G ro u p 4 "
< / g ro u p >

la b e l= " M y S t u f f ">
la b e l= " M o r e S t u f f ">
l a b e l = " B u i l t I n S t u f f ">
l a b e l = " G a l l e r i e s ">

(<g r o u p >, </ g r o u p >) < ta b > </tab>,


.

RibbonX,
(Stuff), . 22.10. ,
<g ro u p >.
<g ro u p id = " G r o u p l" la b e l= " M y S t u f f ">
c la b e lC o n t r o l id = " L a b e l l " g e t L a b e l= " g e t L a b e ll" />
c la b e lC o n t r o l id = " L a b e l2 " g e tL a b e l= " g e tL a b e l2 " />
< e d itB o x id = " E d it B o x l"
showLabe1 = " t r u e "
l a b e l = "N um ber: "
onChange=" E d itB o x l_ C h a n g e " / >
< b u tto n i d = " B u t t o n l "
l a b e l = " C a lc u la t o r "
s iz e = " la r g e "
o n A c tio n = " S h o w C a lc u la to r "
im a g e M s o = "C a lc u la to r" />
< / g ro u p >

L a b e l ()
VBA ( g e t L a b e l l g e t L a b e l 2 ).
.
Sub g e t L a b e ll ( c o n t r o l As IR ib b o n C o n tr o l, ByR ef r e tu r n e d V a l)
r e tu r n e d V a l = " H e llo " & A p p l i c a t i o n . UserName
End Sub
Sub g e t L a b e l2 ( c o n t r o l As IR ib b o n C o n tr o l, ByRef r e tu r n e d V a l)
r e tu r n e d V a l = "T o da y i s " & D ate
End Sub

RibbonX
, L a b e l
.
e d i t Box onChange
E d itB o x l_ C h a n g e ,

22.

707

( ,
). .
Sub E d itB o x l_ C h a n g e ( c o n tr o l As IR ib b o n C o n tr o l, t e x t As S t r in g )
Dim s q u a re R o o t As D o u b le
On E r r o r Resume N e x t
sq u a re R o o t = S q r ( t e x t )
I f E rr.N u m b e r = 0 Then
MsgBox "The s q u a re r o o t o f " & t e x t & " _
i s : " & s q u a re R o o t
E ls e
MsgBox " E n te r a p o s i t i v e n u m b e r.", v b C r i t i c a l
End I f
End Sub

S t u f f .
o n A c tio n VBA S h o w C a lc u la to r,

VBA S h e l l Windows.
Sub S h o w C a lc u la to r ( c o n t r o l As IR ib b o n C o n tr o l)
On E r r o r Resume N e x t
S h e ll " c a lc . e x e " , vb N o rm a lF o cus
I f E rr.N u m b e r <> 0 Then MsgBox " C a n 't s t a r t c a lc . e x e "
End Sub

. 22.11 ,
More S t u f f .
Alex

Today is 27.10.2010

Checkbox

M o n th ;

toggle
Me

N um ber
Stuff

M ore Stuff

. 22.10. ,

. 22.11.

RibbonX .
<group id = "G ro u p 2 " la b e l= " M o r e S t u f f ">
< to g g le B u tto n i d = " T o g g le B u tto n l"
s iz e = " la r g e "
im ageM so="F ileM anageM enu"
la b e l= " T o g g le Me"
o n A c t io n = " T o g g le B u tto n l_ C lic k " />
< s e p a r a to r id = " s e p l" />
<checkBox id = " C h e c k b o x l"
1 a be 1 = " C he ckbo x"
o n A c tio n = " C he ckb o xl_C h a n g e " / >
<comboBox id = "C o m b o l"
la b e l= " M o n th "
onChange=" C om bol_Change">
< ite m id = " M o n th l" la b e l= " J a n u a r y " />
< ite m id = "M o n th 2 " label="February"/>
< ite m id = "M o n th 3 " label="March"/>
< ite m id = "M o n th 4 " label="April"/ >
< ite m id = "M o n th 5 " label="May"/>
< ite m id = "M o n th 6 " label="June"/>
< ite m id = "M o n th 7 " label="July"/>
< ite m id = "M o n th 8 " 1abe1 = "Augus t "/ >
< ite m id = "M o n th 9 " la b e l= "September"/ >
< ite m id = " M o n th l0 " la b e l= " O c to b e r " />

VI.

708
< ite m id = " M o n t h ll" la b e l= "N o v e m b e r" / >
< ite m id = " M o n th l2 " la b e l= "D e c e m b e r" />
</comboBox>
</ g r o u p >

: t o g g le B u t t o n ,
, c h e c k B o x comboBox.
. (
),
, .
Sub T o g g le B u t t o n l_ C lic k ( c o n t r o l As IR ib b o n C o n tr o l, _
ByR ef r e tu r n e d V a l)
MsgBox "T o g g le v a lu e : " & r e tu r n e d V a l
End Sub
Sub C h e c k b o x l_ C h a n g e (c o n tro l As IR ib b o n C o n tr o l, _
p re s s e d As B o o le a n )
MsgBox "C heckbox v a lu e : " & p re s s e d
End Sub
Sub C o m b o l_ C h a n g e (c o n tro l As IR ib b o n C o n tr o l, t e x t As S t r in g )
MsgBox t e x t
End Sub

comboBox ,
. ,
, dropDown.

(. 22.12).

( idM so).
RibbonX .
< g ro u p id = "G ro u p 3 " l a b e l = " B u i l t I n S t u f f ">
c c o n t r o l idM so= "C op y" la b e l= " C o p y " />
< c o n t r o l id M s o = "P a s te " la b e l= " P a s te " e n a b le d = " tr u e "
c c o n t r o l id M s o = " W indow S w itchW indow sM enuE xcel"
la b e l= " S w itc h Window" />
c c o n t r o l i d M s o = " I t a l i c " />
c c o n t r o l id M s o = "B o ld " />
c c o n t r o l id M s o = "F ile O p e n " />
/ g ro u p >

/>

,
.
. 22.13 ,
.

I f t Paste

? Switch Window ~

Pick a Month:
Banjo
Players ^

Buitt In Stuff

Galleries

. 22.12.

. 22.13.

22.
RibbonX, .
g ro u p id = "G ro u p 4 " l a b e l = " G a l l e r i e s ">
< g a lle r y i d = " G a l l e r y l "
im a g e M s o = "V ie w A p p o in tm e n tIn C a le n d a r"
l a b e l= " P ic k a M o n th :"
c o lu m n s = " 2 " ro w s = " 6 "
o n A c tio n = "M o n th S e le c te d " >
c ite m id = " J a n u a r y " la b e l= " J a n u a r y " _
imageM so=" Q u e ry S e le c tQ u e ry T y p e " / >
< ite m id = " F e b r u a r y " la b e l= " F e b r u a r y " _
im a g e M s o = "Q u e ryS e le ctQ u e ryT yp e " / >
c ite m id = "M a rc h " la b e l= " M a r c h " _
imageM so=" Q u e ry S e le c tQ u e ry T y p e " / >
< ite m i d = " A p r i l " l a b e l = " A p r i l " _
imageM so=" Q u e ry S e le c tQ u e ry T y p e " / >
< ite m id = "M a y " la b e l= " M a y " _
im ageM so=" Q u e ry S e le c tQ u e ry T y p e " / >
c ite m id = " J u n e " l a b e l = "J u n e " _
im ageM so=" Q u e ry S e le c tQ u e ry T y p e " / >
c ite m id = " J u l y " l a b e l = " J u l y " _
imageM so=" Q u e ry S e le c tQ u e ry T y p e " / >
c ite m id = " A u g u s t" la b e l= " A u g u s t" _
imageM so=" Q u e ry S e le c tQ u e ry T y p e " / >
c ite m id = "S e p te m b e r" la b e l= " S e p te m b e r" _
imageM so=" Q u e ry S e le c tQ u e ry T y p e " / >
c ite m id = " O c to b e r " la b e l= " O c to b e r " _
imageM so=" Q u e ry S e le c tQ u e ry T y p e " / >
c ite m id = "N o v e m b e r" la b e l= "N o v e m b e r" _
im ageM so=" Q u e ry S e le c tQ u e ry T y p e " / >
c ite m id = "D e c e m b e r" la b e l= "D e c e m b e r" _
im ageM so=" Q u e ry S e le c tQ u e ry T y p e " / >
c b u tto n id = "T o d a y "
la b e l= " T o d a y . . . "
im a g e M s o = "V ie w A p p o in tm e n tIn C a le n d a r"
o n A c t io n = " ShowToday" / >
c /g a lle r y >
c g a l l e r y i d = " G a lle r y 2 "
la b e l= " B a n jo P la y e r s "
s iz e = " la r g e "
c o lu m n s = "4 "
ite m W id th = "1 0 0 " ite m H e ig h t= "1 2 5 "
imageMso= "Cam era"
o n A c tio n = " O n A c tio n " >
c ite m id = " b p 0 1 " im a g e = "b p 0 1 " />
c ite m id = " b p 0 2 " im a g e = "b p 0 2 " />
c ite m id = "b p 0 3 " im a g e = "b p 0 3 " />
c ite m id = "b p 0 4 " im a g e = "b p 0 4 " />
c ite m id = "b p 0 5 " im a g e = "b p 0 5 " />
c ite m id = "b p 0 6 " im a g e = "b p 0 6 " />
c ite m id = "b p 0 7 " im a g e = "b p 0 7 " />
c ite m id = "b p 0 8 " im a g e = "b p 0 8 " />
c ite m id = "b p 0 9 " im a g e = "b p 0 9 " />
c ite m i d = " b p l 0 " im a g e = " b p l 0 " />
c ite m i d = " b p l l " im a g e = " b p ll" />
c ite m i d = " b p l 2 " im a g e = " b p l 2 " />
c ite m id = " b p l3 " im a g e = "b p l3 " />
c ite m id = " b p l4 " im a g e = " b p l4 " />

709

VI.
< ite m id = " b p l5 "
< / g a lle r y >
< / g ro u p >

im a g e = "b p l5 " />

. 22.14 ,
. o n A c t io n M o n th S e l e c t e d , (
Id ) .
Sub M o n th S e le c te d ( c o n tr o l As IR ib b o n C o n tr o l, _
i d As S t r i n g , in d e x As In te g e r )
MsgBox "You s e le c te d " & i d
End Sub

PUP v7

My Stuff

|gyj Pick a Month:

eP January
March

O f May

February

April

June

m July
sP A ugust
sP September eP October
e P November
jJ|

e P December

Today...

. 22.14.

P ic k a M onth ,
( Today).
Sub S h o w T o d a y (c o n tro l As IR ib b o n C o n tr o l)
MsgBox "T o da y i s " & D ate
End Sub

, . 22.15, 15 .
, im a g e s,
custom U I.
r e l s , .
. z ip , .

DynamicMenu

DynamicMenu. , VBA XML-
. ,
.
Dynam icM enu ,
, VBA
.
, Dy
namicM enu. ,
. . 22.16 ,

711

22.

1. VBA XML-,
. XML-
, . XML-
.
a a 3

Microsoft Excel

PUP v7

My Stuff

tn {) 2

Pick a Month:

Banjo
Players Galleries

. 22.15.

RibbonX, , ,
DynamicMenu.
<customUI xm ln s= " h t t p : //s c h e m a s . m i c r o s o f t . / _
o f f i c e / 2 0 0 6 /0 1 /c u s to m u i"
o nLoad=" r ib b o n L o a d e d " >
< rib b o n >
< ta b s>
< ta b id = "C u sto m T a b " la b e l= " D y n a m ic ">
<g ro u p i d = " g ro u p 1" la b e l= "D y n a m ic Menu Demo">
<dynamicMenu id= "D yna m icM en u"
g e tC o n te n t= "d y n a m ic M e n u C o n te n t"
imageM so=" R e g io n L a yo u tM e n u "
s iz e = " la r g e "
la b e l= " S h e e t - S p e c if ic M en u"/>
< /g ro u p >

VI.

712
< /ta b >
< /ta b s >
< /r ib b o n >
</c u s to m U I>

* i

dynamKmenu - Microsoft Excel

07

<menu xmlns="http://schemas.microsoft.com/office/2006/01/customui"
"I..... ......
.
Quit for the day and go home

Click here tf you would like to knock off early


today. Tour boss will be alerted, and he wit
reply va email within JO minutes.

,
dynamicMenu .
Dynamic Menu Demo Dynamic.

button
!mageMso=AttachL_ .
label=Order office supplies...'
onActionxMacrol />
13 <button
id="b3"
imageM so=BlogHomel>age"
label=Quit for the day and go home"
screentip="Had enough?"
supertip="CIck here if you would like to knock oft early today. Your boss
will be alerted, and he will reply via email within 10 minutes."
onAction="Macrol" />

RibbonX
<cu3tOBtCI xmlns=http: //3chema3.micro3oft.com/office/2006/01/cu3tamui"
onLoaii=ribbonLoaded">
<ribbon>
<cabs>
<tab bS-CuatomXab label=Dynaaic>
<group id*=groupl" label"Dynamic Mena Demo">
<dynamicMenu id-" DynamicMenu"
getContentdynamicMenuContent"
imageM9o-*ReglonLayoutMemr
sire - "large*
label-"Sheet-Specific Menu"/>
</gnroup>
</tab>
</tabs>
</ribbon>
</cu3tamOI>

4-.
^. .v
iflu
innm wrnn i i h
. 22.16. DynamicMenu ,


. ,
(.
RibbonX), MyRibbon,
IR ib b o n U I. W o rk b ook_S heetA ct i v a t e ,
U pd ateD y n am icR ib b o n .
Sub U p d a te D y n a m ic R ib b o n ()
1 d ynam icM enuC ontent
On E r r o r Resume N e xt
M y R ib b o n .In v a lid a te
I f E rr.N u m b e r <> 0 Then
MsgBox " L o s t th e R ib b o n o b je c t . Save and r e lo a d . "
End I f
End Sub

U pdateD y n am icR ib b o n MyRibbon,


VBA d y n am icM enuC ontent (
g e t C o n te n t RibbonX).
. ,
VBA, MyRibbon,
.
, ,
. ,
MyRibbon .

22.

713

d y n a m ic M e n u C o n te n t.
, XML-,
XM Lcode. XML-
, r e t u r n e d V a l. D y n a m ic
Menu , .
Sub d y n a m ic M e n u C o n te n t(c o n tro l As IR ib b o n C o n tr o l, _
ByRef r e tu r n e d V a l)
Dim r As Long
Dim XMLcode As S t r i n g
'
XML-
F o r = 1 A p p lic a tio n .C o u n tA ( R a n g e ( " A :A " ))
XMLcode = XMLcode & A c t iv e S h e e t. C e l l s ( r , 1)
N ext r
r e tu r n e d V a l = XMLcode
End Sub

& 11 "

, , - d ynam icm enu. x lsm .


,
Excel.

, .
.

, RibbonX .


, Excel.
,
Excel.

,
RibbonX . ,
, RibbonX
.

Excel.
, .. .

.
.
RibbonX ( ).
ccu stom U I x m ln s = "h t t p : / / s c h e m a s . m ic r o s o f t . c o m /o ffic e /2 0 0 6 /0 1 /
c u s to m u i">
< rib b o n >
< ta b s>
< ta b id M s o = "T a b P a g e L a y o u tE x c e l" v i s i b l e = " f a l s e " />
< ta b id M so = "T a b D a ta " v i s i b l e = " f a l s e " />
< ta b idM so = "T a b R e vie w " v i s i b l e = " f a l s e " />

VI.

714
< /ta b s >
< /r ib b o n >
</c u s to m U I>

. RibbonX,
(Insert),
(Charts).
ccu sto m U I x m ln s = "h t t p : //s c h e m a s . m ic r o s o f t . c o m / o f f ic e / 2 0 0 6 / 0 1 /
c u s to m u i">
< rib b o n >
< ta b s>
< ta b id M s o = " T a b In s e r t">
<group id M s o = "G r o u p In s e r tT a b le s E x c e l" v i s i b l e = " f a l s e " />
<group id M s o = " G r o u p I n s e r t I llu s t r a t io n s " v i s i b l e = " f a l s e " />
<group id M s o = " G r o u p In s e r tL in k s " v i s i b l e = " f a l s e " />
<group id M s o = " G r o u p In s e r tT e x t" v i s i b l e = " f a l s e " />
< /ta b >
< /ta b s >
< /r ib b o n >
</c u s to m U I>

.
.
RibbonX, .
<custom U I x m ln s = "h t t p : //s c h e m a s . m ic r o s o f t . c o m / o f f ic e / 2 0 0 6 / 0 1 /
c u s to m u i">
<commands>
ccommand id M s o = "F ile S a v e " o n A c tio n = "m y S a v e "/>
<command id M s o = " F ile P r in t " o n A c t io n = " m y P r in t" />
<command id M s o = " F ile P r in t Q u ic k " o n A c tio n = " m y P r in t" />
< / commands>
</c u s to m U I>

RibbonX,
.
(Insert ClipArt).
<custom U I x m ln s = "h t t p : //s c h e m a s . m ic r o s o f t . c o m / o f f ic e / 2 0 0 6 / 0 1 /
c u s to m u i" >
<commands>
ccommand id M s o = " C lip A r t I n s e r t " e n a b le d = " f a ls e " / >
< / commands>
</c u s to m U I>

( ),
,
.
<CustomUI>, RibbonX.

, ,
CommandBar,
Excel.
, .
.

22.

715

,
.
. , Com
m andBar, .
C om m andBar ,
.

,
E x ce l 2 0 1 0
Excel 2010,
:


(Custom Toolbars) (Add-Ins)
;

CommandBar Excel.


, , ,
( M a c r o l 2 ). ,
.

,
, .

T h is W o r k b o o k () . , ,
. -, ,
.
P riv a te
C a ll
End Sub
P riv a te
C a ll
End Sub

Sub W orkbook_O pen()


C re a te T o o lb a r
Sub W o rk b o o k _ B e fo re C lo s e (C a n c e l As B o o le a n )
D e le te T o o lb a r

19 ,
w orkbook B e f o re C lo s e .
w orkbook B e f o re C lo s e Excel
... (Do you want to save...). (Cancel),
,
. 19 .

C r e a t e T o o lb a r .
Const TOOLBARNAME As S t r i n g = "M y T o o lb a r"
Sub C r e a te T o o lb a r ()

VI.

716
Dim TB ar As CommandBar
Dim B tn As Com m andBarButton
'


On E r r o r Resume N e x t
CommandBars(TOOLBARNAME).Delete
On E r r o r GoTo 0

'


S e t T B ar = CommandBars. Add
W ith T b a r
.Name = TOOLBARNAME
. V i s i b l e = T ru e
End W ith


S e t B tn = T B a r. C o n tr o ls .A d d ( T y p e : = m s o C o n tro lB u tto n )
W ith B tn
.F a c e ld = 300
.O n A c tio n = "M a c ro l"
.C a p tio n = " 1"
End W ith
1
S e t B tn = T B a r. C o n tr o ls .A d d ( T y p e : = m s o C o n tro lB u tto n )
W ith B tn
.F a c e ld = 25
.O n A c tio n = "M a cro 2 "
.C a p tio n = " 2"
End W ith
End Sub
-

, ,
- o l d - s t y l e t o o l b a r . x lsm .

. 22.17 , .

TOOLBAR, .
D e le t e T o o lb a r ,
fjftl| *0 ^ * ^ j * old-styletoolbar ...
,

Oof ] > Q
(^) 22
.


Q,
,
(
,..
).
- if e k
* [

1
,
1
,
2
3 w
.
4
Sheet1 tJ
13 [ UilJ
>

.......... a i . * > * Q * : ; - .....
A d d CommandBar.
. 22.17. - A d d C o n t r o ls .

A d o b e PDF

A l l

, (Custom
Toolbars) (Addjns)

22.

717

F a ce ID , ;

O n A ctio n , ;

C a p t io n ,
.

F aceiD ,
P ic tu r e , imageMso. ,
.
. P ic t u r e = A p p lic a tio n .C o m m a n d B a rs .G e tIm a g e M s o _
( " A c c e p t l n v i t a t i o n " , 16, 16)


imageMso imageMso .

Workb ook_B ef o r e C lo s e , D e le t e T o o lb a r .
Sub D e le t e T o o lb a r ()
On E r r o r Resume N e x t
CommandBars(TOOLBARNAME).Delete
On E r r o r GoTo 0
End Sub

...
CommandBar
VBA

Excel 2010 Com m andBar ,


Excel. Com m andBar
.

CommandBar
Com m andBar
Excel:

( ).
Excel 2010 CommandBar .
VBA ,
Excel , .
22, ,
CommandBar, (Menu Commands)
(Custom Toolbars),
(Add-Ins). Com m andBar Excel 2010
.
,
CommandBar.

VI.

720

CommandBar
Excel CommandBar,
. :

m soB arTypeN orm al ( = 0);

m soB arTypeM enuBar ( = 1);

m soBarTypePopU p ( = 2).
Excel 2010,
(
). Excel 2010
CommandBar, 0 1,
. Excel 2003
Standard ():
CommandBars( " S ta n d a r d " ) . V i s i b l e

= T ru e

Excel 2010 .
CommandBar,
2 ( ).


Excel 2010 65 .
? Show ShortcutM enuN am es (
), CommandBar.
m soBarTypePopU p ( ,
2), CommandBar.
Sub S how S hortcutM enuN am es()
Dim Row As Long
Dim c b a r As CommandBar
Row = 1
F o r Each c b a r I n CommandBars
I f c b a r.T y p e = msoBarTypePopUp Then
C e lls (R o w , 1) = c b a r .In d e x
C e lls (R o w , 2) = cbar.N am e
Row = Row + 1
End I f
N ext cb a r
End Sub

. 23.1 ,
. 21 148.
, . , CommandBar
36 38 (Name of Cell). ,
,
(Page Break Preview).
-

- show
s h o r t c u t menu n am es.xlsm .

23.

721

CommandBar
Command
B a r ( In d e x )
( Name). ,

* ]v

show shortcut men...

B il

A do b e PDF -

,

Excel (,
).

A80

A p p l i c a t i o n . CommandBars (44)
A p p lic a tio n .C o m m a n d B a rs ( " D e s k to p " )

Com m andBars
A p p l i c a t i o n .
VBA
,
A p p l i c a t i o n . ,
( VBA)
C om m andB ars,
44.

A 1
21
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51

AutoFill
Button
Dialog
Series
Plot Area
Floor and Walls

10
11
12
13
14
15
16
17
18

1 i a t i on.

19
20
2!
22

MsgBox A p p lic a tio n .C o m m a n d B a rs (44) .Name


- -

Com
m andB ars T h i s
W o rkbo ok ()

1
2
3
4

MsgBox CommandBars( 4 4 ) .Name

. . i t .

-------PivotChart Menu
Workbook tabs
Cell
Column
Row
Cell
Column
Row
Ply
XLM Cell
Document
Desktop
Nondefault Drag and Drop

5
6

, i n
dex

23
24

Excel. , Ex
cel 2007 in d e x
CommandBar, 36 39,
Name o f C e ll
( ). Excel 2010

Name o f Column (
).
, .

25
26
27
28

'

"< w

62 Object/Plot
? 1

lljttH jlk lta *

=5

52 Trendline
53 Chart
54 Format Data Series
55 Format Axis
56 Format Legend Entry
57 Formula Bar
58 PivotTable Context Menu
59 Query
60 Query Layout
61 AutoCalculate

29
30

S 22
) S3

I----|.........

T
n

III,, j

|<

Avvsv

. 23.1.


CommandBar
C om m andBar C o n t r o l ,
. 1
C a p tio n . ,
C e l l .

722

VI.

Sub S h o w C a p tio n ()
MsgBox A p p lic a tio n .C o m m a n d B a rs ( " C e l l " ) .
C o n t r o l s ( 1 ) .C a p tio n
End Sub

C a p tio n
,
( Ply).
Sub S h o w C a p tio n s ()
Dim t x t As S t r i n g
Dim c t l As C om m andBarControl
F o r Each c t l I n CommandBars( " P l y " ) . C o n tr o ls
t x t = t x t & c t l . C a p t i o n Sc vbN ew Line
N ext c t l
MsgBox t x t
End Sub


, . 23.2.
.
.
C o n tr o l
C o n tr o l. , F i l t e r
(), ,
. F i l t e r
, .

. 23.2.
F
i
l
t e r ():
Caption

jsJ

&..,

/...
&
^ ,.,

&
&...

MsgBox CommandBars( " C e l l " ) . C o n t r o l s ( " F i l t e r " ) .


C o n t r o l s ( 1 ) .C a p tio n

Excel,
C a p tio n
. C a p tio n ,
, Excel, .
F in d C o n tro l (id )
( ). ,
(Rename) ,
.
Excel, :
CommandBars( " P l y " ) . C o n t r o l s ( "R enam e") . E n a b le d = F a ls e


Excel, .
, ( id ) 889:
MsgBox CommandBars( " P l y " ) . C o n t r o l s ( "R enam e") .ID

:
CommandBars. F in d C o n t r o l( I D := 8 8 9 ) .E n a b le d = F a ls e

CommandBar Excel,
, CommandBars ( " D e s k to p " ) .

23.

723

C o m m a n d B a r
CommandBar ,
.
CommandBar.

C a p tio n . .
, C a p tio n
.

ID. .

F a ce ID. , ,
.

. , (m soC o n tr o lB u tto n ) (m soC ontrolP opu p ).

P i c t u r e . , ,
.

B egin G roup . True,


.

O n A ction . VBA,
.

B ui I t In. T rue,
Excel.
E n a b led . T rue,
.
V i s i b l e . True,
. .
T o o lT ip T e x t. ,
. ( .)


S h o w S h o rtcu tM en u Item s, ,
, ,
.
In d e x , Name, ID, C a p tio n , Type, E n a b le d V i s i b l e .
Sub S h o w S h o rtcu tM e n u Ite m s()
Dim Row As Long
Dim Cbar As CommandBar
Dim c t l As C om m andBarC ontrol
R ange("A 1:G 1") = A r r a y ( " I n d e x " # "Name",
|
"T y p e ", "E n a b le d " , " V i s i b l e " )

"ID ",

" C a p tio n " ,

Row = 2

A p p lic a t io n . S c re e n U p d a tin g = F a ls e
For Each C bar I n A p p l i c a t i o n . CommandBars
I f C b a r.T yp e = 2 Then
F or Each c t l I n C b a r. C o n tr o ls
C e lls (R o w , 1) = C b a r.In d e x

**

724

VI.

C e lls (R o w , 2)
C e lls (R o w , 3)
C e lls (R o w , 4)
I f c t l. T y p e =
C e lls (R o w ,
E ls e
C e lls (R o w ,
End I f
C e lls (R o w , 6 )
C e lls (R o w , 7)
Row = Row + 1
N ext c t l
End I f
N e xt Cbar
End Sub

=
=
=
1
5)
5)

C b a r. Name
c tl.ID
c tl.C a p tio n
Then
= " "
""

= c t l. E n a b le d
= c tl.V is ib le

. 23.3 .

18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33

34
35
36
37
38
39

40
41

42
43
44

45
M

V\ Workbook tdbs
34 Workbook tabs
34 Workbook tabs
34 Workbook tabs
34 Workbook tabs
34 Workbook tabs
34 Workbook tabs
34 Workbook tabs
35 Cell
35 Cell
35|celi
35 Cell
35 Cell
35 Cell
35 Cell
35 Cell
35 Cell
35 Cell
35 Cell
35 Cell
35 Cel!
35 Cell
35Cell
35 Cell
35 Cell
35 Cell
35iceii
35; Ceil
35 celt
35 Cell

17

16

957 &
957 &
957 &
957 &
_______j_______ 957 &
957 &
957 &
957 &
....... & ...
19 &
22 &
21437 & ...
3624 &
3181 &...
292 &...
3125 &
1_____ 31623 & ________________
31402 &
31435 &8___
2031 &
1592 &
1593 &
855 &...
1614 &
13380 & ...
1576 &...
1577 & ...
1015 &
3626 &

'

F '

.................*,*.................................... n

. 23.3.

S h o w S h o rtc u tM e n u Ite rn s ,

. ,
. , (Desktop) 44
:

&... (&New...);
&... (&...);
& ... (Save &Workspace...);
& (&Calculate Now);
& (F&ull Screen).

23.

725

& (Full Screen) ,


Excel . ,
, &
(&Close Full Screen).
-


- s h o w s h o r t c u t m e n u i t e m s , x l s m .
E x c e l 2 0 0 3

B u i l t - i n M e n u s .
Excel 2003 ( Excel,
). - ,
VBA:
A p p l i c a t i o n . C o m m a n d B a r s ( " B u i l t - i n

M e n u s " ) . S h o w P o p u p

- ( m a k e x l 2 0 0 3
m e n u s . x l s m ) , ,
.
(Add-Ins).
Excel 2003 Excel 2010.
.

VI.

726

VBA
VBA,
Excel. ,
VBA,
.


R e s e t .
.
Sub R e s e tC e llM e n u ()
CommandBars( " C e l l " ) .R e s e t
End Sub

, Excel .
( 35).

(38) .
Excel, ,
.
Sub R e s e tC e llM e n u ()
Dim c b a r As CommandBar
F o r Each c b a r I n A p p l i c a t i o n . CommandBars
I f cbar.N am e = " C e ll " Then c b a r .E n a b le d = F a ls e
N ext cb a r
End Sub


.
Sub R e s e tA llO
Dim c b a r As CommandBar
F o r Each c b a r I n A p p l i c a t i o n . CommandBars
I f c b a r.T y p e = m soBarTypePopup Then
c b a r . R ese t
c b a r .E n a b le d = T ru e
End I f
N e xt c b a r
End Sub

,
.
, ,
.


E n a b le d , .
F a ls e ,
.
:
A p p l i c a t i o n . CommandBars( " C e l l " ) . E n a b le d = F a ls e

23.

727

E n a b le d
True.

, .
Sub D is a b le A llS h o r tc u tM e n u s ()
Dim cb As CommandBar
F o r Each cb I n CommandBars
I f c b .T y p e = msoBarTypePopup Then _
c b .E n a b le d = F a ls e
N e xt cb
End Sub


. Excel
. ,
E n a b le d T ru e .



. ,
- .
(Hide)
(Row) (Column).
Sub D is a b le H id e M e n u Ite m s ()
CommandBars( "C o lu m n ") . C o n t r o l s ( " " ) . E n a b le d = F a ls e
CommandBars( "R o w ") . C o n t r o ls ( " " ) . E n a b le d = F a ls e
End Sub



A d d T o S h o rtc u t, ,
. (Toggle Word
Wrap). , Excel .
,
,
(Page Break Preview).
Sub A d d T o S h o rtC u t()
1
Dim B a r As CommandBar
Dim N e w C o n tro l As Com m andBarButton
D e le te F ro m S h o rtc u t
Set B a r = CommandBars( " C e l l ")
Set N e w C o n tro l = B a r . C o n tr o ls .A d d _
(T y p e : = m s o C o n tro lB u tto n / _
te m p o r a r y : = T ru e )
W ith N e w C o n tro l
.C a p tio n = " "
.O n A c tio n = "T oggleW ordW rap"
. P ic t u r e = A p p l i c a t i o n . CommandBars. GetImageMso _
("W ra p T e x t", 16, 16)

VI.

728
.S t y le
End W ith
End Sub

= m s o B u tto n lc o n A n d C a p tio n

. 23.4 ,
. ,
, D e le te F r o m S h o r tc u t (
).
(Toggle Word Wrap).

f| tl

_ I ,

2
3

'

<*-,0 ,00
,00 *,0 >#

h i 1 IoppteWnrd\Atrap
hap

4
5

6
7

JL
8
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27

/
. | _
/ U1
0Q0

trap

trap
trap

trap

...

trap
...

tap

...

trap

trap

rap

...

...
...
.

=-

...
Toggle W ord W rap

..........

. 23.4. ,

P i c t u r e
, ( (Toggle Word Wrap)).
,
, 22.
, ,
O nA ction. T o g g le w ordw rap.
Sub T oggleW ordW rap()
CommandBars. ExecuteM so
End Sub

( "W ra p T e x t")

(WrapText).

23.

729

,
, Excel. ,

VBA. , ,
, ,
.

D e le t e F r o m S h o r t c u t
.
Sub D e le te F r o m S h o r tc u t()
On E r r o r Resume N e x t
CommandBars( " C e l l " ) . C o n tr o ls _
("& ") . D e le te
End Sub

,
.
.
T h is W o r k b o o k ().
P riv a te
C a ll
End Sub
P riv a te
C a ll
End Sub

Sub W orkbook_O pen()


A d d T o S h o rtC u t
Sub W o rk b o o k _ B e fo re C lo s e (C a n c e l As B o o le a n )
D e le te F ro m S h o rtc u t

W o rk b o o k _ O p e n ,
W o rk b o o k _ B e f o r e C lo s e . , .

, ,
, , .
-


- add t o c e l l s h o r t c u t .x ls m .


, ,
. , . . 23.5
.
,
.
, .
Sub AddSubmenu ()
1
Dim B a r As CommandBar
Dim NewMenu As C om m andBarControl
Dim NewSubmenu As Comm andBarButton
De 1e t e Submenu

VI.

730
S e t B a r = CommandBars( " C e ll " )
'

S e t NewMenu = B a r . C o n tr o ls .A d d _
(T y p e : = m so C o n tro lP o p u p , _
te m p o r a r y : = T ru e )
NewMenu. C a p tio n = " & "
NewMenu. B e g in G ro u p = T ru e
'

S e t NewSubmenu = NewMenu. C o n tr o ls .A d d
(T y p e : = m s o C o n tro lB u tto n )
W ith NewSubmenu
.F a c e ld = 38
.C a p tio n = "^ "
.O n A c tio n = "M akeUpperCase"
End W ith

S e t NewSubmenu = NewMenu. C o n tr o ls .A d d
(T y p e : = m s o C o n tro lB u tto n )
W ith NewSubmenu
.F a c e ld = 40
.C a p tio n = " "
.O n A c tio n = "M akeLowerCase"
End W ith
1

S e t NewSubmenu = NewMenu. C o n tr o ls .A d d
(T y p e : = m s o C o n tro lB u tto n )
W ith NewSubmenu
.F a c e ld = 476
.C a p tio n = " ^ "
.O n A c tio n = "M akeP roperC ase"
End W ith
End Sub

. 23.5.

23.

731

, msoContr o lP o p u p .
OnAct io n .
, , .
Sub D e le te S u b m e n u ()
On E r r o r Resume N e xt
CommandBars( " C e l l " ) . C o n t r o l s ( "& " ) .D e le te
End Sub

-

- s h o r t c u t w it h subm enu. xlsm .

, F a c e iD
, ,
.

P ic t u r e . imageMso,
.
.

F a ce iD , F ace iD

, .
,
, FaceiD ? Excel
, ,
FaceiD . ,
.
, F aceiD .
, F aceiD , 1 500.
- show f a c e id s . x ls m .

2
3
4

**- :

[ . : 1500

1 2 3
B C D E F 6 H

10
11
12
13
14
15
,1

I J K

'

5
6
7
8

8 9

L M N O P Q R S T U

.............................................................-........................................... .............................. 1<1.............................................. ..........

................. 1


, ,
, .

19.

732

VI.


,
, W orkbook_Open. ,
T hisW orkbook ()
Modi f y S h o r t c u t ( ).
P r iv a t e Sub W orkbook_O pen()
C a ll M o d ify S h o r tc u t
End Sub

( )
.
R e s t o r e S h o r t c u t (
).
P r iv a t e Sub W o rk b o o k _ B e fo re C lo s e (C a n c e l As B o o le a n )
C a ll R e s to r e S h o r tc u t
End Sub

,
. Excel ? (Do you
want to save the changes?) Workbo ok_B ef o r e C lo s e . (Cancel),
, !
,
Excel, ( W o rk b o o k _ B e fo re clo se),
. .
P r iv a t e Sub W o rk b o o k _ B e fo re C lo s e (C a n c e l As B o o le a n )
I f N ot M e.Saved Then
Msg = " "
Msg = Msg & Me.Name & "? "
Ans = M sgBox(M sg/ v b Q u e s tio n + vb Y esN o C an cel)
S e le c t Case Ans
Case vbYes
Me. Save
Case vbNo
Me. Saved = T ru e
Case vb C a n ce l
C a n ce l = T ru e
E x i t Sub
End S e le c t
End I f
C a ll R e s to r e S h o r tc u t
End Sub

, .
, . R e s t o r e S h o r t c u t ,
. ,
, , Excel.
(Yes), ,
. (No), S av ed
W orkbook T ru e ( ),
. (Cancel), B ef o r e C lo s e
, .

733

23.



, -
, - .
, .
VBA, .
, .
.
,
(Change Case).
2. 2.
P riv a te Sub W o r k s h e e t_ A c tiv a te ()
CommandBars( " C e l l " ) . C o n t r o ls ( _
" " ) . E n a b le d = F a ls e
End Sub

2
.
(Change Case) , 2.
P riv a te Sub W o r k s h e e t_ D e a c tiv a te ()
CommandBars( " C e l l " ) . C o n t r o l s ( _
" " ) . E n a b le d = T ru e
End Sub

, V i s i b l e

E n ab led ).


,
.
M y S h o rtc u t, .
O n A c tio n , ,
,
(Format Cells), . 23.6.
Sub C r e a t e S h o r t c u t()
Set myBar = CommandBars.Add _
(Name: = " M y S h o r tc u t" , P o s i t i o n : =msoBarPopup, _
T e m p o ra ry : = T ru e )
'

Set m ylte m = m yB a r. C o n tr o ls .A d d ( T y p e : = m s o C o n tro lB u tto n )


W ith m ylte m
.C a p tio n = "& .. ."
.O n A c tio n = "Show Form atN um ber"
.F a c e ld = 1554
End W ith
'

Set m ylte m = m yB a r. C o n tr o ls .A d d ( T y p e : = m s o C o n tro lB u tto n )


W ith m ylte m
.C a p tio n = " . . . "

VI.

734
.O n A c tio n = "S h o w F o rm a tA lig n m e n t"
.F a c e ld = 217
End W ith
1

S e t m ylte m = m yB a r. C o n tr o ls .A d d ( T y p e : = m s o C o n tro lB u tto n )


W ith m ylte m
.C a p tio n = " . . . "
.O n A c tio n = "S h o w F o rm a tF o n t"
.F a c e ld = 291
End W ith
'

S e t m ylte m = m yB a r. C o n tr o ls .A d d ( T y p e : = m s o C o n tro lB u tto n )


W ith m ylte m
.C a p tio n = " ^ .. . "
.O n A c tio n = "S h o w F o rm a tB o rd e r"
.F a c e ld = 149
. B e g in G ro u p = T ru e
End W ith
'

S e t m ylte m = m yB a r. C o n tr o ls .A d d ( T y p e : = m s o C o n tro lB u tto n )


W ith m yltem
.C a p tio n = " & .. . "
.O n A c tio n = "S h o w F o rm a tP a tte rn s "
.F a c e ld = 1550
End W ith
1

S e t m ylte m = m yB a r. C o n tr o ls .A d d ( T y p e : = m s o C o n tro lB u tto n )


W ith m ylte m
.C a p tio n = "& 3 . . . "
.O n A c tio n = "S h o w F o rm a tP ro te c tio n "
.F a c e ld = 2654
End W ith
End Sub
F

1
!
J
1

<3
........ <L . g
... 1
1 ( Data)

,4

i
1
? i.

2 Ctri+Shift+M /i.
1----------- 1
)

!
4

*.1

---- -

...
...

;----------

1------------

7
8
9

...

Jy

..

10

-------

11

;..... .

12

.....

13
14
15
16
17
18
19
20
21

.................. j..................
............

[..... ......

. 23.6.

23.

735


Show P opup. ,
W o rk s h e e t ( ), .
P r iv a te Sub W o r k s h e e t_ B e fo r e R ig h tC lic k _
(B yV al T a r g e t As E x c e l.R a n g e , C an cel As B o o le a n )
I f U n io n ( T a r g e t. R an ge ( " A l " ) , R ange( " d a t a " ) ) .A d d re s s = _
R ange( " d a t a " ) .A d d re s s Then
CommandBars( " M y S h o r tc u t" ) . ShowPopup
C a n ce l = T ru e
End I f
End Sub

d a t a
, M y S h o r tc u t . C a n c e l
T r u e , .
: - .
.
,
, (Macro).
Sub S h ow M yS h ortcu tM en u ()
< C tr l+ S h ift+ M >
CommandBars( " M y S h o r tc u t" ) . ShowPopup
End Sub
-

- ( c o n t e x t - s e n s i
s h o r t c u t m enu.xlsm ),
, .
tiv e


...

Excel
, Excel

HTML Help

Excel.

Excel
Excel ,

. , ,
.
(
).

, . ,
, , ,

.
.
,
.
/ , .
>4. 3107

VI.

738

. ,
Excel (, U serForm ).

.
CHM-, Microsoft HTML Help Workshop.


,
. ,
, .
, ,
.
,
(.. ). Excel 2003
. Excel 2003
.
(
) - Microsoft.
.
,
.

Microsoft Office 2007 Microsoft


Office.
( )
MS Help 2. .
-

, ,
-.
, -.
,

,
.
, ,
.
,
( 2; ),
( ), ( 4),
( 5).
.
4 5 .
, .

.

24.

11 1
2 1

AJ
4
5 j



1-

739

_ |

6
1
1

Elephants 4U
/ 1211
-, 92111

23 , 2010

101 .
,
32837
,
, .
, ,
, .
, , .
,
.
,

Form () . , .

Data

( ) . , .

( ) . ,
.

H elp

P rin tM o d . VBA, .

HelpMod. VBA, ,

.
.
U serF orm l. ,

,
U serForm .

VI.

740

,
Excel
,
, Excel.
HTML Help.

.
,
Excel .

. !

T extB ox ( ). ,
, .

.
,
.
. ,
.

.
U serForm .




.
,
. ,
, ,
(. 24.1).
, .
, .
VBA :
A p p l i c a t i o n . D is p la y C o m m e n tln d ic a to r = x lC o m m e n tln d ic a to rO n ly
-

, ,
- c e l l c o m m e n ts \fo r m le tte r .xlsm .

,
.
,
(Format Comment). (Format
Comment) (Colors and Lines).
(Color),

741

24.

(Fill Effects). (Fill Effects)


(Picture) (Select
Picture) .

. jl 1



.

Data.



>/ |

elephants 4U
/ 1211
-, 92111

18


101 .
,
32837

19]
20

21
22;

23
24
25
26
27
28
29
30
31
32
33:
34
35

, .
, ,
, .
, , .
,
.
,

f'CbVW&b'
.

. 24.1.

Excel 1^ ^
(Data^Data Tools^Data Validation),
, , .
,
(Input Message)
(Data Validation) ,
. 250 .

742

VI.



T extB ox

. ^>=> (Insert^Text^Text Box),
.

,
. ^
^ (Insert^lllustrations^Shapes), .
.

. 24.2 ,
. .

:

:
:

3
1
1


:
Elephants4U.
:
C4, - C5.
4 C5
.
:
.
.
/ :
/ .
Data, .
: ,
, , .
,

.
( )

. 24.2.
*

, , ,
. ,
, V i s i b l e .

24.

743

. T e x tB o x
H e lp T e x t.
Sub T o g g le H e lp ()
A c t iv e S h e e t. T e x tB o x e s ( " H e lp T e x t" ) . V i s i b l e = _
N ot A c tiv e S h e e t.T e x tB o x e s ( " H e lp T e x t " ) . V i s i b l e
End Sub
-

,
, -
te x tb o x \fo r m le tte r .x ls m .




, ,
. ,
... .
. 24.3 , .
, .
, .

Sc 11 A re .
,
. ,
. ,
Return () , ,
.
,
, ,
( ).
, ,
.
-

- ( w o r k s h e e t\f orm
l e t t e r .x ls m ),
.

744

VI.


Elephants 4U.

4, <
- 5.
4 5.


.
.


:
/ .
Data, / .

: ,
, , .
.


. 24.3.

L a b e l

. 24.4 U s e rF o rm ,
L a b e l: ,
. S p i n B u t t o n
.
.
, .
S p i n B u t t o n
. C a p t io n
L a b e l ,
H e lp S h e e t ().
P r i v a t e Sub S p in B u tt o n l_ C h a n g e ()
H e lp T o p ic = S p in B u t t o n l. V a lu e
^
L a b e lT o p i c . C a p tio n = S h e e t s ( " H e lp S h e e t" ) . _
C e ll s ( H e l p T o p ic , 1)
L a b e lT e x t . C a p tio n = S h e e t s ( " H e lp S h e e t" ) . C e ll s ( H e l p T o p ic , 2)
M e .C a p tio n = APPNAME & " (H e lp T o p ic " & H e lp T o p ic & " o f " _

24.

745

& S p in B u t t o n l. & " ) "


End Sub
E le p h a n ts 4U ( 3 5)

*1
. 24.4.
S p in B u tto n

APPNAME ,
.
-


- u s e r f o r m l \ f o r m l e t t e r . xlsm .

u se rF o rm C o n tr o lT ip T e x t,
.
,
( ). .

L a b e l


L a b e l. ,
L a b e l ,
Frame,
. . 24.5 U serForm ,
.
Frame.

VI.

746

*]


Elephants 4U.


4 <

3
. 24.5.
Label Frame

, L a b e l,
H e lp S h e e t ().
U serForm . U s e r F o r m _ I n it i a l i z e .
P r iv a t e Sub U s e r F o r m _ I n i t i a li z e ()
Dim LastR ow As Long
Dim r As Long
Dim t x t As S t r in g
M e .C a p tio n = APPNAME Sc " H e lp "
LastR ow = S h e e ts ( " H e lp S h e e t" ) . C e lls _
(R o w s.C ou nt, 1 ) . E n d ( x lU p ) . Row
t x t = ""
F o r r = 1 To LastR ow
t x t = t x t Sc S h e e ts ( "H e lp S h e e t" ) . C e l l s ( r ,
.T e x t & v b C rL f
N e xt r
W ith L a b e ll
.Top = 0
.C a p tio n = t x t
.W id th = 260
.A u to S iz e = T ru e
End W ith
W ith F ra m el
. S c r o llH e ig h t = L a b e l l . H e ig h t
.S c r o llT o p = 0
End W ith
End Sub

1) _

, S c r o l l H e i g h t
Frame ,
L a b e l. , APPNAME ,
.
L a b e l ,

H e lp S h e e t ().

24.

747

, ,
- u s e r fo r m 2 \ f o r m l e t t e r .x ls m .

, , .
. 24.6 U s e rF o rm ,
Com boBox L a b e l.
, ComboBox,
.
Elep ha n ts 4U (2 6)

j
!
| 4, 5 -
| .

4 5.

j >~

. 24.6.

, ,
. Label Frame
( ),
.
, H e lp Sheet (). : .
, .
Com boBox U s e rF o rm _
I n i t i a l i z e . C u r r e n t T o p ic
, .
P riv a te Sub U pdateF orm O
C om boBoxTopics. L is t ln d e x = C u r r e n tT o p ic - 1
M e .C a p tio n = H e lp F o rm C a p tio n & _
" (" Sc C u r r e n tT o p ic & " o f " & T o p ic C o u n t & " ) "
W ith L a b e lT e x t
.C a p tio n = H e lp S h e e t. C e lls ( C u r r e n t T o p ic , 2)
.A u to S iz e = F a ls e
.W id th = 212
.A u to S iz e = T ru e
End W ith
W ith F ra m el
. S c r o llH e ig h t = L a b e lT e x t. H e ig h t + 5
.S c r o llT o p = 1
End W ith

VI.

748
If

C u r r e n tT o p ic = 1 Then
N e x tB u tto n . S e tF o cus
E l s e l f C u r r e n tT o p ic = T o p ic C o u n t Then
P r e v io u s B u t to n . S e tF o cus
End I f
P r e v io u s B u t to n . E n a b le d = C u r r e n tT o p ic <> 1
N e x tB u tto n . E n a b le d = C u r r e n tT o p ic <> T o p ic C o u n t
End Sub
-

, ,
- u s e r f o r m 3 \ f o r m le t t e r .x ls m .

H T M L -
, Excel,
HTML-,
, , .
HTML .
( ). . 24.7
.
1f

) - Mozilla Firefox

>

fie:///:/Compact/Chapter %2024/ftus/web %20br owser . h tm

".

-!>*j

j* ] g jj

(9) *

J*-

[ j C lj j Google

JyP Web Security Guard *


, .
I .

_________________________I___________________________________

. 24.7.
-

, ,
- web b r o w s e r \ f o r m l e t t e r . xlsm .

m h tm l

MHTML MIME Hypertext Markup Language


, . MHTML
Microsoft Internet Explorer.

24.

749

, MHTML Excel.
,
. ^ (File^Save As),
(Save As )
(Single File Web Page (*.mht; *.mhtml)). ,
VBA.
. 24.8 MHTML-, Internet Explorer.
m html:file://f:V nhtm l file\help.m ht
1

I X

[F3]

^1
^

\Q' *

||1 -

E:\mhtml_Ne\help.mht

(16) X

Web Security Guard

*1 Google

* ^ *

**

P -

0 nnhtml:file://E:\mhtml_file\help.mht

* *

* ^

Elephants 4U
Form Letter

Elephants 4U.

( . )
* ;

| Main [ What Print | Printing j Editing Data 1 Viewing A Record- }


100% *

. 24.8. MHTML- -

Internet Explorer MHTML-,


Excel, .

Excel MHTML-.
-

, ,
- :1 f i l e \ f o r m l e t t e r . x l s m .

Excel
MHTML-, Javascript.
.

VI.

750

HTML Help
Windows
HTML Help,
.
WinHelp HLP (.
Microsoft).
.
- .

HTML Help. .
.

,
,
. ,
.
,
.
M ic r o s o f t '

Microsoft
.

WinHelp. RTF (Rich Text Formatting

). Windows 3.0
( 1990 ). RTF-
.h ip . Microsoft
Office, Office 2000.

HTM L Help. HTML- (HyperText Markup Language

). Internet
Explorer 4.0 ( 1997 ). HTML-
. chm. Office,
, Office 2000.

M icrosoft Help 2. HTML, DHTML, XML, VBScript JavaScript.


.h s x .
Office 2007,
.

A ssista n ce Platform Help. Windows Vista

Windows 7.

HTML Help HTML-


.
,
. HTML Help
, , ActiveX,
DHTML (Dynamic HTML HTML). . 24.9
HTML Help.

24.

.. :

< ; ; - *>

1Ijjifen M M iM

[3 Specifying What to Print


0 Printing Form Letters
[jyViewing or Editing Data

?
&
&

751
.ini xi

W e lc o m e to th e F o rm L e tte r
A p p lic a tio n

Viewing a Specific Recor ^ This application makes it easy to

3 About

[s] About this Application

<1

print form letters for Elephants 4U.

1 4

1.......................................

Ill

zl

. 24.9. HTML Help


E x c e l H e lp

Excel Help VBA. ,


Excel.
, Excel
, - Office.com. ( ,
,
.) T o p ic i d
. ,
(Properties). (URL) (Address (URL)) T o p ic id , URL-
( 10 , ).
T o p ic id , VBA:
A p p lic a t io n . A s s is t a n c e . ShowHelp " 10342187"

Excel 2007 ,
(..
). Excel 2010 .
S e a rc h H e lp .
,
. .
A p p lic a t io n . A s s is t a n c e . S e a rc h H e lp " "
-

, ,
- h tm l h e l p \ f o r m l e t t e r . xlsm .

H TM L Help HTM L Help


Viewer, Internet Explorer. ofo6pa , ,

. ,
,

752

VI.

. HTML Help ,
-.
, HTML Help.
HTML Help . ,
HTML Help Workshop, ,
, - Microsoft
MSDN (h t t p : / / m s d n . m i c r o s o f t . c o m ).
HTML H e lp W o rk s h o p .
. 24.10 HTML Help Workshop ,
, . 24.9.
) I
UTH1 it
Ip
.
h
V? OfKSnOp
" J
*

j>
File
F ile

Test

Edit

Tags
T
ags

D |e *l < ! * ' !

V
View
ie w

Too
T o o ls

W in d o w

Help

* |

*d

Bial * | |/| |
Project jCortenttj Index j

|<html>

m
m

ml
a
1

<head>
<title>Specifying What to Print </title>
<BASEF0NT FACE"erial">

IO PTOM SJ
Binary Index=No
Compatbity=1 1 or later
Compiled file =formletter chm
Contents file Table of Contents hhc
Defaul Window =main
DefaU* topicTopic1 hbn
Display compile progress =Yes
Language=(k409 English (United States)
T*le=FoiTn Letter Help

</head>
<body>
<p><strong>Specifying What to Print </strongx/p>
<p>Enter the first record to be printed in cell C4,and the last record to be printed in
cell C5. </p>

[W IN D O W S ]
main "Form Letter Help"

<p>To print only one record, enter the same number in cells C4 and C5.&quot </p>
</body>
</html>

[FILESJ
Topic
Topic3htm
Topic4htm
Topic5hbn
Topichtm

[ALIASJ
IDH_TOPIC1=Topic1htm
IDH_TOPIC2-TopK2htm
IDH_TOPIC3=Topic3htm
IOH_TOPIC4Topic4htm
_015-51*
IDH_T0PIC6Top*chtm
[M AP]
defne IDH_T0PC1 1000
define IDH_TOPIC21001
define IOH_TDPIC3 1002
define IDH_TOPIC4 1003
define I0H_T0P1C5 1004
define IDH_TOPICG 1005

M\

. 24.10. HTML Help Workshop

Help
H e lp A p p l i c a t i o n
. WinHelp HLP,
HTML Help . ,
.
H e lp :
A p p lic a tio n .H e lp ( h e lp F ile ,

h e lp C o n te x tID )

24.

753

.
, Excel.
, ,
.
m yapp. chm, .
, ,
. : .
Sub S h o w H e lp C o n te n ts ()
A p p lic a t io n . H e lp T h is W o rk b o o k . P a th & "\m ya p p .ch m "
End Sub


1002.
HTML Help, myapp . chm.
A p p lic a t io n . H e lp T h is W o rk b o o k . P a th & "\m y a p p .ch m ", 1002




: Project Properties ( )
VBA.
Visual Basic Editor Tools^xxx Properties
(1^ ), . Project
Properties ( ) General ()
HTML Help .
. chm.
myf u n c s . chm.
, .
T h is W o rk b o o k .V B P ro je c t. H e lp F ile = T h is W o rk b o o k . P a th & " \m y fu n c s . chm"


, VBA.
Excel 1^ (Developer^Code1^ M acro Security)
(Trust Center).
VBA (Trust Access to the VBA
Project Object Model).

<F1>
(Insert function).
<F1>
U s e rF o rm . ,

, <F1>.

754

VI.


V B A
VBA ,

. ,
<F1>
.
,
.
1. .
2. , (
).
3. Visual Basic Editor <F2>
Object Browser.
4. Project/Library (/).
5. Classes () , .
6. Member () .
7. Properties ()
. ,
Member Options ( ), . 24.11.
H 1

[M e m b e r O p tion s

Name:

.............

IAddTwo

Description:

Cancel

J
Help File:
C:\work\Excel2007_VB,

OK

*j|
I
J

T j
Help Context ID:
| 0

Help

. 24.11.

,
. .

Member Options
. ,
.

, VBA,
.
M a c r o O p tio n s .
M a c r o O p tio n s
,
(AddTwo S q u a re d ). .

24.

755

Sub S e tO p tio n s O
' AddTwo
A p p lic a tio n .M a c r o O p tio n s M a c ro : = "A dd T w o ", _
D e s c r i p t i o n : = " " , _
H e l p F i l e : = T h is W o rk b o o k . P a th & " \m y fu n c s . ch m ", _
H e lp C o n te x tID :=10 0 0
A r g u m e n tD e s c r ip tio n s : = A r r a y s ( " ", _
" ")
S quared
A p p lic a tio n .M a c r o O p tio n s M a c ro : = " S q u a re d ", _
D e s c r i p t i o n : = " " , _
H e l p F i l e : = T h is W o rk b o o k . P a th & " \m y fu n c s . ch m ", _
H e lp C o n te x tID :=2000
A r g u m e n tD e c r ip tio n s : = A r r a y ( " " )
End Sub
1


(Insert Function),
<F1> (Help on This Function).


M a c ro O p tio n s . , Excel 2010
A rg u m e n tD e s c rip tio n s .
.
(Function Arguments),
(Insert Function).
-


- f u n c t io n h e lp \m y fu n c s . x ls m .

2 5
L

...
,

,
, . ,
,
.

,

, , Excel,
.
,
Excel.
, ,
, (
, ,
Excel). ,
, .

VI.

758


(Loan Amortization Wizard) ,
.
. ,
, ,
, .
, .
(* . XLT)
. ,
.
. 25.1 ,
.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38



23 2010

:

:
:
():

:

378
20,0%
75 600
302 400
360
6,25%
01.03.2010

Q

1
2010
2
2010
3
2010
4
2010
5
2010
6
2010
7
2010
8
2010
9
2010
10
2010

Q

Q Q
1 862
1 575
287 302 113
3
4
1 862
1 574
288 301 825
5
1 862
1 572
290 301 535
6
1 862
1 570
291 301 243
7
1 862
1 569
293 300 950
8
1 862
1 567
294 300 656
9
1 862
1 566
296 300 360
10
1 862
1 564
298 300 062
11
1 862
1 563
299 299 763
12
1 862
1 561
301 299 463
18 619

2010

11
12
13
14
15
16
17
18
19
20
21
22

2011
2011
2011
2011
2011
2011
2011
2011
2011
2011
2011
2011

1
2
3
4
5
6
7
8
9
10
11
12

1 862
1 862
1 862
1 862
1 862
1 862
1 862
1 862
1 862
1 862
1 862
1 862

23

2012

22 343
1 862

2011

15 682

1 560
1 558
1 557
1 555
1 553
1 552
1 550
1 549
1 547
1 545
1 544
1 542
18 611

1 540

2 937

299 463

302
304
305
307
309
310
312
313
315
317
318
320

299160
298 856
298 551
298 244
297 936
297 625
297 314
297
296 685
296 368
296 050
295 730
3 732 295 730
322 295 408

. 25.1. ,
30
-

-
lo a n a m o r t iz a t io n w iz a r d .x la m , * .

25.

759



, . ,
.
.
, ,
, .
, .
U s e rF o rm
M u lt iP a g e ,
(. 25.2-25.6).
*J

,

.


,

1%

<

>

.-

. 25.2. 1

|378000

(* : ^

(%):

6,25

_j

<

1302 400

>

jI

. 25.3. 2

F o r m M a in U s e rF o rm ,
;

VI.

760

*1

- 3 5
----------------------------------------:--------------------------------

( 30 (360 )

15 (180 )


: |

- :

: pHHof

. 25.4. 3
- 4 5

|!

<?


--------------------------------------------

<

>

. 25.5. 4
- 5 5

J<J

j
:
|
:
[ 23 20iO .

R 13

|
|
=l J _______
. 25.6. 5

F o rm H elp UserForm ,
;

H e lp S h e e t , ,
;

25.

761

M odM ain VBA, ,


U serForm ;

T hisW orkbook
Open Be f o r e c l o s e Workbook,
.
XML- RibbonX,
Loan Amortization Wizard ( ).


,
(Add-Ins).
^ ^ (File^Excel Options^ Add-Ins).
Excel (Excel Options) (Manage)
Excel (Excel Add-Ins) (Go).
(Browse).
Excel. ,
^ (File^Open).

,
, .
.
, .
,
, .
.
, .
.
. -
,
.
.
. ,
, .

.
RibbonX,
(Insert), . 25.7.
S t a r t A m o r t iz a t io n W iz a r d ,
FormMain.
RibbonX, .
<custom UI x m ln s = "h t t p : //s c h e m a s . m ic r o s o f t . c o m /o f f ic e / 2 0 0 6 / _
01 /c u s to m u i">
< rib b o n >
< ta b s>
< ta b id M s o = " T a b In s e r t">
< g ro u p i d = " g p U t i l s " l a b e l = "Loan A m o r t iz a t io n " >

762

VI.

< b u tto n i d = " b l "


s iz e = " la r g e "
im a g e M so= "C re ateQ u eryF ro m W izard "
la b e l= " L o a n A m o r t iz a t io n W iz a rd "
s u p e r t ip = " _
."
o n A c t io n = " S ta r tA m o r t iz a tio n W iz a r d " />
</g r o u p >
< /ta b >
< /ta b s >
< /r ib b o n >
</c u s to m U I>

22 .

Excel
, .

, .
, .
. 25.8.

mm

I l l

1
w

j
v!
lo a n Amortization Wizard.

Loan Amortization
Wizard
\v,| lo an Amortization

. 25.7.

. 25.8.

,
.
W orkbook_Open,
.
P r iv a t e Sub W orkbook_O pen()
I f G etS etting(A P P N A M E , " D e f a u lt s " ,
"Y e s ") = "Y e s" Then
Form Message. Show
End I f
End Sub

"S how M essage", _


Windows.
( APPNAME). , ^, Yes (),
.
, .

25.
P r iv a te Sub O K B u tto n _ C lic k ()
I f cbMessage Then
S a v e S e ttin g APPNAME, " D e f a u lt s " ,
E ls e
S a v e S e ttin g APPNAME, " D e f a u lt s " ,
End I f
U n lo a d Me
End Sub

763

"Show M essage", "No"


"ShowM essage",

"Y es"


, No (),
.
Form M ain

U s e r F o r m _ I n i t i a l i z e FormMain
.

S t y l e M u ltiP a g e
fm T ab S tyleN on e. , Visual Basic Editor,
.

V a lu e M u ltiP a g e
0.
M u ltiP a g e , , .


ComboBox, .

G e t D e f a u lt s ,
(
).

. ,
O p tio n B u tto n ,
.

,
. ,
O p tio n B u tto n ,
.

U ser F o rm

FormMain
C l i c k C hange ,
UserForm .

,
M u ltiP a g e . M u ltiP a g e i_
Change UserForm ,
/ ,
.
15.

VI.

764

.
, U s e r Form. , (. 25.9).
, .
, ,
M u lt iP a g e .
*

-
j 2
.

1J

. .
15
30 .
(
).
.
.

<

!8 >

. 25.9.

,

. ,
, I s A d d in
F a ls e . , ,
Project (Immediate) :
T h is W o rk b o o k . Is A d d in = F a ls e


24.

.
C l i c k .
1. D a t a l s V a l i d ,
. ,
T r u e .
, D a t a l s V a l i d
, ,
(. 25.10).

25.

765

2. ,
,
.

.
.

. 25.10.
,
,

3. ( , , ,
) .
I f ,
, .
4. .
5. .
, ,
.
. ,
. ,
.
6. , R1C1 (
, ).
7.
.
8. ,
, S u b t o t a l
. Excel,
.
9. ,
,
.
10. Excel , .
,
C l e a r O u t l i n e .
11. ,
: ,
,
.
12. ,
.

VI.

766

13. ,
, , .
, .
14.
(Protect Sheet), ( ).
15. , S a v e D e f a u lt s
U s e rF o rm .
,
(
).

, , U s e rF o rm ,
(F o rm M a in ), ,
. ,
.
-
, .

U s e rF o rm .
, , ,
U s e rF o rm .
, G e t D e f a u lt s ,
U s e rF o rm .
T e x tB o x , C om boBox, O p t i o n B u t t o n , C h e c k B o x S p in B u t t o n ,
V B A G e t S e t t i n g
. , G e t S e t t i n g
, ,
. ,
. APPNAME ,
.
Sub G e t D e f a u lt s ()
'

Dim c t l As C o n tr o l
Dim C tr lT y p e As S t r i n g
F o r Each c t l I n M e .C o n tr o ls
C tr lT y p e = T y p e N a m e (c tl)
I f C tr lT y p e = "T e x tB o x " Or _
C tr lT y p e = "ComboBox" Or _
C tr lT y p e = " O p tio n B u tto n " Or _
C tr lT y p e = "C heckB ox" Or _
C tr lT y p e = " S p in B u tto n " Then
c t l . V a l u e = G e tS e ttin g _
(APPNAME, " D e f a u l t s " , c tl.N a m e ,
End I f
N e xt c t l
End Sub

c tl.V a lu e )

767

25.

. 25.11 ,
Windows (Windows Registry Editor).
*
! >]
Microsoft
Q j MoafaPtughs
|
: &
Netscape
23 Nokia

>1 Hus
1*|]( )
[^ShowMessage

REG.SZ
REG_SZ

( )
Yes


?-~1 Opwa Software
| SflJPoJdee
1 8 S3 PRPlKtMr
il3 RealNetworks
| A CJ SO.
SDL International
; it! &J SOFTWARE
Spyware Terminator
i is S J SSPmt
j
:
Trades
; Trodtech
0 ( VBand VBAProgramSetHngs
Export Charts
: <| Loan Amortnatton Wizard

< Power UOhtv Pak


: StentTek
i $
Tt Toots uaty

Get A Color
13

Vnoneer
WinRAR
] WinRARSFX

ncwieoTe(>'HY_CLIRRB<T'JJseR^eftweVe and VBAProgramSetttngsioan Waardlpefautts

. 25.11. Windows ,

S a v e D e f a u lts , G e tD e f a u lts .
VBA S a v e S e t t i n g
.
Sub S a v e D e fa u lts ()
1

Dim c t l As C o n tr o l
Dim C tr lT y p e As S t r in g
F o r Each c t l I n M e .C o n tro ls
C tr lT y p e = T yp e N a m e (c tl)
I f C tr lT y p e = "T e x tB o x " Or _
C tr lT y p e = "ComboBox" Or _
C tr lT y p e = " O p tio n B u tto n " Or _
C tr lT y p e = "C heckB ox" Or _
C tr lT y p e = "S p in B u tto n " Then
S a v e S e ttin g APPNAME, " D e f a u lt s " ,
C S t r ( c t l. V a lu e )
End I f
N e xt c t l
End Sub

c tl.N a m e , _

, C S tr,
,
, .
G et S e t t i n g , S a v e S e tt in g
.
HKEY_CURRENT_USER\Software\VB and VBA P rogram S e t t i n g s \

,
. ,
, :

768

VI.

,
,
;

,
,
;

(,
);


, - .
,
.
, ,
.

Excel:

( )
;

E n a b le d ;

T e x tB o x S p in B u t t o n ;

VBA;

VBA;

, ,
.
.

?
,
.

?
, ,
.

?
,
, .

25.

769

,
? ,
, , ,
.

?
Excel , .

? ,
, ,
.

? ,
?

?
( )
.

?
.
.

Excel
. ,
. ,
, ,
.

i 1

1

...
2 6


2 7

VBA
2 8

Visual Basic
2 9


3 0


31

Excel

...




Macintosh
64- Excel


Excel, Macintosh
, ,
.



.
.
, . ,
, Windows,
, MacOS Linux.
, :
Excel 2010 Excel Windows Excel
Macintosh. Excel ,
. ,
Excel 97, Excel 2000, Excel 2002, Excel 2003 Excel 2002 Macintosh
, .

774

VII.

. Excel 2010 Excel 2007


. , Excel 2010,
, Excel 2007
.
, Excel , ,
.
,
.
, .

.
Excel. Excel
, .
Excel 2010 ( Excel 2007)
Excel Microsoft Office Compatibility Pack.

. , ,
Excel,
.

, Microsoft. Microsoft
. , 23,
Excel.

Windows Macintosh.
,
.

, . Excel 2010
Excel, 32- 64- . VBA
API-, ,
32- 64- Excel
Excel.

.
Excel,
.
,
:
, Excel.
. ,
Excel.


Excel ,
.

26.

775


Microsoft,
h t t p : / / s u p p o r t . m i c r o s o f t . c o m .
, Excel.


Excel (Excel 2010
), ,
Excel, .
. ,
, Excel ,
.
VBA, ,
, .
.
Excel 2000 ,
Excel 2000,
.
M ic ro s o ft O f f ic e C o m p a tib ilit y P a c k

Excel 2010,
, :

XLS;

, , Microsoft
Office Compatibility Pack.

Microsoft Office Compatibility Pack - Microsoft


w w w .m ic ro s o ft.c o m .
Office Office 2003 , ,
Word, Excel PowerPoint.
: Microsoft Office Compatibility Pack
Excel , Excel 2007 Excel 2010.
.

Excel 2007 ,
Excel 2010 (. 26.1).
^^ ^
(File^Info^Check For Issues^Check Compatibility).
,
Excel.

VII.

776

[ M ic ro so ft E x ce l -

Excel.
Excel
.

^1


.
.
: ' 1'

'

Excel 97-2003
Excel 2007

, .
Excel .
:

|||

Excel 97-2003

:>1|

"

. 26.1.

, VBA
.
Microsoft Office Code Compatibility Inspector ( - h t t p : / /
M i c r o s o f t . c o m ) .
(Developer).
VBA.

Macintosh
Macintosh.
Excel Macintosh Excel,
. ,
XLS .
, ,
VBA .
Excel

v e r s i o n A p p l i c a t i o n Excel.
,
. VBA v a l .
T ru e , Excel 2007
.
F u n c t io n X L 1 2 0 r L a t e r ()
X L 1 2 0 r L a te r = V a l ( A p p l i c a t i o n . V e r s io n )
End F u n c t io n

>= 12

: Excel 2007 12, a Excel 2010 14.


13 .

777

26.

, Excel
Macintosh, VBA.

VBA, ,
. O p e r a tin g S y s te m
A p p l i c a t i o n T ru e,
Windows (.. Win).
F u n c tio n W indow sO SO As B o o le a n
I f A p p l i c a t i o n . O p e r a tin g S y s te m
WindowsOS = T ru e
E ls e
W indowsOS = F a ls e
End I f
End F u n c t io n

lik e

" * W in * "

Then

Windows- - Excel .
(,
). . , Excel
Macintosh ActiveX. , Excel Macintosh
1904, ,
, 4 . Excel Windows
1900. , Macintosh 1 1
1904 . Windows 1 1900 .
Windows API Excel Macintosh
. ,
, .
, ,
( Macintosh
Windows).
VBA.
P a th S e p .
PathSep = A p p l i c a t i o n . P a th S e p a r a to r

P a th S e p
.
, ,

. ( Excel
Windows), .
, .
Excel
Macintosh: .
,
.

64- Excel
Excel 2010 32- 64-
. 64-

VII.

778

Windows. 64- Excel ,


64-
Windows.
64- Excel,
.
64- Excel . ,
64- Excel ,
32- .
, , 32- Excel,
64- Excel.
, VBA,
Windows API. ,
32- API- 64- Excel.
, 32- Excel,
64- Excel 2010 .
D e c la r e F u n c t io n G e tW in d o w s D ir e c to r y A L i b " k e r n e l3 2 " _
(B y V a l l p B u f f e r As S t r i n g , B y V a l n S iz e As L o n g ) As L o n g

Excel 2010 ( 32-,


64-), Excel
.
D e c la r e P t r S a f e F u n c t io n G e tW in d o w s D ir e c to r y A L i b " k e r n e l3 2 " _
(B y V a l l p B u f f e r As S t r i n g , B y V a l n S iz e As L o n g ) As L o n g

API- 32- 64- Excel


.

VBA7 T ru e , VBA 7
( Office 2010).

Win64 T ru e ,
64- Excel.

VBA. ,
Excel Excel 2010,
VB Editor
Excel Help^About Microsoft Visual Basic (
Microsoft Visual Basic),
VBA 7.

API-,
32- 64- Excel.
# I f VBA7 A nd W in64 T h e n
D e c la r e P tr S a f e F u n c t io n G e tW in d o w s D ir e c to r y A L i b Mk e r n e l3 2 " _
(B y V a l l p B u f f e r As S t r i n g , B y V a l n S iz e As L o n g ) As L o n g
# E ls e
D e c la r e F u n c t io n G e tW in d o w s D ir e c to r y A L i b " k e r n e l3 2 " _
^
(B y V a l l p B u f f e r As S t r i n g , B y V a l n S iz e As L o n g ) As L o n g
#End I f

D e c la r e ,
(VBA7 W in d 6 4 ) T r u e

26.

779

16- Excel 2010. Excel


D e c l a r e .


.
Excel .
Excel:
MsgBox A p p l i c a t i o n . I n t e r n a t i o n a l (x lC o u n tr y C o d e )

Excel, ,
1. . 26.1.
2 6 .1 . , E x c e l

()

1
7
30
31
33
34
36
39
42
45
46
47
48
49
55
66
81
82
84
86
90
91
92
351
358
886
966
972
982

VII.

780

Excel ,
Excel .
.
, ,
:
M sgbox A p p lic a tio n .L a n g u a g e S e tt in g s . L a n g u a g e lD ( m s o L a n g u a g e lD U I)

, 1033.
,
, , .
,
.
.
. .
, //.
,
,
.
,
, .
.


,
. ,
, .
(, , ).
-

- m u l t i l i n g u a l w iz a r d ,
x ls m ,
: , .


O p t io n B u t t o n , .

.
U s e r F o r m _ I n i t i a l i z e ,
I n t e r n a t i o n a l .
S e le c t Case A p p l i c a t i o n . I n t e r n a t i o n a l ( x l C o u n t r y C o d e )
Case 34 '
U s e rL a n g u a g e = 2
Case 4 9 '
U s e rL a n g u a g e = 3
Case E ls e '
U s e rL a n g u a g e = 1 '
End S e le c t

. 26.2 ,
.

26.

781

W elcom e to th e W i 2ard Demo. This


w orkb o o k dem onstrates h o w to create
a sim ple "W iza rd -like " app lica tio n in
Excel.

Enter your name:

B ienvenido a W izard Demo. Este


cuaderno d e trabajo dem uestra
crear una aplicacion en Excel con una
"Apariencia-W izard".
Nombre

gngksh
W illko m m e n zur W izard-Dem o. Dieses
an

A rbeitsbuch d e m o n s trie rt w ie Sie e in e


Zauberer-ahnliche A nw endung in Excel
schaffen.
Geben Sie Ihren Namen ein

I______
Eng&sh

Espand

<* Qeutsch

. 26.2. ,

VBA
, VBA . Excel
: Excel VB. Excel
. (
Excel).


, ,
, , . ,
1:
MsgBox R an ge ( " A l " ) . F o rm u la


F o r m u la L o c a l F o r m u la .
MsgBox R ange( " A l " ) . F o rm u la L o c a l

.
. 26.2 ( ,
).
2 6 .2 .

Address

A d d re s s L o c a l

C a teg o ry

C a te g o r y L o c a l

Formula

F o r m u la L o c a l

( XLM)

782

VII.
. 26.2

F o r m u la R lC l

F o r m u la R lC lL o c a l

Name

N am eLocal

Num berForm at

N u m b e rF o rm a tL o c a l

R e fe rs T o

R e fe r s T o L o c a l

R e fe r s T o R lC l

R e fe r s T o R lC lL o c a l


R1C1

R1C1


, ,
, .
.

. ,
.

. , .

. ,
.
I n
t e r n a t i o n a l A p p l i c a t i o n . ,
, :
MsgBox A p p l i c a t i o n . I n t e r n a t i o n a l ( x l D e c i m a l S e p a r a t o r )

45 ,
I n t e r n a t i o n a l . . 26.3.

26.3.

x lC o u n try C o d e
x lC o u n tr y S e ttin g
x l D e c im a lS e p a r a t o r
x lT h o u s a n d s S e p a r a to r
x lL is tS e p a r a to r
x lU p p e rC a s e R o w L e tte r
x lU p p e rC a s e C o lu m n L e tte r
x lL o w e r C a s e R o w L e tte r
x lL o w e r C a s e C o lu m n L e tte r
x lL e ftB r a c k e t
x lR ig h tB r a c k e t
x lL e ftB r a c e
x lR ig h t B r a c e

international


Microsoft Excel




( R1C1)



,
([) R1C1
,
(]) R1C1
,
({)
,
(})

26.

783
. 26.3

xlC o lu m n S e p a ra to r

,

,

,
,

(/)
(:)
()
()
(d)
(h)
()
(s)


,

,

,


;
Microsoft Windows

;
Microsoft Windows
,
True, 24- ;
F alse , 12-
True,
True, ; F alse ,

True,
True, ;
F a ls e
True,
; F a ls e

True, ,

True, ,

x lR o w S e p a ra to r
x lA lte rn a te A rr a y S eparator
x lD a te S e p a ra to r
x lT im e S e p a ra to r
xlYearC ode
xlMonthCode
xlDayCode
xlHourCode
x lM in ute C od e
xlSecondCode
xlC urre ncyC o de
xlG eneralForm atN am e
x lC u r r e n c y D ig its
x lC u rre n c y N e g a tiv e
x lN o n c u r re n c y D ig its
xlMonthNameChars

xlWeekdayNameChars

x lD a te O rd e r
x l2 4 H o u rC lo ck
x lN o n E n g li shFunct io n s
x lM e tr ic
x lC u rre n cyS p a ce B e fo re
x lC u rre n c y B e fo re
x lC u rre n cyM in u sS ig n

x lC u r re n c y T r a ilin g Z e r o s
x lC u rre n c y L e a d in g Z e ro s

784

VII.
. 26.3

xlM o n th L e a d in g Z e ro

True,

xlD a yL e a d in g Z e ro

True,

x l4 D ig itY e a r s

True, ,
F a ls e
True,
- - ( ); F a ls e
/ /
True,

( )

xlMDY

x lT im e L e a d in g Z e ro


,
, ,
.
VBA D a t e S e r i a l , Excel
( ).
D a t e S e r i a l
S t a r t D ate. 1 .
Sub W rite D a te O
Dim S ta r tD a te As D ate
S ta r tD a te = D a t e S e r ia l(2010, 4,
R a n g e ( " A l" ) = S ta r tD a te
End Sub

15)

, ,
. Excel
,
. (
/

).

27

L J


VBA
...






ADO

VBA,
,
.


Excel
.
VBA.
Excel.
F ile S y s te m O b je c t,
Microsoft Scripting Library. Excel 2000 .

Excel F ile S e a r c h ,
Excel 2007 .
, F ile S e a r c h ,
.

786

VII.

,
.

VBA
VBA, , . 27.1.
;
Excel.
2 7 .1 . V B A ,

C hD ir
C hD rive
D ir



,



( )
,




F ile C o p y
F ile D a te T im e
F ile L e n
G e tA ttr
K ill
M kD ir
Name
RmDir
S e tA ttr

,
. 27.1 .

T ru e,
. , F a ls e .
D ir , .
F a ls e .
F u n c tio n F ile E x is ts ( fn a m e )
F i le E x i s t s = D ir( fn a m e )
End F u n c tio n

As B o o le a n
<> " "

F i l e E x i s t s .
, VBA.

T ru e, .
F a ls e .
F u n c tio n P a th E x is ts (p n a m e ) As B o o le a n
1 TRUE,
On E r r o r Resume N e xt
P a th E x is ts = (G e tA ttr(p n a m e ) And v b D ir e c to r y )
End F u n c tio n

= v b D ir e c t o r y

787

27. VBA
-

F i le E x i s t s P a th E x is ts - f i l e f u n c t io n s .x ls m .

( ) ,
. , ,
.
Sub L i s t F i l e s ()
Dim D i r e c t o r y As S t r in g
Dim r As Long
Dim f As S t r i n g
D ir e c to r y = " f : \ e x c e lf ile s \ b u d g e t in g \ "
r = 1
'
C e l l s ( , 1) = " "
C e l l s ( , 2) = ""
C e l l s ( , 3) = " / "
R a n g e ( " A l : C l " ) . F o n t.B o ld = T ru e
1
f = D i r ( D ir e c t o r y , vbR eadO nly + v b H id d e n + vbSystem )
Do W h ile f <> " "
r = r + 1
C e l l s ( r , 1) = f
C e l l s ( r , 2) = F ile L e n ( D ir e c t o r y & f )
C e l l s ( r , 3) = F ile D a te T im e ( D ir e c to r y & f )
'

f = D i r ()
Loop
End Sub

. 27.1 L i s t F i l e s .

2 0 1 -5 0 0 .

0 2 - .mp3

4 03 - .

1 D :\E ntertaim ents\M usik

..... 1

8 581108

10.09.2009 5:00

10199 660

11.09.2009 18:08

12 020 930

09.09.200922:58

5 04 - .mp3

9 570 663

11.09.2009 14:30

8214369

11.09.200914:30

8 506 953

10.09.2009 6:31

05 - .mp3

7 06 - .mp3
8 07 - 151.mp3

10633 300

10.09.2009 6:31

9 08- .mp3

8539 333

10.09.2009 23:02

10 09 - , mp3

14886 044

11.09.2009 16:51

11

. 27.1. L

..JL.

1'

is tF ile s

, D i r .
,
. , D i r ?

VII.

788
-

- c r e a te f i l e l i s t . x l s m
,
.

D i r .
(, Excel), :
f = D i r ( D i r e c t o r y & " * . x l ? ? " / vbR eadO nly + v b H id d e n + vbSystem )

* .x l ? ? .
,
, XL. ,
XLSX, XLTX XLAM. D i r
( , ).
D i r
, , , .
. 27.2 D ir.
2 7 .2 . ,
D ir

vbNo 1

vbReadOnly
vbH idden
vbSystem
vbVolume

1
2
4
8

v b D ir e c to r y

16

. ,
,



. - ,

. . D ir
v b D ir e c to r y

D i r ,
, ,
D ir .
D ir .

, ,
, .
, . .
P u b lic Sub R e c u r s iv e D ir ( B y V a l C u r r D ir As S t r i n g ,
O p tio n a l B yV al L e v e l As Long)
Dim D ir s O As S t r in g
Dim Num D irs As Long
Dim F ileN am e As S t r in g
Dim PathAndName As S t r in g

27. VBA
1
'

789

Dim i As Long

I f R ig h t ( C u r r D ir , 1) <> " \ " Then C u r r D ir = C u r r D ir & " \ "

C e l l s (1, 1) = " "
C e l l s (1, 2) = " "
C e l l s (1, 3) = " "
C e lls (1 , 4) = " / "
R ange( " A l : D l " ) . F o n t . B o ld = T ru e

'


FileN am e = D i r ( C u r r D i r &
v b D ir e c to r y )
Do W h ile L e n (F ile N a m e ) <> 0
I f L e ft( F ile N a m e , 1) <>
Then 1
PathAndName = C u r r D ir & F ileN am e
I f (G e tA ttr(P a th A n d N a m e ) And v b D ir e c to r y ) = _
v b D ir e c t o r y Then
'
ReDim P re s e rv e D ir s ( 0 To N um D irs) As S t r in g
D irs (N u m D irs ) = PathAndName
Num Dirs = Num Dirs + 1
E ls e
'
C e lls (W o r k s h e e tF u n c tio n .C o u n tA _
(R ange( " : " ) ) + 1 , 1) = C u r r D ir
C e lls ( W o r k s h e e tF u n c tio n . C o u n tA ( _
R a n g e ( " B :B " ) )
+ 1 , 2) = F ileN am e
C e lls (W o r k s h e e tF u n c tio n .C o u n tA ( _
R ange( " : C "))
+ 1 , 3) = F ile L e n (P a th A n d N a m e )
C e lls (W o r k s h e e tF u n c tio n .C o u n tA ( _
R ange( " D :D " ))
+ 1 , 4) = _
F ile D a te T im e (P a th A n d N a m e )
End I f
End I f
F ile N am e = D i r ( )
Loop
'
F o r i = 0 N um D irs - 1
R e c u r s iv e D ir D i r s ( i ) , L e v e l + 2
N e xt i
End Sub

C u r r D i r ,
.
.
D i r s . , ,
D i r s .
D i r s .
R e c u r s i v e D i r ,
:
C a ll R e c u r s iv e D ir ( " : \ d i r e c t o r y \ ")
-

- ,
.
r e c u r s iv e f i l e l i s t . x l s m .

VII.

790

FileSystemObject
F ile S y s te m O b je c t Windows Scripting Host
.
- (,
VBScript JavaScript) Excel 2000
.

Windows Scripting Host


, .
,
.

F ile S y s t e m O b je c t ,
, .

(Drive). .

(File). .

(Folder). .

(TextStream). ,
, .

F i le S y s t e m O b j e c t
. .
:
Dim F ile S y s As O b je c t
S e t F ile S y s = C r e a t e O b je c t( " S c r ip t in g . F ile S y s t e m O b je c t " )

, F i le S y s ,
Obj e c t , .
.
, ,
Windows Scripting Host Object Model (. 27.2).
VBE Tools ^References
(^). ,
.
Dim F ile S y s As F ile S y s te m O b je c t
S e t F ile S y s = C r e a t e O b je c t( " S c r ip t in g . F ile S y s t e m O b je c t " )


(Auto List Members) VBE.
.
Object
Browser ( <F2>).

F ile S y s t e m O b je c t .
**

27. VBA

791

R e fe re n c e s - V B P ro je c t

Available References:
\ wiaview 1.0 Type Library

I
I
1

W fn32iinaryFiiter 1.0 Type Library


Windows Media Player
Windows Media Player
Windows Media Player Compatibility Layer
Windows Media Player Launcher
Windows Media Streamer Plugin Tyi

: ~ ..

Cancel

jd
Priority

I wisptis 1.0 Type Library


| WklmgSrv 1.0 Type Library
I WmdmLog 1.0 Type Library
WMIADSI Extension Type Library
j WMICnti 1.0 Type Library
nWMPDeskBand LOTvoe Ubrarv

Help

__ _____ I

Windows Script Host Object Mode!


Location:

C: \WlNDOW5\system32\wsbom.ocx

Language:

Standard

. 27.2.
Windows Script Host Object Model

F u n c t i o n (
), T ru e , .
F u n c tio n F ile E x is ts 3 ( fn a m e ) As B o o le a n
Dim F ile S y s As O b je c t ' F ile S y s te m O b je c t
S e t F ile S y s = C r e a te O b je c t( " S c r ip t in g . F ile S y s t e m O b je c t " )
F ile E x is t s 3 = F ile S y s . F i l e E x i s t s ( fname)
End F u n c tio n

F ile S y s t e m O b j e c t F i le S y s ,
F i l e E x i s t s .

F u n c t i o n (),
T ru e , .
F u n c tio n P a th E x is ts 2 ( p a th ) As B o o le a n
Dim F ile S y s As O b je c t ' F ile S y s te m O b je c t
S e t F ile S y s = C r e a t e O b je c t( " S c r i p t i n g . F ile S y s te m O b je c t")
P a th E x is ts 2 = F i le S y s . F o ld e r E x is ts ( p a th )
End F u n c tio n

F ile S y s t e m O b j e c t
, .
D r iv e s ,
.
. 27.3 ,
. , (ready),
, , , .

VII.

792
_

1
2

.......

..

...'

1
F_____ 1
!


8,002+10 17439453184

3
4

-:.....

1,+11 14097965056

!
4.004EW9 4004007936

7 G

8 Z

, ..;*;.

3.201+11 2.37136+11,l

9
10
4 1 ! , XJ

:<1

...

.... ________ 1

]__1

. 27.3. show D riveinfo


-


- show d r iv e i n f o . x lsm .
Sub S h o w D r iv e in fo ()
Dim F ile S y s As F ile S y s te m O b je c t
Dim D rv As D r iv e
Dim Row As Long
S e t F ile S y s = C r e a t e O b je c t( " S c r ip t in g . F ile S y s t e m O b je c t " )
C e l l s . C le a rC o n te n ts
Row = 1
1
R ange( " A l : F I ") = A r r a y ( " " , " ", " ", " ", _
" ", " ")
On E r r o r Resume N e xt
1
F o r Each D rv I n F ile S y s . D r iv e s
Row = Row + 1
C e lls (R o w , 1) = D r v . D r iv e L e t t e r
C e lls (R o w , 2) = D rv .Is R e a d y
S e le c t Case D r v . D riv e T y p e
" "
Case 0: C e lls (R o w , 3)
" "
Case 1 : C e lls (R o w , 3)
" "
Case 2 : C e lls (R o w , 3)
" "
Case 3 : C e lls (R o w , 3)
" - "
Case 4 : C e lls (R o w , 3)
"RAM- "
Case 5 : C e lls (R o w , 3)
End S e le c t
C e lls (R o w , 4) = Drv.Volum eNam e
C e lls (R o w , 5) = D r v . T o t a lS iz e
C e lls (R o w , 6 ) = D rv .A v a ila b le S p a c e
N e x t D rv
1
A c t iv e S h e e t. L is t O b je c ts .A d d x lS rc R a n g e ,
R ange( " A l " ) . C u rre n tR e g io n , , x lY e s
End Sub

11
Windows API.

27. VBA

793



,
.
. , , C am era M o d e l
( ) D im e n s io n s (); ,
A r t i s t (), T i t l e (), D u r a t i o n () ..
Windows. Win
dows Vista 267 , a Windows 7 .
, .
Sub L i s t F i l e P r o p e r t i e s ()
Dim i As Long
Dim o b jS h e ll As O b je c t ' IS h e llD is p a tc h 4
Dim o b jF o ld e r As O b je c t ' F o ld e r3
'
S e t o b jS h e ll = C r e a te O b je c t( " S h e l l . A p p l i c a t i o n " )
'
S e t o b jF o ld e r = o b jS h e ll.N a m e s p a c e ( "C : \ ")
1
F o r i = 0 To 500
C e lls ( i + 1, 1) = _
o b j F o ld e r . G e tD e t a ils O f( o b j F o ld e r . Ite m s , i )
N e xt i
End Sub

, Windows.
, Windows 2000 T i t l e 11. Windows
10, Windows Vista 21.

F i l e l n f o ,
Windows S h e l l .A p p l i c a t i o n .
( G e tD ir e c to r y , ),
, 41 ( )
.
Sub F i l e l n f o ()
Dim As Long, As Long, i As Long
Dim F ileN am e As O b je c t 1 F o ld e rIte m 2
Dim o b jS h e ll As O b je c t 1 IS h e llD is p a tc h 4
Dim o b jF o ld e r As O b je c t 1 F o ld e r3
'


S e t o b jS h e ll = C r e a t e O b je c t( " S h e l l . A p p l i c a t i o n " )

'


S e t o b jF o ld e r = o b j S h e l l . N a m e s p a c e (G e tD ire c to ry )

W o rk s h e e ts .A d d
= 0
F o r i = 0 4 0
= + 1

'

794

VII.

C e lls (1, ) = o b jF o ld e r . G e t D e t a ils O f ( o b jF o ld e r . Ite m s ,


N e xt i
'
= 1
F o r Each FileN am e I n o b jF o ld e r . Ite m s
= 0
r = r + 1
F o r i = 0 To 4 0
= + 1
C e l l s ( , ) = o b jF o ld e r . G e tD e ta ils O f( F ile N a m e , i )
N e xt i
N e x t FileN am e
'

A c t iv e S h e e t. L is t O b je c ts .A d d x lS rc R a n g e , _
R ange( " A l " ) . C u rre n tR e g io n
End Sub

i)

. 27.4 , ,
MP3.
01 -
02 -
03 -
04
05 -
06 -
07-
08 -
09 - --
10 - pi
11 ,
01 -
04 - ______

6135
3 318
3200
2925
2 240
4 296
4070
4 309
2 666
6104
39$5
6135
2 925

MP3
MP3
MP3
MP3
MP3
MP3
MP3
MP3
MP3
MP3
MP3
MP3

*1*

- !

15.07.200013:50
15.07.2000 13:51
15.07.200013:52
15.07.200013:52
15.07.200013:53
15.07.2000 13:54
15.07.2000 13:55
15.07.200013:56
15.07.200013:57
15.07.200013:59
15.07.200014:00
15.07.200013:50
15.07.200013:52

- ; - *
26.04.2010

13.12.2009 3:23
13.12.2009 3:23
26.04.2010

13.12.2009 3:23
26.04.2010

13.12.2009 3:23
26.04.2010
13.12.2009 3:23
26.04.2010

13.12.2009 3:23
26.04.2010

13.12.2009 3:23
26.04.2010

26.04.2010
13.12.20093:23

13.12.2009 3:23
26.04.2010
13.12.2009 3:23
26.04.2010

13.12.2009 3:23
26.04J010A
26.04.2010
13.12.2009 3:23

13.12.2009 3:23
26.04.20101

- j
SERG- 744857\1
SERG- 744857\1
SERG- 744857\ lex
SRG-7C4485C3C7\Alex
SERG-7C4485C3C7\Alex
SERG- 744857\1
SERG- 744851
SERG-7C4485C3CAAIex
SERG-7C4485C3C7\Alex
SERG- 744857\1
SERG- 744857\1
SERG-7C4485C3C7\Alex
SERG-7C4485C3C7\Alex

. 27.4. ,

S h e l l .
A p p l i c a t i o n , .
VBE T o o ls ^ References (1^
) Microsoft Shell Controls and Automation.
-

- f i l e in f o r m a t io n . x lsm .


VBA ,
. -
, Excel.
.

. .
.

. ,
( VBA,
).

27. VBA

795

.
.
. VBA .
VBA
,
. .
,
.
.


. .
F ile S y s te m O b je c t T e x tS tre a m ,
. F i le S y s t e
mObj e c t Windows Scripting Host.
,
.


VBA O pen ( O pen A p p l i c a t i o n )
.
, .
O pen ,
.
Open F o r [A ccess ] [ ] _
As [#] _ [Len= _ ]

( ). O pen
. () .

( ).
:

A p p e n d ,
, ;
I n p u t , ,
;
O u t p u t ,
.
( );
B i n a r y ,
;
Random ,
, _
Open.

VII.

796

(
). Read, W r i t e R ead W r it e .

.
( ).
: S h a re d , L o c k Read, L o c k W r it e , L o c k R ead W r it e .


1 511.
F r e e F i l e . (
.)

_.

_ .

(
) (
) .


VBA
.
1. Open.
2. S eek ( ).
3. I n p u t , I n p u t # L in e
In p u t

#.

4. C lo se .



.
1. Open.
2. S eek ( ).
3. W r i t e # P r i n t #.
4. C lo se .


, VBA,
Open.
Open " m y f i l e . t x t "

F o r In p u t As #1

, #1.
, # 2 .
Open " a n o t h e r . t x t "

F o r In p u t As #2

VBA F r e e F i l e ,
.
. .

27. VBA

797

F ile H a n d le = F r e e F ile
Open " m y f i l e . t x t " F o r In p u t As F ile H a n d le



. ,
S e ek.


VBA .

:

I n p u t ;

I n p u t # ;
;

L in e

I n p u t # (
/ ).

.
W r i t e # ,
.
, /
. , W r i t e #,
I n p u t #.

P r i n t # ,
. ,

/ . , P r i n t #,
L in e I n p u t # I n p u t #.

E x c e l

Excel .

CSV (Comma Separated Values ).


,
. Excel
.

PRN. ,
.
.
TXT (Tab delimited ).
,
.
^ (File^
Open) ,
.

798

VII.

, Excel
. ,
, . .
( ^ ^ (Data^Data Tools^Text to Table))
. , ,
.


,
.



( ).
Sub Im p o r tD a ta ()
Open " c : \ d a t a \ t e x t f i l e . t x t " F o r In p u t As #1
r = 0
Do U n t i l EOF(1)
L in e In p u t #1, d a ta
A c t i v e C e l l . O f f s e t ( r , 0) = d a ta
r = r + 1
Loop
C lo se #1
End Sub

,
. ,
^ (File^Open).



CSV. , Excel
CSV-, .
.
Sub E x p o rtR a n g e ()
Dim F ile n a m e As S t r i n g
Dim NumRows As Long, NumCols As I n t e g e r
Dim r As Long, As I n t e g e r
Dim D ata
Dim ExpRng As Range
S e t ExpRng = S e le c t io n
NumCols = ExpR ng. C olu m n s. C ount
NumRows = ExpRng. Rows. C ount
F ile n a m e = A p p l i c a t i o n . D e f a u lt F ile P a t h & " \ t e x t f i l e . c s v "
Open F ile n a m e F o r O u tp u t As #1
F o r r = 1 To NumRows
F o r = 1 To NumCols
D ata = ExpRng. C e l l s ( r , c ) .V a lu e
I f Is N u m e ric (D a ta ) Then D ata = V a l(D a ta )
I f Is E m p ty (E x p R n g . C e l l s ( r , c ) ) Then D ata = " "

27. VBA

799

If

<> NumCols Then


W r ite #1, D a ta ;
E ls e
W r ite #1, D ata
End I f
N e xt
N ext r
C lose #1
End Sub

, W rite #.
,
/ .
W rite # ,
.
D a ta .
, ,
. , V a lu e
0. , (
IsE m pty), 0 .
. 27.5 ,
Windows Notepad.
L is te r - [c:\D o cu m e n ts and S e ttin g s \1\ \te x tfile .c s v }

JSJ*l|

100

" ", " 1 " ," 2 " , " 3 " , " 4 " , " 5 " ," 6 " , " "
" " ,2 4 5 8 ,8 3 1 8 ,6 1 1 8 ,2 0 5 5 ,1 7 3 3 ,5 9 8 3 ,2 6 6 6 5
" " ,7 6 3 0 ,7 4 9 6 ,2 8 0 8 ,4 7 2 0 ,2 1 7 6 ,9 2 8 0 ,3 4 1 1 0
" " ,93 7 3 ,64 5 6 ,1*576 ,1 066 ,4408 ,3 5 2 0 ,2 9 3 9 9
" " ,2 2 6 5 ,1 0 4 2 ,3 2 6 1 ,6 0 9 6 ,6 2 9 4 ,6 9 3 7 ,2 5 8 9 5
" " ,9 9 8 9 ,2 0 7 0 ,1 9 3 0 ,4 1 8 8 ,4 1 3 4 ,5 1 7 5 ,2 7 4 8 6
" ",2 0 3 3 ,3 1 6 3 ,5 7 4 0 ,5 8 5 3 ,2 8 9 5 ,1 0 4 7 6 ,3 0 1 6 0
" ",8 7 0 2 ,1 0 6 7 9 ,1 0 5 1 9 ,1 0 1 4 3 ,8 7 9 1 ,1 8 00,5 06 3 4
" " ,6 4 2 0 ,3 7 9 1 ,4 7 7 3 ,1 6 4 5 ,8 6 5 5 ,9 9 2 6 ,3 5 2 1 0
" " ,4 2 4 6 ,8 7 1 7 ,9 6 8 7 ,4 6 0 6 ,2 0 7 8 ,6 9 7 2 ,3 6 3 0 6
" " ,1 0 5 0 9 ,4 3 1 4 ,1 0 8 4 4 ,8 7 4 3 ,8 6 2 3 ,2 5 8 9 ,4 5 6 2 2
" " ,1 1 9 4 ,5 5 8 5 ,7 9 1 9 ,7 9 0 0 ,1 0 3 1 5 ,4 8 4 8 ,3 7 7 6 1
" " ,8 9 2 4 ,3 4 7 5 ,2 3 3 6 ,7 8 0 3 ,1 0 0 0 9 ,6 8 3 8 ,3 9 3 8 5
" " , 7 3 7 4 3 ,6 5 1 0 6 ,7 0 5 1 1 ,6 4 8 1 8 ,7 0 1 1 1 ,7 4 3 4 4 ,4 1 8 6 3 3

. 27.5. VBA
-


- e x p o r t and im p o r t c s v .x ls m .
E x c e l

, CSV-
, Excel
. * . ,
, ,
, .

800

VII.
() - 2 3

-!*!

.
.

<

| | >

:
, .
.
, Excel

CSV. , .
-
, -,
(Cancel).
,
-
.
.
. ,
() (Text Columns), -
.
Sub C le a rT e x tT o C o lu m n s ()
On E r r o r Resume N e xt
I f Is E m p ty (R a n g e ( " A l " )) Then R ange( " A l ") = "XYZZY"
R ange( " A l " ) . T extToC olum ns D e s t in a t io n : =R ange( " A l " ) ,
D a ta T y p e : = x lD e lim it e d / _
T e x t Q u a l i f i e r : = x lD o u b le Q u o te , _
C o n s e c u t iv e D e lim it e r : = F a ls e , _
T a b := F a ls e , _
S e m ic o lo n : = F a ls e , _
Comma: = F a ls e , _
S p a ce : = F a ls e , _
O th e r : = F a ls e , _
O th e rC h a r: = " "
I f R a n g e ( "A l") = "XYZZY" Then R a n g e ("A l") = " "
I f E rr.N u m b e r <> 0 Then MsgBox E r r . D e s c r ip t io n
End Sub

,
. , 1

27. VBA

801

, T extToC olum ns - .
1 , ( T extToC olum ns
, ).
.


,
.
.
. ,
.
Sub Im p o rtR a n g e ()
Dim ImpRng As Range
Dim F ile n a m e As S t r i n g
Dim r As Long, As In t e g e r
Dim t x t As S t r i n g , C har As S t r in g * 1
Dim D ata
Dim i As I n t e g e r
Set ImpRng = A c t iv e C e ll
On E r r o r Resume N e x t
F ile n a m e = A p p li c a t i o n . D e f a u lt F i l e P a t h & " \ t e x t f i l e . c s v "
Open F ile n a m e F o r In p u t As #1
I f E r r <> 0 Then
MsgBox "He : " & F ile n a m e , v b C r i t i c a l , ""
E x i t Sub
End I f
r = 0
= 0
t x t = ""
A p p l i c a t i o n . S c re e n U p d a tin g = F a ls e
Do U n t i l EOF(1)
L in e In p u t #1, D a ta
F o r i = 1 To L e n (D a ta )
C har = M id (D a ta , i , 1)
I f C har = " , " Then '
A c t i v e C e l l . O f f s e t ( r , c) = t x t
= + 1
t x t = ""
E l s e l f i = L e n (D a ta ) Then '
I f C har <> C h r(3 4 ) Then t x t = t x t & C har
A c t i v e C e l l . O f f s e t ( r , c) = t x t
t x t = ""
E l s e l f C har <> C h r(3 4 ) Then
t x t = t x t & C har
End I f
N ext i
= 0
r = r + 1
Loop
C lo se #1
A p p l i c a t i o n . S c re e n U p d a tin g = T ru e
End Sub

26 3ak. 3107

VII.

802

:
, . ,
,
# 2 0 0 7 -0 5 -1 2 # .

Excel
, ,
Excel.
, ,
Excel.
.
, T hisW orkbook
(), .
P r iv a t e Sub W orkbook_O pen()
Open A p p lic a t io n . P a t h & " \ e x c e lu s a g e . t x t "
P r i n t #1, " " & Now
C lo se #1
End Sub

F o r Append As #1

e x c e l u s a g e . t x t
.
:
1 1 /1 6 /1 0 9 :2 7 :4 3

.
, .
P r iv a t e Sub W o rk b o o k _ B e fo re C lo s e (C a n c e l As B o o le a n )
Open A p p lic a t io n . P a t h & " \ e x c e lu s a g e . t x t " _
F o r Append As #1
P r i n t #1, " " & Now
C lo se #1
End Sub
-

e x c e l usage lo g . x s lm
-.

19,
, Workbook_Open W o rkbo ok_B efo reclose .



. F i l t e r F i l e , ,
( i n f i l e . t x t ) , ,
( o u t p u t . t x t ) .
Sub F i l t e r F i l e ()
Open T h is W o rk b o o k . P a th & " \ i n f i l e . t x t "

F o r In p u t As #1

27. VBA

803

Open A p p l i c a t i o n . D e f a u lt F ile P a t h & " \ o u t p u t . t x t " _


F o r O u tp u t As #2
T e x tT o F in d = " "
Do U n t i l EOF(1)
L in e In p u t #1, d a ta
I f I n S t r ( l , d a ta , T e x tT o F in d ) Then
P r i n t #2, d a ta
End I f
Loop
C lo se #1
End Sub
-

, ,
- f i l t e r t e x t f i l e . x ls m .

HTML

HTML. ,
,
-.
Excel ^ -
(File^Save As)? , ,
: HTML. , E x p o r t ToHTML 70 .
2,6 . Excel ^
(File^Save as Web Page),
15,8 ( ).
, E x p o r t ToHTML
.
, .
,
.
Sub E xportToH TM L()
Dim F ile n a m e As V a r ia n t
Dim TDOpenTag As S t r i n g , TDCloseTag As S t r i n g
Dim C e llC o n te n ts As S t r i n g
Dim Rng As Range
Dim r As Long, As I n t e g e r
'

'


Set Rng = A p p l i c a t i o n . I n t e r s e c t ( A c t i v e s h e e t . UsedRange, _
S e le c tio n )
I f Rng I s N o th in g Then
MsgBox " .", v b C r i t i c a l
E x i t Sub
End I f

F ilenam e = A p p lic a tio n .G e tS a v e A s F ile n a m e ( _
I n i t i a l F il e N a m e : = "m y ra n g e . h tm " , _
f i l e F i l t e r : = "HTML F i l e s ( * . h tm ) , * .h tm " )
I f F ile n a m e = F a ls e Then E x i t Sub

VII.

804
1

Open F ile n a m e F o r O u tp u t As #1
'

P r i n t #1,
P r i n t #1,
'

" <HTML>"
"< TABLE BORDER=0 CELLPADDING=3 >"

F o r = 1 To R ng. Rows. C ount


P r i n t #1, "<TR>"
F o r = 1 To R ng. C olu m n s. C ount
S e le c t Case R n g . C e lls ( r , c ) . H o r iz o n t a lA lig n m e n t
Case x lH A lig n L e f t
TDOpenTag = " <TD ALIGN=LEFT>"
Case x lH A lig n C e n te r
TDOpenTag = " <TD ALIGN=CENTER>"
Case x lH A lig n G e n e r a l
I f Is N u m e r ic ( R n g .C e lls ( r , c ) ) Then
TDOpenTag = "<TD ALIGN=RIGHT>"
E ls e
TDOpenTag = " <TD ALIGN=LEFT>"
End I f
Case x lH A lig n R ig h t
TDOpenTag = "<TD ALIGN=RIGHT>"
End S e le c t
TDCloseTag = "< /T D > "
I f R n g . C e l l s ( r / c ) . F o n t . B o ld Then
TDOpenTag = TDOpenTag & "<B>"
TDCloseTag = "< /B > " & TDCloseTag
End I f
I f R n g . C e lls ( r , c ) . F o n t. I t a l i c Then
TDOpenTag = TDOpenTag & " < I> "
TDCloseTag = " < / I > " & TDCloseTag
End I f
C e llC o n te n ts = R n g . C e lls ( r , c ) . T e x t
P r i n t #1, TDOpenTag & C e llC o n te n ts & TDCloseTag
N ext
P r i n t #1, "< /T R > "
N ext r
'

P r i n t #1,
P r i n t #1,
'

" < /TABLE>"


"</HTML>"

C lo se #1
'

MsgBox R n g .C o u n t & " " & F ile n a m e


End Sub

.

. ,
.
. .
F o r-N e x t. HTML (
) . ,
, .

27. VBA

805

. 27.6 , . 27.7
, - HTML-.

1
2

L ...... L _ J

..... _ J L _ .... J

3
4

11249,09.
9 265,44.

11423,69.
10 778,64. [

4 936,33.
10 519,65.

5 438,79.
5044,97.

11606,05.

8 306,11.
11509,05.

11055,09.
6 951,02.

8 388,56.

7956,91.

7 850,21.

9937,65.

9 346,92.

8 399,23.

6456,32.!

8669,86.

10907,65.
4 898,50.

6 298,21.

6 530,04.

8403,11.

8 848,34.

10

5013,93.

7690,16.

9 527,34.

7 327,38.

11
12

8 986,08.

11600,23.
5 011,99.

5 740,46.

11394,59.

9417,73.

10 519,65.

13
14

9994,88.

7996,68.

7659,12.

15

5574,59.

10320,80.
11436,30.
103 956,84.

6500,94.
105 739,70.

1f

...... I

8 965,71.

10557,48. 10421,68.
103121,67. 312818,21.

16
17

. 27.6. ,
HTML

Rte

dht

\$ew

History

gookmarte

Getting Started

file://^:/work/% D0% A3<m }% flE% D0% B /

;; .

Search Web -1

S e rv ic e s # )' ! 0 Wtefe Seajritv Guard |

.!

11249,09.!

11 423,69

4 936,33.

5 438,79.

9 265,44.

10 778,64.

10 519,65.

5 044,97.
8 388,56.

11 606,05.!

8 306,

11055,09.

7 956,91

509,05.

6 951,02.

8 965,71.
10 907,65.

7 850,21.

9 937,65.

9 346,92

8 399,23.

6 45632.

8 669,86

4 898,50.

6 298,21

6 530,04

8 403,11.

8 848,34.

5 013,93

7 690,16.

9 527,34

7 327,38.

8 986,08.!

600,23.

5 740,46

11 394,59.
10 519,65.

5 574,59.!

Goode

Latest Headnes

~/pe vour seardi here..

Tools

5 011,99.

9 417,73

10 320,80

9 994,88.

7 996,68

7 659,12.

436,30.

6 500,94

10 557,48

10 421,68.

103 956,84

105 739,70. 103 121,67. 312 818,21.

. 27.7.
HTML

VII.

806
-


- e x p o r t t o h tm l . x ls m .

XML-
, ,
Excel XML. , XML
.
. , 27.8
, . 27.9 XML-, -.
cs
; 111 l i f j j f
_____

..... ............................................ 1|

4
5

9001 Oovolto
9002 Fuller
9003 leverling
9004 Peacock

Nancy______ Sales Representative


Andrew
Vice President, Sales
Janet
Sales Representative
Margaret
Sales Representative

12.8.68
2.19.52
8.30.63
9.19.58

8
9
10
11

9006 Suyama
9007 King
9008 Callahan
9009 Dodsworth
9102 Jackson

Michael
Robert
Laura
Ann
Raymond

7.2.63
5.29.60
1.9.58
7.2.69
2.16.52

Sales Representative
Sales Representative
inside Sales Coordinatoi
Sales Representative
Sales Representative

5.1.01 507 - 20th Ave. E. A p t 2A


8.14.02 908 W. Capital Way
4.1.06 722 Moss Bay Blvd.
5.3.99 4110 Old Redmond Rd.

Seattle WA
Tacoma WA
Kirkland WA
Redmond WA

London
10.17.97 Coventry HouseSMIner Rd.
1.2.98 Edgeham Hollow Winchester Way London
3.5.94 4726- 11th Ave. N.E.
Seattle Wa
11.15.03 7 Houndstooth Rd.
3.4.00 11 Franklin Way
Portland OR

98122
98401
98033
98052

USA
USA
USA
USA

EC2 7JR
RG19SP
98105
Wt.2
97223

UK

(206) 555-9857
(206) 555-9482
(206) 555-3412
(206) 555-8122
(71) 555-4848
(71)555-7773
(71) 555-5598
(206)555-1189
(71)555-4444
(503)555-0983 ~

UK
USA
UK
USA

'w
L

. 27.8. XML
it i

git

Ffc

Sew

Higtory

{jookmarks

- iR < ' & [


U. Latest HeaAnes

Iools

- in i x i

Help

fc://A>:*nyr4nge xml

Getting Started

Qudc Search; | l f l Type your search here.

jg Search Web -

Look for * |

Services (9 )*

i j i Web Seojnty Guard *

>>

H as X M L f ie does no t appear to have any style m form ation associated w ith tf. The docum ent tree is show n be knv

- < E m p Io y e e L is t>
< E m p lo y e e >
< E m p Io y e e lD > 9 0 0 1< E m p io y e e I D >
< L a s tN a ra e > D a v o lk > < /L a s tN a m e >
< F irs tN a m e > N a a c y < /F ir s t N a e e >
< T itle > S a le s R ep re s e n ta tiv e < T itle >
< B irth D a te > 1 9 6 8 - 12 -0 8 < B irtfc D a te >
< H ire D a te > 2 0 0 1 -0 5 -0 1 < H ir e D a te >
< A d d re s s > 5 0 7 - 20 th A v e E A p t 2 A < /A d d re s s >
< C it y > Seatlie<.C ity >
< R e g jo m > W A < K e g io * >
< P o s ta lC o d e > 9 8 1 2 2 < P o s ta lC o d e >
< C o e tr y > U S A < C o * B try >
< H o m e P h o e > < 2 0 6 ) 555 9 8 5 7 < H o m e P h o .e >
< /E m p lo y e e >
- < 1 >
< E m p lo y e e ID > 9 0 0 2 < E m p k > y e e ID >
< L a s tN a m e > F n le r< /L a s tN a m e >
< F ir s t N e> A n d r e w < F irs t N a e e>
< T itle > V ic e President, S a le s < T itle >
< B ir t k D a te > 1 9 5 2 -0 2 1 9 < /B ir th D a te >
< H ir e D a te > 2 0 0 2 - 0 8 - 1 4 < H ir e D a te >
< A d d re s s > 9 0 8 W

C ap ital W a y < A d d r e s s >

< C ity > T acom a<' ity >


< R e g k m > W A < /R e fio B >
< P o s ta lC o d e > 9 8 4 0 1< P o s ta lC o d e >
< C o M * r y > U S A < C o M tr y >
<1>><206) 5 5 5 -9 4 8 2 < /H o m e P h o e >
< E m p lo y e e >
- <E m pb ye e>
< E n p lo y e e ID > 9 0 0 3 < E m p to y e e ID >
< L a s tN a M *> L e v e riin g < rL a s tN a m >
< F irs tN a m e > J a n e t< /F irs tN a m e >

......... .

[ Oone

. 27.9. XML

27. VBA

807

, Excel 2003, XML, Excel 2010 XML-


() .

E x p o rtT o X M L . ,
E x p o rtT o H T M L , .
Sub E xp ortT o X M L ()
Dim F ile n a m e As V a r ia n t
Dim Rng As Range
Dim r As Long, As Long
'
'


S et Rng = R a n g e ( "T a b le l[# A 1 1 ] ")

F ile n a m e = A p p lic a tio n .G e tS a v e A s F ile n a m e ( _
I n it ia lF ile N a m e : = " m y r a n g e . x m l" , _
f i l e F i l t e r : ="XML F i l e s ( * . x m l) , * . x m l" )
I f F ile n a m e = F a ls e Then E x i t Sub

'


Open F ile n a m e F o r O u tp u t As #1

<xm l>
P r i n t #1, "< ? xm l v e r s io n = " " 1 . 0 " " e n c o d in g = _
""U T F - 8 " " s ta n d a lo n e = " " y e s " "? > "
P r i n t #1, "< E m p lo y e e L is t
x m ln s : x s i = " " h t t p : //w w w .w 3 . o rg /2 0 0 1 /X M L S c h e m a -in s ta n c e " "> "

'


F o r = 2 To R ng . Rows. Count
P r i n t #1, "<E m ployee>"
F o r = 1 To R ng . C olum ns. C ount
P r i n t #1, "< " Sc R n g .C e lls (1, c) & " > " ;
I f Is D a te ( R n g . C e l l s ( r , c ) ) Then
P r i n t #1, F o rm a t(R n g . C e l l s ( r , c) , "y y y y -m m -d d ") ;
E ls e
P r i n t #1, R n g . C e lls ( r / c ) . T e x t ;
End I f
P r i n t #1, " < / " Sc R n g .C e lls (1, c) & "> "
N ext
P r i n t #1, "< /E m p lo y e e > "
N e xt r

P r i n t #1, " < /E m p lo y e e L is t> "

C lo se #1

'

1
'


MsgBox R ng. Rows. C ount - 1 & " " _
Sc F ile n a m e
End Sub
-

- e x p o r t t o
XM L.xlsm .

VII.

808

XML- Excel.
, . 27.10. XML, . ,
.
:
(*

|)^-T^iwuai

-wra,
XML-

. 27.10. XML Excel


, ZIP.
Excel 2010 ZIP ( . z ip ). ZIP , .
. , JPG
, .
-


- z ip f i l e s , x ls m u n z ip a f i l e . xlsm .


ZIP-
. Z i p F i l e s
, . ZIP- com
p r e s s e d . z i p Excel, .
Sub Z i p F i l e s ()
Dim S h e llA p p As O b je c t
Dim F ile N a m e Z ip As V a r ia n t
Dim F ile N am es As V a r ia n t
Dim i As Long, F ile C o u n t As Long
'

F ileN am es = A p p l i c a t i o n . G etO penF ilenam e _
( F i l e F i l t e r : ="A11 F i le s ( * . * ) , * . * " ,
F i l t e r l n d e x := 1 , _
T i t l e : = " " , _
M u l t i S e l e c t : =T rue)
'

I f N o t Is A rr a y ( F ile N a m e s ) Then E x i t Sub
F ile C o u n t = U B ound(F ileN am es)
F ile N a m e Z ip = A p p l i c a t i o n . D e f a u lt F ile P a t h _
& " \c o m p r e s s e d .z ip "
'

Z ip - z ip
Open F ile N a m e Z ip F o r O u tp u t As #1
P r i n t #1, Chr$ (80) Sc Chr$ (75) & C h r$ (5 ) & C h r $ ( 6 ) &

**

27. VBA

809

S t r i n g (18, 0)
C lo se #1
S et S h e llA p p = C r e a t e O b je c t( " S h e l l . A p p l i c a t i o n " )
'


F or i = L B o u n d (F ile N a m e s) To U B ound(F ileN am es)
S h e llA p p .N a m e s p a c e (F ile N a m e Z ip ).C o p y H e re F ile N a m e s ( i)
N e xt i

'


On E r r o r Resume N e x t
Do U n t i l S h e llA p p .N a m e s p a c e (F ile N a m e Z ip ). it e m s . C ount = _
F ile C o u n t
A p p lic a t io n . W a it (Now + T im e V a lu e ( " 0 : 0 0 : 0 1 " ) )
Loop
I f M s g B o x (F ile C o u n t & " : " & _
vbN ew Line & F ile N a m e Z ip & vbN ew Line & vbN ew Line & _
" z i p - ?", v b Q u e s tio n + vbYesNo) = _
vbYes Then S h e ll " E x p lo r e r . e x e / e , " & _
F ile N a m e Z ip , vbN orm alFocus
End Sub

. 27.11 ,
G e tO p e n F ile n a m e A p p l i c a t i o n (
12).
.

fl> Chapter 27

'*'1

* X j !*

^
^

:
:


~
|

. 27.11.

Z i p F i l e s c o m p r e s s e d , z i p
, ZIP-. S h e l l .
A p p l i c a t i o n , C o p y H e r e ZIP-. D o
U n t i l ZIP-. , ,
,
, ZIP- (, , ).
ZIP- ,
, . 27.12.

VII.

810

(Yes) Windows,
.
*1
7 :
C :poojm ents and S e ttin g s V ^ e x \compressed,zip
?
|

. 27.12. ZIP-

z i p F i l e s , ,
. ,
, ,
ZIP-, com pressed,
z ip .


,
, . ZIP, , ! U n z i p p e d ,
Excel, .
Sub U n z ip A F ile O
Dim S h e llA p p As O b je c t
Dim T a r g e t F ile
Dim Z ip F o ld e r
1

T a r g e t F ile = A p p l i c a t i o n . G etO penF ilenam e _


( F i l e F i l t e r : = " Z ip F i le s ( * . z i p ) , * . z i p " )
I f T a r g e t F ile = F a ls e Then E x i t Sub
Z ip F o ld e r = A p p l i c a t i o n . D e f a u lt F ile P a t h & " \U n z ip p e d \"
1

On E r r o r Resume N e xt
RmDir Z ip F o ld e r
M kD ir Z ip F o ld e r
On E r r o r GoTo 0
'

S e t S h e llA p p = C r e a t e O b je c t( " S h e l l . A p p l i c a t i o n " )


S h e llA p p .N a m e s p a c e (Z ip F o ld e r).C o p y H e re _
S h e llA p p .N a m e s p a c e (T a rg e tF ile ) . ite m s
I f M sgBox( " :" & _
vbN ew Line & Z ip F o ld e r & vbN ew Line & vbN ew Line & _
" ? " , v b Q u e s tio n + vbYesNo) = vbYes Then _
S h e ll " E x p lo r e r . e x e / e , " & Z ip F o ld e r , vb N o rm a lF o cus
End Sub

U n z i p A F i l e G e t O p e n F i l e n a m e
ZIP-. S h e l l . A p p l i c a t i o n ZIP- .
.

27. VBA

811

ADO
ADO (ActiveX Data Objects AciveX) ,
,
(
). ,
. ADO
. ADO
DAO (Data Access Objects ).
ADO
Access.

ADO .
Excel ,
.

ADO_Demo Access
bu d g et d a t a . a c c d b . (B udget).
Item , L e a se , D i v i s i o n ,
N. A m erica, Y ear,
2 0 08. R e c o r d s e t,
(. 27.13).
A
1

-T

F
G

D
E

----

10 N. A m e r Data Proces; Facility

Lease

2008

Jan

3450

26311

819

34

34 N. A m er Human Resc Facility

lease

2008

Jan

4353;

3875!

478)

58

58 N. A m e r A ccounting Facility

Lease

2008

Jan

3898

29791

919
-360

10

82

82 N. A m erT ra in in g

Facility

Lease

2008

Jan

3185

3545

106

106 N. A m e r Security

Facility

Lease

2008

Jan

3368

4120

752

130

130 N. A m er R&D

Facility

Lease

2008

Jan

3926

3432

494

154 N. A m e r O perations Facility

Lease

2008

Jan

3715

-386j

178

178 N. A m e r Shipping

Facility

Lease

2008

Jan

2892

1203

10

202;

202 N. A m e r Sales

Facility

Lease

2008

Jan

3242

2687

555

11

226

226 N. A m e r A dvertising Facility

Lease

*2008

Jan

3933

3580

353

12

250

250 N. A m er Public Relati Facility

Lease

2008

Jan

4316

4328

-12

13

1330

1330 N. A m e r Data Process Facility

Lease

2008

Feb

4440

4357

83

14

1354|_

1354 N. A m e r Human Resc Facility

Lease

2008

Feb

4210

3196

1014

154

3329

1378

1378 N. A m e r Accounting Facility

Lease

2008

Feb

2860

3658

798

16

1402

1402 N. A m e rT ra in in g

Facility

Lease

2008

Feb

4468

3759

709

17

1426 N. A m e rS e cu rity

Facility

Lease

2008

Feb

3499

3568

69

18

1450

1450 N. A m e r R&D

Facility

Lease

2008

Feb

3394

4196

802

13

19

1474

1474 N. A m e r O perations Facility

Lease

2008

Feb

4187

3074

1113

20

1498]

1498 N. A m e r Shipping

Facility

Lease

2008

Feb

2870

3751

-881

21

1522

1522 N. A m e r Sales

Facility

Lease

2008

Feb

4046

4013;

14 i Sbeetl

D e s c ry

<3

a<L

.......

_J

. 27.13. Access
Sub ADO_Demo ()
'

1 M i c r o s o f t A c t i v e X D a ta O b j e c t s 2 . x L i b r a r y
D im D B F u llN a m e As S t r i n g
D im C n c t As S t r i n g , S rc As S t r i n g
D im C o n n e c t io n As ADODB. C o n n e c tio n
D im R e c o r d s e t As ADODB. R e c o r d s e t
D im C o l As I n t e g e r
C e l l s . C le a r

812
1

VII.

DBFullName = T h is W o rk b o o k . P a th & " \b u d g e t d a ta .a c c d b "


'

S e t C o n n e c tio n = New ADODB. C o n n e c tio n


C nct = " P ro v id e r= M ic ro s o ft.A C E .O L E D B .1 2 . 0 ; "
C nct = C n ct & "D a ta S o u rce = " & DBFullName & " ; "
C o n n e c tio n .O p e n C o n n e c tio n S t r in g : =C nct
1

S e t R e c o rd s e t = New ADODB. R e c o rd s e t
W ith R e c o rd s e t
'

S rc =
S rc =
S rc =
.Open
'

"SELECT * FROM B u dg e t WHERE Ite m = 'L e a s e '


S rc Sc "a nd D i v is i o n = 'N . A m e ric a ' "
S rc Sc "a n d Y e a r = '2 0 0 8 '"
S o u rc e := S rc , A c t iv e C o n n e c tio n : = C o n n e c tio n

"

F o r C o l = 0 To R e c o r d s e t. F i e l d s . C ount - 1
R ange( " A l " ) . O f f s e t (0 , C o l) .V a lu e = _
R e c o rd s e t. F ie ld s ( C o l) .N a m e
N e xt
'

R ange( " A l " ) . O f f s e t (1, 0 ) . C opyFrom R ecordset R e c o rd s e t


End W ith
S e t R e c o rd s e t = N o th in g
C o n n e c tio n . C lo se
S e t C o n n e c tio n = N o th in g
End Sub
-

(s im p le ado e x a m p le .x ls m )
Access (b u d g e t d a ta .a c c d b )
-. -
ADO
CSV. s im p le ado e xa m p le 2 .x ls m CSV-
m u sic l i s t . c s v .

Visual Basic
...

IDE
IDE
VBA
VBA,

VB VB
UserForm
UserForm

VBE
( VBA).

IDE
,
, VBA .
VBA ,
VBA, .
VBA, , VBA
U serForm .
ID E Visual Basic Editor
OLE.
Visual Basic Extensibility Library

814

VII.

, VBE, IDE.
VBE Tools^References (^)
References (),
Microsoft Visual Basic for Applications Extensibility Library (. 28.1).
V B ID E. V B ID E
, V B ID E ,
, IDE. , IDE
, ,
IDE, , IDE.
R e fe re n c e s - V B A P ro je c t

Avateble References:

Mkrosoft Telephony
^31
Microsoft Terminal Services Active Client 1,0 Type Ub
Microsoft Theme API Type Library
Microsoft Tuner 1.0 Type Library
Microsoft VBScnpt Regular Expressions L.0
Microsoft VBScript Regular Expressions 5.5
Microsoft Vtsio Viewer 14.0 Type Lfcrary

*1
Priority

M krosoft Visual Stuck) .NET VB and C# Project Model


Microsoft Visual Studio 2005 Tools for the Microsoft
Microsoft Visual Studio 2005 Tools for the Microsoft
Microsoft Visual Studio 2005 Tools for the Microsoft
Microsoft Visual Studio 2005 Tools for the M krosoft
ft c
HMiCTOsoft Visual Studip 2005Tools for the Microsoft

Microsoft Visual Basic for Applications Extensibility 5.3

Help

------ ---------

Location:

C:Y>rogram HesVZommon FilesV^toosoft Shared \VBA\VBA6\Vf

Language:

Standard

. 28.1. Microsoft
Visual Basic for Applications Extensibility Library

OLE
20.

IDE,
, :

VBA;

VBA;

U s e rF o rm .

Excel

VBA
Excel, ,
. .^
Microsoft ( Excel 2002)
VBA VBA.
, , ,
, .

28. Visual Basic

815

,
(Trust Center).
:

^ Excel (File^Excel Options);

Excel
(Trust Center);


(Trust Center Settings);

(Trust Center)
(Macro Settings).

^
^ (Developer^Code^Macro Security).
VBA
(Trust Access to the VBA Project Object Model).

-2

<?

( , )

ActiveX


F " VBA

. ,
,
VBA . ,
, - .
VBA.
, V B P ro je c t
. .
On E r r o r Resume N e xt
S et x = A c tiv e W o rk b o o k . V B P ro je c t
I f E r r <> 0 Then
MsgBox " ."

VII.

816
E x i t Sub
End I f

:
Excel. ,
. ,
VBA (Trust Access to Visual Basic Project).

IDE
.
VBE (Visual Basic Environment
Visual Basic). Excel, VBE
. .
VBE
V B P ro je c t
VBComponent
CodeModule
D e s ig n e r
P r o p e r ty
R e fe re n c e
Window
CommandBar

Windows CommandBars
Microsoft Visual Basic for Applications Extensibility Library,
Excel.
V B P ro je c t,
. ,
Excel .

VBProj ects
V B P r o je c t ,
V B P r o j e c t s . V B P ro
j e c t Microsoft Visual Basic
for Applications Extensibility Library (. IDE).
V B P r o je c t W o rk b o o k V B P r o je c t .
, V B P r o je c t
.
Dim VBP As V B P ro je c t
S e t VBP = A c tiv e W o rk b o o k .V B P ro je c t

Dim ,
Microsoft Visual Basic for Application Extensibility.

V B P r o j e c t VBA,
( U s e rF o rm , , ,

28. Visual Basic

817

). V B C o m p o n e n ts . , V B P ro j e c t R e f e r e n c e s ,
, .
V B P r o j e c t s .

Excel. V B P r o j e c t s .
V B P r o je c t ;
V B P r o j e c t .
VBComponents

VBComponents,
VBComponents .
VB .
S et VBC = T h is W o rk b o o k .V B P ro je c t.V B C o m p o n e n ts (1)
S et VBC = T h is W o rk b o o k .V B P ro je c t.V B C o m p o n e n ts ( " M o d u le l" )
R e fe r e n c e s

VBA Excel .
, Tools^ Refe
rences (^) (. 28.1).
(, VBA, Excel, OLE Automation, Office Object Library),
.
VBA. R e f
e r e n c e s R e f e r e n c e ,
. ,
Name, D e s c r i p t i o n F u l l P a t h
R e f e r e n c e .
Sub L is t R e f e r e n c e s ()
Dim R ef As R e fe re n c e
Msg = " "
F o r Each R ef I n A c tiv e W o r k b o o k .V B P ro je c t. R e fe re n c e s
Msg
=Msg &
Ref.Name & vbN ew Line
Msg
=Msg &
R e f . D e s c r ip t io n & vbN ew Line
Msg
=Msg & R e f . F u llP a t h & vbN ew Line & vbN ew Line
N e x t R ef
MsgBox Msg
End Sub

. 28.2 ,
.

R e fe re n c e , L i s t R e fe re n c e s VBA Extensibility
Library. R ef
O b je c t, VBA Extensibility Library .

VII.

818

M icro so ft Excel

VBA
Visual Basic For Applications
:V*OGRA~ 1V:0MM0N~ 1V4ICR0S~ 1\VBA\VBA7\V8E7.DLL
Excel
Microsoft Excel 14.0 Object Library
C:V^ISOffice2010VOffice H^XCa.EXE
stdole
OLE Autonation
C:\WINDOWSWstem32Vstdote2.tib
Office
Microsoft Office 14.0 Object Library
C:V>rogram FiiesYZommon Files M icrosoft Shared\OFFICE14VHSO.DLL
VBSoipt_RegExp_ 10
M krosoft VBScrpfRegular Expressions 1.0
C:\WINDOWS\5ystern32\vbsaipt. cffl\2
VBScnpt_RegExp_55
Microsoft VBScript Regular Expressions 5.5
C:\WWDOWS\pystem32\vbscriptdl\3

OK

. 28.2.
,

.
R e f e r e n c e . A d d F r o m F ile ,
, . A d d F ro m G u id ,
, GUID.
.

VBA
S h o w C o m p o n e n ts , ,
VBA
:

.
Sub ShowCom ponents()
Dim VBP As V B ID E. V B P ro je c t
Dim VBC As VBComponent
Dim row As Long
'

1
'

S e t VBP = A c tiv e W o rk b o o k .V B P ro je c t

C e l l s . C le a rC o n te n ts
R an ge ( " A l : C l ") = A r r a y (" ", " ",
R an ge ( " A l : C l " ) . F o n t . B o ld = T ru e
row = 1
VB
F o r Each VBC I n VBP. VBComponents
row = row + 1

" ")
^

28. Visual Basic


C e lls ( r o w ,
'

1)

819

= VBC.Name

S e le c t Case VBC.Type
Case v b e x t_ c t_ S td M o d u le
C e lls ( r o w , 2 ) = ""
Case v b e x t_ c t_ C la s s M o d u le
C e lls ( r o w , 2) = " "
Case vb e xt_ct_M S F o rm
C e lls ( r o w , 2) = " "
Case v b e x t_ c t_ D o c u m e n t
C e lls ( r o w , 2) = " "
End S e le c t
1

C e lls ( r o w ,
N e x t VBC
End Sub

3) = VBC. C odeM odule. C o u n tO fL in e s

,
(, v b e x t_ c t_ S td M o d u le ) .
, Microsoft
Visual Basic for Applications Extensibility Library.
. 28.3 ShowCom ponents.
VBA ,
.
A

2 ThisWorkbook

0|

3 S h e e tl

M o d u le l

Classl

U serForm l

UserForm

50

H 4 ! 1 . 2

_J

46

JL

7 Sheet2
Sheet3

. W < \ j i

J ................ >0

. 28.3.
ShowComponents
-


- l i s t vb com ponents .x ls m .
, VBA Extensibility Li
brary, VB-.

VBA,

L i s tP r o c e d u r e s , ,
VBA, , .
Sub L is t P r o c e d u r e s ()
Dim VBP As V B ID E .V B P ro je c t
Dim VBC As VBComponent
Dim CM As CodeModule

VII.

820
Dim S t a r t L in e As Long
Dim Msg As S t r in g
Dim ProcName As S t r i n g


S e t VBP = A c tiv e W o rk b o o k .V B P ro je c t

'

VB
F o r Each VBC I n VBP. VBComponents
S e t CM = VBC. CodeModule
Msg = Msg & vbN ew Line
S t a r t L in e = CM. C o u n tO fD e c la ra tio n L in e s + 1
Do U n t i l S t a r t L in e >= CM. C o u n tO fL in e s
Msg = Msg & VBC.Name &
" & _
C M .P r o c O fL in e ( S ta r tL in e , v b e x t_ p k _ P r o c ) & vbN ew Line
S t a r t L in e = S t a r t L in e + CM. P ro c C o u n tL in e s _
(CM. P r o c O f L in e ( S t a r t L in e , v b e x t_ p k _ P r o c ) , _
v b e x t_ p k _ P r o c )
Loop
N e xt VBC
MsgBox Msg
End Sub

. 28.4 ,
.
-


-
l i s t a l l p ro c e d u re s . xlsm .

ThsWorkbook: WoricbookjOpen
Sheet 1; Worksbeet_Seledx>nChange
Modulel: UstProcedures
Modulel: Macro 1
M odulel: Macro2

Module 2: JustAMacro
UserForml: CommandButtonl_Cfeck
UserForml: O ptw nButtonljC kk
UserForml: OpbonButton2_C6ck

, ,
VBA VBA.
V B C om ponent ( E x p o r t, 28.4.
Remove I m p o r t ) , - ,
. ,
, ,
,
.
, .
, ,
VBA , .
:

U s e r B o o k . x ls m ( M o d u le l) , ^

U p d a t e U s e r B o o k . x ls m VBA,
M o d u le l U s e r B o o k . x ls m .

28. Visual Basic

821

B e g i n U p d a t e .
U p d a t e U s e r B o o k . x l s m ,
U s e r B o o k . x l s m . ,
U s e r B o o k . x l s m . ,
. 28.5.
I

M icro so ft Excel

Modulel UserBook.xlsm Module.

( .

. 28.5. ,

Sub B e g in U p d a te ()
Dim F ile n a m e As S t r in g
Dim Msg As S t r i n g
F ile n a m e = "U s e rB o o k .x ls m "


On E r r o r Resume N ext
W o r k b o o k s ( F ile n a m e ) .A c tiv a te
I f E r r <> 0 Then
MsgBox F ile n a m e & " ." , v b C r i t i c a l
E x i t Sub
End I f
Msg = " M o d u le l U s e rB o o k .x ls m "
Msg = Msg Sc " ." & v b C rL f & v b C rL f
Msg = Msg Sc " OK ."
I f M sgBox(Msg, v b ln fo r m a t io n + vbO KC ancel) = vbOK Then
C a ll R e p la ce M o d u le
E ls e
MsgBox " ,", v b C r i t i c a l
End I f
End Sub

( ) R e M o d u l e l
U s e r B o o k . x l s m M o d u l e l , U p d a t e U s e r

p la c e M o d u le .
B o o k . x ls m .

Sub R e p la c e M o d u le ()
Dim M o d u le F ile As S t r in g '
Dim VBP As V B ID E .V B P ro je c t
1 M o d u le l
M o d u le F ile = A p p l i c a t i o n . D e f a u lt F ile P a t h & "\te m p m o d x x x .b a s "
T h is W o rk b o o k . V B P roj e c t . VBCom ponents( " M o d u le l") _
.E x p o r t M o d u le F ile

M o d u le l U serBook
S e t VBP = W o rk b o o k s ( "U s e rB o o k .x ls m ") .V B P ro je c t
On E r r o r GoTo E rrH a n d le
W ith VBP.VBComponents
. Remove VBP. VBC om ponents( " M o d u le l")
.Im p o r t M o d u le F ile

VII.

822
End W ith
'


K i l l M o d u le F ile
MsgBox " .", v b ln f o r m a t io n
E x i t Sub
E r r H a n d le :
' ?
MsgBox ". .", _
v b C r itic a l
End Sub

.
1. M odulel ( ).
,
.
2. U s e r F o r m .x ls m M o d u le l (
). Rem ove V B C o m p o n e n t s.
3. ( )
U s e r B o o k . x ls m .
4. .
5. ,
.
.
-


- : U serB ook. x ls m U pdateU serB ook. xlsm .

VBA VBA
, , VBA
VBA. A ddB uttonA ndC ode
.
1. .
2. CommandButton.
3. , C om m an dB utton .
4. Command
B u tto n .

C o m m a n d B u tto n l_ C lic k .
1.
A d d B u tto n A n d C o d e .
Sub A d d B u tto n A n d C o d e ()
Dim NewSheet As W o rkshe et
Dim N ew B u tto n As O LEO bject

28. Visual Basic

823

'


S e t NewSheet = S h e e ts .A d d

'


S e t N ew B u tto n = N e w S h e e t.O L E O b je cts.A d d _
( " F o rm s. Com m andButton.1 " )
W ith N ew B u tto n
.L e ft = 4
.Top = 4
.W id th = 100
.H e ig h t = 24
. O b je c t . C a p tio n = " 1"
End W ith

'


Code = "Sub C o m m a n d B u tto n l_ C lic k ( ) " & v b C rL f
Code = Code & " On E r r o r Resume N e x t" & v b C rL f
Code = Code & " S h e e ts ( " " 1 "" ) . A c t iv a t e " & v b C rL f
Code = Code & " I f E r r <> 0 Then" &
v b C rL f
Code = Code & " MsgBox "" 1 . " " " _
& v b C rL f
Code = Code & " End I f " & v b C rL f
Code = Code & "End Sub"

W ith A c tiv e W o r k b o o k .V B P ro je c t. _
V B C om ponents(N ew S heet.N am e). CodeModule
N e x tL in e = . C o u n tO fL in e s + 1
. I n s e r t L in e s N e x tL in e , Code
End W ith
End Sub

. 28.6 C o m m a n d B u tto n ,
A d d B u tto n A n d C o d e .

|. . 6

_f

. 28.6. , C o m m a n d B u t t o n
VBA


- add b u tt o n and co d e . x ls m .

VBA
. , Code.
.
I n s e r t L i n e s .

824

VII.

N e x t L in e
.
.
, O p t io n
E x p l i c i t , .
. 28.7 ,
A d d B u tto n A n d C o d e .
CommandButtonl

**

P r iv a t e Sub Com m andButtonl C lic k : ()


On E r r o r Resume N e xt
S h ee ts ( " J Ih c tI" ) . A c t iv a t e
I f E r r <> 0 Then
MsgBox " J I h c t I . "
End I f
End Sub

___ 1

fli

. 28.7. VBA


U se rF o rm

, Use Form,
, ,
,
.
VBE,
.
U s e rF o rm , . 28.8 ( U s e r
F o rm l), 100 C o m m a n d B u tto n .
. ,
C o m m a n d B u tto n .

, .
VBA
.

28. Visual Basic

825

. 28.8.
C o m m a n d B u t t o n
U s e r F o r m VBA

userForm

U se F o rm
.
U s e r F o r m ,
. ,
, . ,
C a p t io n ,
.
VBE, , U s e rF o rm .
IV ,
U se F o rm .
, .

VBE. , VBA

U se Form .
, D e s ig n e r U s e rF o rm .

, ,
C o m m a n d B u tto n U s e r Form .
, .
R u n T im e B u tto n , , .
C o m m a n d B u tto n
.
Use Form . C o m m a n d B u tto n

VII.

826

.
VBE, , .
Sub R u n T im e B u tto n ()
'

Dim B u tn As CommandButton
S et B u tn = U s e rF o rm l. C o n tr o ls .A d d ( "F o rm s . C om m andB utton.1 ")
W ith B u tn
.C a p tio n = " "
.W id th = 100
.Top = 10
End W ith
U s e rF o rm l. Show
End Sub

D e s i g n T i m e B u t t o n . ,
D e s i g n e r , V B C o m p o n e n t .
, A d d C o m m a n d
B u t t o n . D e s i g n e r ,
C o m m a n d B u t t o n U s e r F o r m ,
.
Sub D e s ig n T im e B u tto n ()
'
Dim B u tn As CommandButton
S e t B u tn = T h is W o r k b o o k .V B P ro je c t. _
VBC om ponents( "U s e rF o rm l") _
. D e s ig n e r . C o n t r o ls .A d d ( " F o rm s. Com m andButton.1 " )
W ith B u tn
.C a p tio n = " "
.W id th = 120
.Top = 4 0
End W ith
End Sub

100 CoxnmandButton

D e
U s e r F o r m . 100
C o m m a n d B u t t o n (
), C a p t i o n
C o m m a n d B u t t o n 100 (
C o m m a n d B u t t o n ) .
s ig n e r

Sub A d d lO O B u tto n s ()
Dim UFvbc As VBComponent
Dim CMod As CodeModule
Dim c t l As C o n tr o l
Dim cb As CommandButton
Dim n As Long, As Long,
Dim code As S t r in g
'

r As Long

S e t UFvbc = T h is W o rk b o o k .V B P ro je c t.V B C o m p o n e n ts ( " U s e rF o rm l")



F o r Each c t l I n U F vb c. D e s ig n e r . C o n tr o ls

28. Visual Basic

827

U F v b c .D e s ig n e r. C o n t r o ls . Remove c tl.N a m e
N e xt c t l
' VBA
U F vb c. C odeM odule. D e le te L in e s 1, U F vbc. C odeM odule. C o u n tO fL in e s
1 100 CommandButton
n = 1
F o r r = 1 To 10
F o r = 1 To 10
S e t cb = U F vb c. D e s ig n e r . _
C o n t r o ls . A d d ( "F o rm s . C om m andButton.1 " )
W ith cb
.W id th = 22
.H e ig h t = 22
. L e f t = (c * 26) - 16
.Top = ( r * 26) - 16
.C a p tio n = n
End W ith
'

W ith U F vb c. CodeModule
code = " "
code = code & " P r iv a t e Sub CommandButton" Sc n Sc _
" _ C lic k " Sc vb C r
code = code & "Msgbox "" " Sc n Sc _
" " " " & vb C r
code = code & "End Sub"
. In s e r t L in e s . C o u n tO fL in e s + 1, code
End W ith
n = n + 1
N ext
N ext r
End Sub
-


- add b u tto n s .x ls m .

A d d lO O B u tto n s U s e rF o rm (
U s e r F o r m l) .
.
. D e l e t e L i n e s C o d e M o d u le .
C o m m a n d B u tto n
F o r - N e x t .
. (
C o m m a n d B u tto n l).
P r iv a t e Sub C o m m a n d B u tto n l_ C lic k ()
MsgBox " C om m andB uttonl"
End Sub


,
End Sub.
VBA. U s e rF o rm s . A d d ( " U s e rF o rm l" ) . Show

, ,
U s e rF o rm . VBA U s e r -

VII.

828

Form, 100 ,
, .
U se rF o rm l U serF orm s,
A dd. (,
) .
A d d Show. ,

U serF orm s.


UserForm
VBA
U se F o rm .
: , .


, , .
, . .
M a ke F o rm .
1. U serF orm .
Add VBComponents.
2. Com m andButton UserForm .
D e s ig n e r .
3. UserForm.
(C o m m an d B u tto n l_ C lick )
.
4. U se Form .
5. U serForm .

U s e rF o rm , .
,
.
, .
M akeF orm .
Sub M akeForm ()
Dim TempForm As O b je c t
Dim N ew B u tto n As M s fo rm s . CommandButton
Dim L in e As I n t e g e r
A p p lic a tio n .V B E .M a in W in d o w .V is ib le = F a ls e
'
U serForm
S e t TempForm = T h is W o rk b o o k .V B P ro je c t. _
VBCom ponents. A d d (3) 1 v b e xt_ct_M S F o rm
W ith TempForm
. P r o p e r t i e s ( " C a p t io n " ) = " "

28. Visual Basic

'

'

829

. P r o p e r t i e s ( " W id th " ) = 200


. P r o p e r t i e s ( " H e ig h t ") = 100
End W ith
CommandButton
S e t N ew B u tto n = T e m p F o rm .D e s ig n e r. C o n tr o ls _
.A d d ( " F o rm s. C om m andButton.1 " )
W ith N ew B u tto n
.C a p tio n = " !"
. L e f t = 60
.Top = 4 0
End W ith

W ith TempForm.CodeModule
L in e = . C o u n tO fL in e s
. I n s e r t L i n e s L in e + 1, "Sub C o m m a n d B u tto n l_ C lic k ( ) "
. I n s e r t L i n e s L in e + 2, " MsgBox " " !" " "
. I n s e r t L i n e s L in e + 3 , " "
. I n s e r t L i n e s L in e + 4, "End Sub"
End W ith

VB A.U serForm s .Add (TempForm.Name) . Show


T h i sW o rkb o o k. VB P roj e c t . VBComponent s . Remove TempForm
End Sub
-

- a te u s e r fo r m on th e f l y . x l s m .

M a ke F o rm U s e rF o rm ,
. 28.9.

. 28.9. UserForm

, MakeForm,
VBA Extensibility Library. ,
TempForm o b je c t (
VBComponent). .

, VBE
V i s i b l e F a ls e .
.

VII.

830


, .
G e t O p t i o n , U s e r F o r m .
O p t i o n B u t t o n ,
. ,
O p t i o n B u t t o n , .
-


- g e t o p t io n f u n c t i o n . x ls m .

G e t O p t io n .
F u n c tio n G e tO p tio n (r a y , D e f a u lt , T i t l e )
Dim TempForm As O b je c t
Dim N e w O p tio n B u tto n As M s fo rm s . O p tio n B u tto n
Dim NewCommandButtonl As M s fo rm s . CommandButton
Dim NewCommandButton2 As M s fo rm s . CommandButton
Dim i As I n t e g e r , TopPos As I n t e g e r
Dim M axW idth As Long
Dim Code As S t r i n g
'
'

VBE
A p p lic a tio n .V B E .M a in W in d o w .V is ib le = F a ls e
U serForm
S e t TempForm = _
T h is W o rk b o o k .V B P ro je c t.V B C o m p o n e n ts .A d d (3)
T e m p F o rm .P ro p e rtie s ( " W id th " ) = 800

O p tio n B u tto n
TopPos = 4
M axW idth = 0 ' O p tio n B u tto n
F o r i = L B ou n d(O p A rra y) To U B ound(O pA rray)
S e t N e w O p tio n B u tto n = T e m p F o rm .D e s ig n e r. C o n t r o ls . _
A d d ( " F o rm s. O p tio n B u tto n .1 " )
W ith N e w O p tio n B u tto n
.W id th = 800
.C a p tio n = O p A r r a y ( i)
.H e ig h t = 15
. A c c e le r a t o r = L e f t ( . C a p tio n , 1)
.L e ft = 8
.Top = TopPos
.Tag = i
.A u to S iz e = T ru e
I f D e f a u lt = i Then .V a lu e = T ru e
I f .W id th > M axW idth Then M axW idth = .W id th
End W ith
TopPos = TopPos + 15
N ext i

'


S e t NewCommandButtonl = T e m p F o rm .D e s ig n e r. C o n t r o ls . _
A d d ( " F o rm s. C om m andButton.1 " )
W ith NewCommandButtonl
.C a p tio n = ""
. C a n ce l = T ru e

28. Visual Basic


.H e ig h t = 18
.W id th = 44
. L e f t = M axW idth + 12
.Top = 6
End W ith
'

OK
S e t NewCommandButton2 = T e m p F o rm .D e s ig n e r. C o n t r o ls .
A d d ( " F o rm s. C om m andButton.1 " )
W ith NewCommandButton2
.C a p tio n = "OK"
. D e f a u lt = T ru e
.H e ig h t = 18
.W id th = 44
. L e f t = M axW idth + 12
.Top = 28
End W ith
CommandButton
Code = n
Code = Code Sc "Sub C om m andButtonl C l i c k ( ) " & v b C rL f
Code = Code Sc " GETOPTION RET V A L = F a ls e " & v b C rL f
Code = Code Sc " U n lo a d Me" & v b C rL f
Code = Code Sc "End Sub" Sc v b C rL f
Code = Code Sc "Sub C o m m a n d B u tto n 2 _ C lic k ( ) " & v b C rL f
Code = Code Sc " Dim c t l " Sc v b C rL f
Code = Code Sc " GETOPTION_RET_VAL = F a ls e " & v b C rL f
Code = Code Sc " F o r Each c t l I n M e .C o n tr o ls " & v b C rL f
Code = Code Sc " I f T y p e N a m e (c tl) = " " O p t io n B u t t o n " " " _
Then" 1 Sc: v b C rL f
Sc
Code = Code Sc " I f c t l Then GETOPTION_RET_VAL = "
Sc
c t l . T a g " Sc v b C rL f
Code = Code Sc " End I f " Sc v b C rL f
Code = Code Sc " N e xt c t l " Sc v b C rL f
Code = Code Sc " U n lo a d Me" & v b C rL f
Code = Code Sc "End Sub"
W ith TempForm.CodeModule
. I n s e r t L in e s . C o u n tO fL in e s + 1, Code
End W ith

'


W ith TempForm
. P r o p e r t i e s ( " C a p t io n " ) = T i t l e
. P r o p e r t i e s ( " W id t h " ) = New C om m andButtonl. L e f t + _
NewCommandButton1 .W id th + 10
I f . P r o p e r t i e s ( " W id t h " ) < 160 Then
. P r o p e r t i e s ( " W id t h " ) = 160
N ew C om m andButtonl. L e f t = 106
NewCommandButton2. L e f t = 106
End I f
. P r o p e r t i e s ( " H e ig h t ") = TopPos + 24
End W ith


VBA. U s e rF o rm s .A d d (TempForm. Name) . Show

T h is W o rk b o o k . V B P roj e c t . VBCom ponents. Remove VBComponent
=TempForm

'

832

VII.

'


G e tO p tio n = GETOPTION_RET_VAL
End F u n c tio n

G e t O p t i o n , ,
.
.
U s e Form .
G e t O p t io n

G e t O p t i o n .

O p A r r a y , ,
O p t i o n B u t t o n .

D e f a u l t , O p t i o n
B u t t o n , U s
e r Form . 0,
O p t i o n B u t t o n .

T i t l e ,
U s e r F o r m .

G e t O p t io n

G e t O p t i o n .
1. VBE,
UserForm .
2. U s e F orm Tem pForm .
3. O p tio n B u tto n .
,
O p A r r a y . T a g
. T a g
.
4. CommandButton:
.
5. Com m andButton
.
6. U s e Form:
C o m m a n d B u tto n
U s e r F o r m .
7. U s e r F o r m .
, C o r a m a n d B u tto n l_ C lic k . ,
O p t i o n B u t t o n ,
GETOPTION_RET_VAL (*
P u b l i c ) .
8. Use Form .

28. Visual Basic

833

9. GETOPTION_RET_VAL
.

Use rF o rm ,
VBA Extensibility Library.
, (
m odO ptionsForm ),
G e tO p tio n .

G e t O p t i o n .
U s e r F o r m (
O p s ) .
Sub T e s tG e tO p tio n ()
Dim O p s (1 To 5)
Dim U s e rO p tio n
O p s(1) = " "
O p s(2) = ""
O p s(3) = " "
O p s(4) = " "
O p s(5) = " "
U s e rO p tio n = G e tO p tio n (O p s , 5,
D e b u g .P r in t U s e rO p tio n
MsgBox O p s (U s e rO p tio n )
End Sub

" ")

U s e r O p t i o n .
( <Escape>),
U s e r O p t i o n F a l s e .
, A c c e l e r a t o r
,
<Alt+> .
,
.
. 28.10 U s e r Form, .

U serForm ,
,
. G e tO p tio n
.
,
. . 28.11 , ,
.
G e t O p t io n


C o m m a n d B u t t o n . G e t O p t i o n
( U s e r F o r m ) .
27 . 3107

VII.

834

Sub C o m m a n d B u tto n l_ C lic k ()


GETOPTION_RET_VAL = F a ls e
U n lo a d Me
End Sub
Sub C o m m a n d B u tto n 2 _ C lic k ()
Dim c t l
GETOPTION_RET_VAL = F a ls e
F o r Each c t l I n M e .C o n tr o ls
I f T y p e N a m e (c tl) = " O p tio n B u tto n " Then
I f c t l Then GETOPTION_RET_VAL = c t l . T a g
End I f
N e xt c t l
U n lo a d Me
End Sub
I ?

B IS : i d

Highway 61 Revisited
good On The Tracks
gonde On Blonde

j
i
1

<

*1

r lPi
(2

1___ SS.... 1


(* gee
. 28.10. G e t O p t i o n
U s e r F o r m

Love And Theft

Modem Times
Together Through Life

.
1

. 28.11.
u s e r F o r m

U serForm ,
VBE. ,

(' ).
T h is W o rk b o o k . V B P roj e c t . VBCom ponents. Remove _
VBCom ponent: =TempForm


...




CSVFileClass

,
,
.


VB
. Excel 97
. , ,
.
(class module) VBA,
. ,
. , Excel
. ,
, .

( 15, 18, 19 22)


.

? :
. ,
.
, .
.

836

VII.

, . (
18.)

.
. ( 19 22.)

Windows API
. , ,
<NumLock> <CapsLock>.
, .


U serF o rm . .

15 ,
Com m andButton
C lic k .

, ;
.
,
.


,
, . NumLock,
(V alue) (T oggle).
<NumLock>
Windows API.
<NumLock>. API-,
( VBA).
? ,
.
VBA, <NumLock>
, V a l u e .
MsgBox Num Lock. V a lu e

<NumLock>. ,
<NumLock>:
N um Lock.V alue = T ru e

<NumLock> T o g g le .
NumLock. T o g g le

, , ,
.
VBA ,
.
,
. .

29.


VBE Inserts Class Module (^
). ,
C l a s s l . Properties () ,
<F4>. Properties NumLo
C la s s (. 29.1).
: fit

Edit

Jmert

Fe*iMt

Btbuo gun

loo's

Aea In!

yymaow blp

eepot

. . >

VBA
, Va
<NumLock>, ;
Windows API,
<NumLock>. .

,
- Microsoft. Excel 2
, -,
Excel.
1
P r iv a t e Type OSVERSIONINFO
d w O S V e rs io n ln fo S iz e As Long
d w M a jo rV e rs io n As Long
d w M in o rV e rs io n As Long
dw B uildN um ber As Long
d w P la tfo r m ld As Long
szC S D V ersion As S t r in g * 128
End Type
' A P I-
P r iv a t e D e c la re P trS a fe F u n c tio n G e tV e rs io n E x L ib

"K e rn e l3 2 "

838

VII.

A l i a s "G e tV e rs io n E x A " _
( lp V e r s io n ln f o r m a t io n As OSVERSIONINFO) As Long
P r iv a t e D e c la re P trS a fe Sub k e y b d _ e v e n t L ib "u s e r3 2 " _
(B yV a l bVk As B y te , _
B yV al bScan As B y te , _
B yV al d w fla g s As Long, B yV al d w E x tr a ln fo As Long)
P r iv a t e D e c la re P trS a fe F u n c tio n G e tK e y b o a rd S ta te L ib " u s e r 3 2 n _
(p b K e y S ta te As B y te ) As Long
P r iv a t e D e c la re P trS a fe F u n c tio n S e tK e y b o a rd S ta te L ib "u s e r3 2 " _
(Ip p b K e y S ta te As B y te ) As Long
'
C onst VK_NUMLOCK = &H90
C onst VK_SCROLL = &H91
C onst VK_CAPITAL = &H14
C onst KEYEVENTF_EXTENDEDKEY = &H1
C onst KEYEVENTF_KEYUP = &H2

,
<NumLock>. V a l u e .
. V a l u e .
,
P ro p e rty

G e t.

P r o p e r ty G et V a lu e () As B o o le a n
1
Dim k e y s (0 To 255) As B y te
G e tK e y b o a rd S ta te ke ys(O )
V a lu e = keys(VK_NUMLOCK)
End P r o p e r ty

P r o p e r ty .

.

, W in d o w s API G e t K e y b o a r d S t a t e ,
<NumLock>. ,
VBA V a l u e . , VBA,
, P r o p e r t y G e t .
MsgBox N um Lock.V alue

,
<NumLock>. :
. P r o p e r t y L e t .
P r o p e r ty L e t V a lu e ( b o o lV a l As B o o le a n )
Dim As OSVERSIONINFO
Dim k e y s (0 To 255) As B y te
. d w O S V e rs io n ln fo S iz e = L e n (o )
G e tV e rs io n E x
G e tK e y b o a rd S ta te ke ys(O )
'
?
I f b o o l V a l = T ru e And ke ys (VK_NUMLOCK) = 1 Then E x i t P ro p e ifty
I f b o o lV a l = F a ls e And keys(VK_NUMLOCK) = 0 Then E x i t P r o p e r ty
'
.
'

k e y b d _ e v e n t VK_NUMLOCK, &H45, KEYEVENTF_EXTENDEDKEY Or 0, 0

29.

839


ke y b d _ e v e n t VK_NUMLOCK, &45, KEYEVENTF_EXTENDEDKEY Or
KEYEVENTF_KEYUP, 0
End P r o p e r ty

P r o p e r t y L e t ,
T r u e , F a l s e . VBA, ,
V a l u e N u m L o c k T r u e .
P ro p e rty

L e t:

N um Lock.Value = T ru e
, N u m L o c k .

Sub T o g g le ()
1
Dim As OSVERSIONINFO
. d w O S V e rs io n ln fo S iz e = L e n (o )
G e tV e rs io n E x
Dim k e y s (0 To 255) As B y te
G e tK e y b o a rd S ta te keys(O )
1
k e y b d _ e v e n t VK_NUML0CK, &H45, KEYEVENTF_EXTENDEDKEY Or 0,
'
k e y b d _ e v e n t VK_NUMLOCK, &H45, KEYEVENTF_EXTENDEDKEY Or
KEYEVENTF_KEYUP, 0
End Sub

, T o g g l e
( P r o p e r t y L e t P r o p e r t y G e t ) .
VBA N u m L o c k T o g g le :
N u m L o c k . T o g g le

N u m L o ckcia ss
N u m L o c k C l a s s
. , VBA (
), :
Dim NumLock As New Num LockClass

, N u m L o c k C l a s s (..
). , N u m
L o c k .
V a l u e N u m L o c k
T r u e . <NumLock>.
Sub NumLockOn()
Dim NumLock As New Num LockClass
NumLock. V a lu e = T ru e
End Sub

,
<NumLock> (T rue F a l s e
).
Sub G e tN u m L o c k S ta te ()
Dim NumLock As New N um LockClass

VII.

840
MsgBox N um Lock.V alue
End Sub

<NumLock>.
Sub Tog gle N um Lo ck()
Dim NumLock As New N um LockClass
Num Lock. T o g g le
End Sub

, <NumLock>
T o g g le .
Sub T og gle N um Lo ck2 ()
Dim NumLock As New N um LockClass
N um Lock.V alue = N o t N um Lock.V alue
End Sub

, NumLock ,
API-.
.
-


- k e y b o a rd c la s s e s .x ls m .

<Caps Lock> <Scroll Lock>.


,
V a lu e T o g g le .
, .
, ,
. , C l a s s l , C la s s 2
.. .


.
. ,
-:
.

VBE Auto List Members ( )


, .
.
, ,
, , . ,
, P r o p e r t y G et.
.
P r o p e r ty Get F ile N a m e O n ly () As S t r in g
F ile N a m e O n ly = " "
F o r i = L e n (F u llN a m e ) To 1 S te p -1
C har = M id (F u llN a m e , i , 1)

29.

841

If

C har = " \ " Then


E x i t F u n c tio n
E ls e
F ile N a m e O n ly = C har & F ile N a m e O n ly
End I f
N e xt i
End P r o p e r ty

, P r o p e r t y G e t .
, .
F i l e N a m e O n l y .
,
F u l l N a m e . , F u l l N a m e
:\d a ta \

m y f i l e . t x t .
, VBA .

m y f ile . t x t ,
N a m e O n ly

F ile

, ,
:

P ro p e rty

Get

P ro p e rty

Let

( ). , ,
( ) P r o p e r t y

G e t.

.
Dim X L F ile As B o o le a n
P r o p e rty G et S a v e A s E x c e lF ile () As B o o le a n
S a v e A s E x c e lF ile = X L F ile
End P r o p e r ty
P r o p e rty L e t S a v e A s E x c e lF ile ( b o o lV a l As B o o le a n )
X L F ile = b o o lV a l
End P r o p e r ty

, P r o p e r ty S e t
P r o p e r ty L e t.

, P u b l i c ,
.
P r o p e r t y G e t P r o p e r t y L e t
.
P u b lic S a v e A s E x c e lF ile As B o o le a n

, ,
P r o p e r t y L e t P r o p e r t y G e t .
X L F i l e ,
. P r o p e r t y G e t
. F i l e S y s ,
S a v e A s E x c e l F i l e :
MsgBox F ile S y s . S a v e A s E x c e lF ile
, P r o p e r t y
L e t
. ,
( ), S a v e A s E x c e l F i l e
T r u e .

VII.

842
F ile S y s . S a v e A s E x c e lF ile = T ru e

T ru e P r o p e r t y L e t,
.
X L F ile.
.
, .

.
, VBA
.
,
.


.
Sub F u n c tio n , .
, , .
:
.

VBA,
. ,
.
X L F ile. , .
Sub S a v e F ile O
I f X L F ile Then
A c tiv e W o rk b o o k . SaveAs F ile N a m e : =FName, _
F ile F o r m a t : = xlW o rkb o o kN o rm a l
E ls e
A c tiv e W o rk b o o k . SaveAs F ile N a m e : =FName, _
F ile F o r m a t : =xlCSV
End I f
End Sub

C S V F ile C la s s , ,
, .


: I n i t i a l i z e T e rm in a te .
I n i t i a l i z e , T e r
m i n a t e . I n i t i a l i z e
, .
.
P r iv a t e Sub C l a s s _ I n i t i a l i z e ()
1
End Sub
P r iv a t e Sub C la s s _ T e r m in a te ()
1
End Sub

29.

843

( ),
, , .
, N o th in g .
, MyObj e c t:
Set M yO b je ct = N o th in g

CSVFileClass
, , ,
.

CSV

F ile C la s s .

E x p o rtR a n g e .
, CSV.
Im p o rtR a n g e . ,
CSV.

I m p o r t
CSV, C S V F i l e N a m e .
, I m p o r t R a n g e .

E x p o r t ,
E x p o r t R a n g e , CSV,
C S V F i l e N a m e .


- c s v c l a s s . xlsm .


,
. C S V F i l e C l a s s
, .
.
P r iv a t e R an ge T oE xpo rt As Range
P r iv a t e Im p o r tT o C e ll As Range

R a n g e T o E x p o r t R a n g e ,
. I m p o r t T o C e l l R a n g e ,
,
CSV. P r o p e r t y G e t
P r o p e r t y L e t (. ).

844

VII.


C S V F ile C la s s .
P r o p e r t y G et ,
P r o p e r t y L e t .
P r o p e r ty Get E x p o rtR a n g e () As Range
S e t E xp o rtR a n g e = R angeT oE xport
End P r o p e r ty
P r o p e r ty L e t E x p o rtR a n g e (rn g As Range)
S e t R an ge T oE xpo rt = rn g
End P r o p e r ty
P r o p e r ty G et Im p o rtR a n g e () As Range
S e t Im p o rtR a n g e = Im p o r tT o C e ll
End P r o p e r ty
P r o p e r ty L e t Im p o rtR a n g e (rn g As Range)
S e t Im p o r tT o C e ll = rn g
End P r o p e r ty


C S V F ile C la s s ,
. .
E xp ort

E x p o r t E x p o rt.
: ,
. .
, E x p o rtR a n g e.
R an g eT o E x p o rt.
.
Sub E xp o rt(C S V F ile N a m e )
'
CSV
I f R angeT oE xport I s N o th in g Then
MsgBox " "
E x i t Sub
End I f
On E r r o r GoTo E rrH a n d le
A p p lic a tio n .S c r e e n U p d a tin g = F a ls e
S e t ExpBook = W o rk b o o k s .A d d (x lW o rk s h e e t)
R a n g e T o E x p o rt. Copy
A p p l i c a t i o n . D is p l a y A le r t s = F a ls e
W ith ExpBook
. S h e e ts ( 1 ) . P a ste
.SaveAs F ile N a m e : =CSVFileNam e/ F ile F o r m a t : =xlCSV
.C lo s e SaveC hanges: = F a ls e
End W ith
A p p lic a tio n .C u tC o p y M o d e = F a ls e
A p p lic a tio n .S c r e e n U p d a tin g = T ru e
A p p l i c a t i o n . D is p l a y A le r t s = T ru e
E x i t Sub
E r r H a n d le :
E xpB ook. C lo s e S aveC hanges: = F a ls e

29.
A p p lic a tio n .C u tC o p y M o d e = F a ls e
A p p lic a tio n .S c r e e n U p d a tin g = T ru e
A p p l i c a t i o n . D is p l a y A le r t s = T ru e
MsgBox " " & E r r & v b C rL f & v b C rL f & E r r o r ( E r r ) ,
v b C r i t i c a l , " "
End Sub

845


.
CSV, .
, . (,
), E r r H a n d l e
, .
E x p o rt

R a n g e T o E x p o rt

im p o r t

I m p o r t C S V ,
C S V F i l e N a m e . ,
I m p o r t T o C e l l .
I m p o r t R a n g e .
.
E x p o r t , I m p o r t .
Sub Im p o rt(C S V F ile N a m e )
1 CSV
I f Im p o r tT o C e ll I s N o th in g Then
MsgBox " "
E x i t Sub
End I f
If

CSVFileName = " " Then


MsgBox "He "
E x i t Sub
End I f
On E r r o r GoTo E rrH a n d le
A p p l i c a t i o n . S c re e n U p d a tin g = F a ls e
A p p l i c a t i o n . D is p l a y A le r t s = F a ls e
W o rkb o o ks. Open CSVFileName
S e t C S V F ile = A c tiv e W o rk b o o k
A c tiv e s h e e t.U s e d R a n g e . Copy D e s t in a t io n : = Im p o r tT o C e ll
C S V F ile . C lo se SaveC hanges: = F a lse
A p p l i c a t i o n . S c re e n U p d a tin g = T ru e
A p p l i c a t i o n . D is p l a y A le r t s = T ru e
E x i t Sub
E r r H a n d le :
C S V F ile . C lo se S a ve ch a n g e s: = F a ls e
A p p lic a tio n .S c r e e n U p d a tin g = T ru e
A p p l i c a t i o n . D is p l a y A le r t s = T ru e
MsgBox " " & E r r & v b C rL f & v b C rL f & E r r o r ( E r r ) ,
v b C r i t i c a l , " "
End Sub

VII.

846

CSVFileClass
C S V F ile C la s s VBA,
, C S V F ile C la ss.
.
Dim C S V F ile As New C S V F ile C la s s

,
, .
Dim S e t.
Dim C S V F ile As C S V F ile C la s s
1
S e t C S V F ile = New C S V F ile C la s s

Dim S e t ,
, S e t.
: , .
, , ,
. , S e t
.
,
, .
Auto List Members (. 29.2)
.
, .
3

<* < SfM* |*

pttovie gun Joob 4<Mlm

Window 8>

. } *

. 29.2. Auto List Members


CSV, te m p . c sv . ,
.

29.

847

Sub E x p o rtA R a n g e ()
Dim C S V F ile As New C S V F ile C la s s
W ith C S V F ile
.E x p o rtR a n g e = A c tiv e W in d o w . R a n g e S e le c tio n
.E x p o rt C SVFileN am e: = T h is W o rk b o o k . P a th & " \te m p .c s v "
End W ith
End Sub

W ith-E nd W ith . ,
.
Sub E x p o rtA R a n g e ()
Dim C S V F ile As New C S V F ile C la s s
C S V F ile . E xp o rtR a n g e = A c tiv e W in d o w .R a n g e S e le c tio n
C S V F ile . E x p o r t CSVFileNam e: = T h is W o rk b o o k . P a th & " \ te m p .c s v "
End Sub


CSV. .
Sub Im p o r tA F ile ()
Dim C S V F ile As New C S V F ile C la s s
W ith C S V F ile
On E r r o r Resume N ext
.Im p o rtR a n g e = A c t iv e C e ll
. Im p o r t CSVFileNam e: = T h is W o rk b o o k . P a th & " \te m p .c s v "
End W ith
I f E r r <> 0 Then _
MsgBox " " & _
T h is W o rk b o o k .P a th & " \te m p .c s v "
End Sub

VBA .
C S V F ile C la ss.
Sub E x p o r t 3 F ile s ()
Dim C S V F ile (1 To 3) As New C S V F ile C la s s
C S V F ile ( 1 ) .E x p o rtR a n g e = R ange( " A l:A 2 0 ")
C S V F ile ( 2 ) .E x p o rtR a n g e = R ange( "B 1 : B 20")
C S V F ile (3) .E x p o rtR a n g e = R ange( " C l : C20" )
F o r i = 1 To 3
C S V F i l e ( i ) . E x p o r t CSVFileNam e: = "" & i
N e xt i
End Sub

& ".c s v "



...

Excel 2010.


Excel 2010 .
, . ,
, . ,
, .
Excel 2007
, 56 .
, . ,
, 56 ,
.
. Excel 2007 ,
, . ,
, (16 777 216 ),
.
VBA ,
0 16777215. VBA,
- .
A c t iv e C e l l . I n t e r i o r . C o lo r = 5911168

850

VII.

VBA
. , v b R e d 2 5 5 ( ,
), v b G r e e n 6 5 2 8 0.
17 ,
, .
,
RGB.

RGB
RGB
, .
0 255.
256x256x256 = 16 777 216. 0,
. 255,
. 128 ( ),
. 16 777 213
.
RGB VBA
R G B . ,
, .
.
R G B ,
( - ,
5 9 1 1 1 6 8 ).

A c t i v e C e l l . I n t e r i o r . C o lo r = RGB(128,

50,

90)

. 30.1 RGB
.
3 0 .1 .

B la c k ()
W h ite ()
Red ()
G re e n ()
B lu e ()
Y e llo w ()
P in k ()
T u rq u o is e ()
Brown ()
in d ig o (-)
80% Gray (80% )

0
255
255
0
0
255
255
0
153
51
51

0
255
0
255
0
255
0
255
51
51
51

0
255
0
0
255
0
255
255
0
153
51

0
16777215
255
65280
16711680
65535
16711935
16776960
13209
10040115
3355443

30.

851

HSL
Excel (More Colors),
(Colors).
(Custom), ,
: RGB HSL. . 30.1
HSL.

. 30.1. HSL

HSL :
(Hue), (Saturation) (Luminance).
RGB, 0 255.
RGB HSL, HSL
. , 16 777 216
- : RGB,
HSL .
(Colors)
HSL, , ,
Excel HSL.
VBA .
RGB ( RGB).
HSL VBA .


, RGB
.
VBA RGB. , ( , g ),
, 0 0 255.

:
D e c im a lC o lo r = RGB( ,

g , b)

852

VII.


- VBA:
F u n c tio n RGB2DECIMAL(R, G, )
'
RGB
RGB2DECIMAL = RGB(R, G, )
End F u n c tio n

,
1:1.
=RGB2DECIMAL(A l , 1 , C l )

,
. ,
.
F u n c tio n DECIM AL2RGB(ColorVal) As V a r ia n t
'
RGB
1 3 - V a r ia n t
DECIMAL2RGB = A r r a y ( C o lo r V a l \ 256 0 And 255,
C o lo rV a l \ 256 1 And 255, C o lo rV a l \ 256 2 And 255)
End F u n c tio n

D E C I M A L 2 R G B
, . ,
, 1 .
RGB
, , .
<Ctrl+Shift+Enter> ,
.
{ =DECIMAL2RGB(A l ) }

, ,
, .
{=TRANSPOSE(DECIMAL2RGB(Al)) }

. 30.2 DECIMAL2RGB.
-

- c o lo r c o n v e rs io n f u n c t io n s ,
x ls m ,
: DECIMAL2RGB, DECIMAL2HSL, HSL2RGB, RGB2DECIMAL, RGB2HSL
HSL2DECIMAL.

,
16 777 216 . ,
16777216 , ?
,
, F o r-N e x t.
Sub G e n e ra te C o lo r V a lu e s ()
Dim Red As Long, B lu e As Long, Green As Long
Dim A l l C o l o r s (0 To 16777215) As Long
Dim ColorNum As Long

30.

853

ColorNum = 0
F o r B lu e = 0 255
F o r G reen = 0 2 55 F o r Red = 0 255
F o r Red = 0 To 255F or Red = 0 To 255
A llC o lo rs ( C o lo r N u m ) = RGB(Red, B lu e , G reen)
ColorN um = ColorNum + 1
N e x t Red
N e x t Green
N e xt B lu e
End Sub

A l l c o l
o rs , Excel.

.

2

--RGB
R

J L

<3
0

jj *

--HSL
S

167772

92

143

58

248

72

335 544

184

30

242

94

503 316

20

174

82

235

90

671088

112

61

10

21

213

61

838 860

204

204

12

42

227

108

1006632

40

92

15

71

184

54

10

1174404

132

235

17

63

221

126

11

1342 176

224

122

20

21

213

122

12

1509 948

60

10

23

244

182

35

13

1677720

152

153

25

43

183

89

14

1845 492

244

40

28

231

136

15

2013 264

80

184

30

71

184

107

16

2181036

172

71

33

12

173

102

17

2348 808

215

35

91

237

112

18

2516580

100

102

38

44

117

70

19

2684 352

192

245

40

53

232

142

20

2 852124

28

133

43

91

166

80

21

3 019 896

120

20

46

244

182

70

22

3187668

212

163

4S

30

167

130

48

51

51

128

50

2L
4

3355 440
?CT1.J............

_____ :... J L

..J ___

. 30.2.

D E C IM A L2 R G B

D E C IM A L 2 H S L


,
.
, ,
, (,
8% ).
- ^
.
, ,
. . ,
.

854

VII.

, .
RGB (0, 0, 0 ),
RGB (255, 255, 2 5 5 ), - RGB(128, 128, 12 8 ).
256 .
, 256 ,
.
( ) ,
1 256. .
Sub G e n e ra te G ra y S c a le ()
Dim As Long
F o r r = 0 To 255
C e l l s ( r + 1, 1 ) . I n t e r i o r . C o lo r = RGB(r , r ,
N e xt r
End Sub

r)

. 30.3 .


,
,
. ,
-. ,
, .
,
RGB :

28,7% ;

58,9% ;

11,4% .

1 6 7 5 1 0 0 1 (

), R G B ( 1 5 3 ,

153,

: 28,7%. 153 = 44;

: 58,9%. 153 = 90;

2 5 5 ) .

RGB:

: 11,4%.255 = 29.
163. , RGB ,
16751001, R G B (163, 163, 1 63).
VBA,
.
.
F u n c tio n G r a y s c a le ( c o lo r )
Dim r As Long, g As Long, b As Long
r = ( c o lo r \ 256 A 0 And 255) * 0 .2 8 7
g = ( c o lo r \ 256 * 1 And 255) * 0 .5 8 9
b = ( c o lo r \ 256 A 2 And 255) * 0 .1 1 4
G ra y s c a le = RGB(r + g + b , r + g + b , r + g + b)
End F u n c tio n

30.

855

. 30.3. 256


, Excel
. -
, .
(Sheet)
(Page Setup).
, (Page Setup)
(Page Layout).
(Black And White), -
( ). , -
. :
. - .
,
.
1. .
2. <Ctrl+C> .
3. ^ ^^
(Home^Clipboard1^ Pasted Picture).
4. ^
^ (Picture Tools^Format^AdjustMColor),
(Recolor)
(Grayscale) (. 30.4).

VII.

856


08

1
2
3

4
5
6
7

S
9
10
11

12
13

^
^
...

14
15
16
17

. 30.4.

,
. S h o w C h a rtA sG ra y S c a le
, .
, .
Sub S h o w C h a rtA s G ra y S c a le ()
'
;
'

I f A c t iv e C h a r t I s N o th in g Then
MsgBox " ."
E x i t Sub
End I f
A c t iv e C h a r t . P a r e n t. C o p y P ic tu re
A c t iv e C h a r t . P a r e n t. T o p L e f t C e ll. S e le c t
A c t iv e S h e e t. P i c t u r e s . P a ste
A c t iv e S h e e t. P ic t u r e s ( A c t iv e S h e e t . P i c t u r e s . C o u n t) . _
ShapeRange. P ic tu r e F o r m a t. C o lo rT y p e = m s o P ic tu re G ra y s c a le
End Sub
-

, ,
- c h a r t t o g r a y
s c a le p ic t u r e .x ls m .

He .+

.

30.

857


. 30.5 ,
. ,
RGB, ,
.

1
2

Excel

3
4
5

6
7
8
9

10
11
12
13
14
15

17
18
19
/A J

21

22
23
25
26
27
28
29

. 30.5.
,
-


- RGB c o lo r demo. xlsm .

,
.
, 0 255.
.

, , *
(00-FF) (0-255).
RGB
HTML-.

VII.

858

, ,
(
). .

, ,
, RGB.

,
.

HSL.


Excel 2007 , .

. : ,
( ).
, , .
, ,
.


Microsoft Office 2010 40 .
.
. ( (Chart
Styles).) , , ,
. ,
, ,
.
-

,
- docum ent theme demo.
x ls x . , ,
, ( ),
. ^^
(Page LayoutMThemes^Themes Gallery)
.

. ,
,
. .
.

30.

859

,
,
.
, ,
.
,
.


,
,
(. 30.6).
60 (10 6 ), 10
. (More Colors)
(Color), 16777216 .
2 - Microsoft Excel

Calibri

411

- - ' *

- %

iM P V-

**
||


tj

"|< < ..N

Z -

*
|

^, , S0% ]

...

! , 2 , ^ 3

100%

.iSLfj

. 30.6.

60 . , ,
, 2,
20%. . 30.2 60 .
(Tint), (Shade).

3 0 .2 .
/

10

1
2

5%

15%

25%

35%

50%

50%

35%

25%

15%

5%

10%

25%

50%

75%

90%

80%

80%

80%

25%

50%

80%

60%

40%

25%

50%

80%

60%

40%

25%

50%

80%

60%

40%

25%

50%

80%

60%

40%

25%

50%

80%

60%

40%

25%

50%

80%
*

60%

40%

25%

50%

30.

861

: ,
.
( / ).
.

^^^
(Page Layout^Themes^Colors^Create New Theme Colors),
: (Hyperlink)
(Followed Hyperlink).
.

,
.
, .
2, 25%, 2,
80%.
Sub C h a n g e C o lo rs ()
W ith S e l e c t i o n . I n t e r i o r
.P a tte r n = x lS o lid
. P a tte r n C o lo r ln d e x = x lA u to m a tic
.T h em eC o lo r = x lT h e m e C o lo rA c c e n t2
. T in tA n d S h a d e = -0.2 49 9 77 11 11 17 89 3
. P a tte rn T in tA n d S h a d e = 0
End W ith
W ith S e l e c t i o n . F o n t
.T h em eC o lo r = x lT h e m e C o lo rL ig h t2
.T in tA n d S h a d e = 0.799981688894314
End W ith
End Sub

,
( P a t t e r n , P a t t e r n C o l o r l n d e x P a t t e r n T in t A n d S h a d e ) .

, ( -
). (Fill)
(Format Cells).
, .
( ) .
Sub C h a n g e C o lo rs ()
W ith S e l e c t i o n . I n t e r i o r
1
( 2, 25%)
.T hem eC olor = x lT h e m e C o lo rA c c e n t2
.T in tA n d S h a d e = -0 .2 49 9 77 11 11 17 89 3
End W ith
W ith S e le c t io n . F o n t
'
( 2, 80%)
.T hem eC olor = x lT h e m e C o lo rL ig h t2
.T in tA n d S h a d e = 0.799981688894314
End W ith
End Sub

, T h e m e C o lo r T i n
tA n d S h a d e . T h e m e C o lo r :

862

VII.

. T in tA n d S h a d e
. .
T in tA n d S h a d e -1 +1. -1
, +1 . T in tA n d S h a d e
0, ( ) ,
T in tA n d S h a d e
. T in tA n d S h a d e
. T in t A n d
Shade, , . 30.2.
(Tint),
T in tA n d S h a d e .
(Shade), T i n
tA n d S h a d e .

, T in tA n d S h a d e
. ,
T in tA n d S h a d e , -0 .2 4 9 9 7 7 1 1 1 1 1 7 8 9 3 -0 .2 5 ,
.
-

T in tA n d
Shade tin ta n d s h a d e demo. xlsm ,
- (. 30.7). ,
50 T in tA n d
Shade, -1 +1.
, ( ).

RGB TintAndShede

* J f

/ / / /

S J jr J

/ / / /

. 30.7. , TintAndShade

30.

863


, 60
.
Sub S how Them eC olors()
Dim r As Long, As Long
F o r r = 1 To 6
F o r = 1 To 10
W ith C e l l s ( r , c ) . I n t e r i o r
.T h em eC o lo r =
S e le c t Case
Case 1 ' / 1
S e le c t Case
. T in tA n d S h a d e = 0
Case 1
. T in tA n d S h a d e = - 0 .0 5
Case 2
Case 3 . T in tA n d S h a d e = - 0 .1 5
Case 4
.T in tA n d S h a d e = - 0 .2 5
Case 5 . T in tA n d S h a d e = -0 .3 5
Case 6 . T in tA n d S h a d e = - 0 .5
End S e le c t
Case 2 ' / 2
S e le c t Case r
Case 1: .T in tA n d S h a d e = 0
Case 2: . T in tA n d S h a d e = 0 .5
Case 3: .T in tA n d S h a d e = 0 .3 5
Case 4 : .T in tA n d S h a d e = 0 .2 5
Case 5: .T in tA n d S h a d e = 0 .1 5
Case 6 : .T in tA n d S h a d e = 0 .0 5
End S e le c t
Case 3 ' / 3
S e le c t Case r
Case 1: .T in tA n d S h a d e = 0
Case 2 : .T in tA n d S h a d e = - 0 .1
Case 3 : .T in tA n d S h a d e = -0 .2 5
Case 4 : .T in tA n d S h a d e = - 0 .5
Case 5 : .T in tA n d S h a d e = - 0 .7 5
Case 6 : .T in tA n d S h a d e = - 0 .9
End S e le c t
Case E ls e 1 / 4 1-6
S e le c t Case r
Case 1
. T in tA n d S h a d e = 0
Case 2
.T in tA n d S h a d e = 0. 8
Case 3
.T in tA n d S h a d e = 0. 6
Case 4
.T in tA n d S h a d e = 0 .4
Case 5
.T in tA n d S h a d e = -0 .2 5
Case 6
. T in tA n d S h a d e = - 0 .5
End S e le c t
End S e le c t
C e l l s ( r , c) = .T in tA n d S h a d e
End W ith
N ext
N e xt r
End Sub

. 30.8 Show Them eC olors (


). ,
.

864

VII.

| < : 11 ,

. 30.8. VBA
-


- g e n e ra te theme c o lo r s . xlsm .


C o l o r I n t e r i o r . ,
V B A RGB .
(
).
R ange( " A l : F 2 4 ") . I n t e r i o r . C o lo r = 5913728
R a n g e ( " A 1 : F 2 4 " ) . I n t e r io r . C o lo r = RGB(128/ 60,

90)

, ,
. ,
, A1:F24 .
, , T he m e
C o lo r () T in tA n d S h a d e .


.
S h ap e , .
Excel ^1^
(Insert^Illustrations^Shapes).
. 30.9 Shape, .
1 (Right Arrow 1).
( , ).
, ( ),
3.

30.

865

. 30.9. shape


S h a p e R G B .
, ,
:

MsgBox A c t iv e S h e e t . S h ap e s( " 1 " ) . F i l l . F o r e C o lo r . RGB

,
. F i l l S h a p e F i l l F o r m a t .
F o r e C o l o r F i l l F o r m a t C o l o r F o r m a t . ,
R G B C o l o r F o r m a t ,
.

F o re C o lo r?
VBA, ,
B a c k C o lo r.
, B a c k C o lo r .
shape , F o re C o lo r
.

S h a p e
. .
S h p .
Dim Shp As Shape
Set Shp = A c t iv e S h e e t . S h a p e s ( " 1 ")
MsgBox S h p . F i l l . F o r e C o lo r . RGB


VBE Auto List Members (
).
(. 30.10).
shape,
Excel.
28 . 3107

VII.

866

Sub ModifyShape()
Dim Shp As Shape
Set Shp = Activesheet.Shapes(" 1)
GracbentAngle
ef
ef
ef
ef
gf*

GracfientColorType
GradtentDegree
Gra<fcentStops
GradientStyle
GradientVariant

. 30.10. Auto List Members

,
C o lo rF o rm a t, .
Dim ShpCF As C o lo rF o rm a t
S e t ShpCF = A c t iv e s h e e t . S h a p e s( " 1 " ) . F i l l . F o re C o lo r
MsgBox ShpCF.RGB

RGB C o lo rF o rm a t .
. ,
.

O b je c tT h e m e C o lo r. 1 10,
( 10x6).

S chem eC olor. , 0 80,


.
56- ,
.

TintA ndShade. -1 +1, .

. , C o lo rF o rm a t. ,
, , 1
RGB.
.
C o lo rF o rm a t,
L in e F orm at.
Shape.

30.

867

Dim Shp As Shape


Set Shp = A c t iv e S h e e t. S h a p e s( " 1 ")
S h p .F ill.F o r e C o lo r .R G B = RGB(255/ 0, 0)
Shp. L in e . F o r e C o lo r . RGB = RGB(255, 0, 0)

,
.
Dim Shp As Shape
Dim F illC F As C o lo rF o rm a t
Dim LineC F As C o lo rF o rm a t
Set Shp = A c t iv e S h e e t . S h ap e s( " 1 ")
Set F illC F = S h p . F ill. F o r e C o lo r
S et LineC F = S h p . L in e . F o re C o lo r
F illC F .R G B = RGB(255, 0, 0)
LineCF.RGB = RGB(255, 0, 0)

, ,
. , ,
S ch em eC o lo r () T in tA n d S h ad e.


O b je c tT h e m eC o lo r T in tA n d S h a d e F o r e c o lo r .
4, 40%.
W ith A c t iv e S h e e t . S h ap e s( 1 ) . F i l l . F o re C o lo r
. O b je c tT h e m e C o lo r = m soThem eC olorA ccent4
. T in tA n d S h a d e = 0 .4
End W ith

, ,
(Fill Color), .
, Microsoft
. , .
. 30.11 B2:D8, 2,
80%. ,
, .
. ,
. .
Sub C o lo rS h a p e ()
W ith A c t iv e S h e e t. S h a p e s ( 1 ) . F i l l . F o re C o lo r
.O b je c tT h e m e C o lo r = R ange( "B 2 : D8 " ) . I n t e r i o r . Them eC olor
. T in tA n d S h a d e = R an ge ( "B 2 : D8 " ) . I n t e r i o r . T in tA n d S h a d e
End W ith
End Sub

. 30.12 C o lo rS h a p e .
, .
2, 80%
(Fill Color),
.

868

VII.

. 30.11. ,

/ ^ 7 7 7 ~

. 30.12. .

30.

869

,
. I n
t e r i o r .
.
.
.
A c t iv e S h e e t. S h a p e s ( 1 ) . F i l l . F o r e C o lo r . RGB = _
R ange( "B 1 : D8 " ) . I n t e r i o r . C o lo r

Excel 15 12
;

T h e m e C o l o r ( )
O b j e c t T h e m e C o l o r ;

T i n t A n d S h a d e F i l l F o r m a t 0,
.
, , , ( ),
, .
,
.


,
, . . 30.13
, S h a p e .

Microsoft
Excel

. 30.13. , VBA
-

, ,
- shape o b je c t c o lo r s , xlsm .

VII.

870


.
, .
, ,
.
. 30.14 1.
, .

. 30.14.

VBA, .
A c t iv e s h e e t . C h a r t O b je c ts ( " 1 " ) . C h a rt. _
S e r ie s C o l l e c t i o n ( 1 ) . F o rm a t. F i l l . F o r e C o lo r . RGB = vbRed

,
. .
C h a r t O b j e c t s .
C h a r t O b j e c t 1. C h a r t
C h a r t O b j e c t C h a r t . C h a r t S e r i
e s C o l l e c t i o n , S e r ie s 1.
F o rm a t S e r ie s C h a r t F o rm a t. F i l l
C h a r t F o r m a t F i l l F o rm a t. F o r e C o lo r F i l l F o r m a t C o lo r F o r m a t . RGB C o lo r F o r m a t
.

18
VBA.


( ).
Sub C h a n g e S e rie s lC o lo r
Dim M y C h a rtO b je c t As C h a rtO b je c t
Dim M yC hart As C h a rt
Dim M y S e rie s As S e r ie s
Dim M yC h artF o rm at As C h a rtF o rm a t
Dim M y F illF o r m a t As F illF o r m a t
Dim M y C o lo rF o rm a t As C o lo rF o rm a t
'

30.

871

S e t M y C h a rtO b je c t = A c t iv e S h e e t. C h a r t O b je c ts ( " 1 ")


S e t M yC hart = M y C h a rtO b je c t. C h a rt
S e t M y S e rie s = M y C h a rt. S e r ie s C o l l e c t i o n (1)
S e t M yC h artF o rm at = M y S e rie s . Form at
S e t M y F i11F orm at = M y C h a rtF o rm a t. F i l l
S e t M yC o lo rF o rm a t = M y F illF o r m a t. F o re C o lo r
1
M y C o lo rF o rm a t. RGB = vbRed
End Sub

RGB ,
VBA.
C o lo rF o rm a t.

Obj e c tT h e m e C o lo r. 0 16, .
VBA . , m soThem eC o lo rA c c e n t3 7.

T in tA n d S h a d e . -1 +1,
.
, -
, .
, .
-

-
c h a r t c o lo r s . xlsm .

. ,
.
, F i l l F orm at.
Sub A d d P r e s e tG r a d ie n t()
Dim M yC hart As C h a rt
S e t M yC hart = A c t iv e S h e e t. C h a r t O b je c ts ( " 1 " ) . C h a rt
W ith .M yC h a rt. S e r ie s C o l l e c t i o n ( 1 ) . F o r m a t . F il l
. P r e s e tG r a d ie n t _
S t y l e : = m s o G ra d ie n tH o riz o n ta l, _
V a r ia n t : = 1 , _
P r e s e tG ra d ie n tT y p e : = m s o G ra d ie n tF ire
End W ith
End Sub

.
, ,
.
Sub R e c o lo r C h a rtA n d P lo tA r e a ()
Dim M yC hart As C h a rt
S e t M yC hart = A c t iv e S h e e t. C h a r t O b je c ts ( " 1 " ) . C h a rt
W ith M yC hart
. C h a rtA r e a . F o rm a t. F i l l . F o r e C o lo r . O b je c tT h e m e C o lo r = _
m soT hem eC olorA ccent 6
. C h a rtA r e a . F o rm a t. F i l l . F o r e C o lo r . T in tA n d S h a d e = 0 .9
. P lo t A r e a . F o rm a t. F i l l . F o re C o lo r.O b je c tT h e m e C o lo r = _
m soT hem eC olorA ccent 6
. P lo t A r e a . F o rm a t. F i l l . F o r e C o lo r . T in tA n d S h a d e = 0 .5

872

VII.

End W ith
End Sub


. ,
,
. U seR a nd om C o lo r s R a n d o m C o lo r.
Sub U seR andom C olors()
Dim M yC hart As C h a rt
S e t M yC hart = A c t iv e S h e e t. C h a r t O b je c ts ( " 4 " ) . C h a rt
W ith M yC hart
. C h a rtA r e a . F o rm a t. F i l l . F o r e C o lo r . RGB = R andom Color
. P lo t A r e a . F o rm a t. F i l l . F o r e C o lo r . RGB = R andom Color
. S e r ie s C o l l e c t i o n ( 1 ) . F o rm a t. F i l l . F o r e C o lo r . RGB = _
R andom Color
. S e r ie s C o l l e c t i o n ( 2 ) . F o rm a t. F i l l . F o r e C o lo r . RGB = _
R andom Color
. L e g e n d . F o n t . C o lo r = Random Color
. C h a r t T i t l e . F o n t. C o lo r = Random Color
. A x e s ( x lV a lu e ) . M a jo r G r id lin e s . B o r d e r . C o lo r = R andom Color
. A x e s ( x lV a lu e ) . T ic k L a b e ls . F o n t. C o lo r = R andom Color
. A x e s ( x lV a lu e ) . B o r d e r . C o lo r = R andom Color
. A x e s ( x lC a t e g o r y ) . T ic k L a b e ls . F o n t . C o lo r = R andom Color
. A x e s ( x lC a te g o r y ) . B o r d e r . C o lo r = R andom Color
End W ith
End Sub
F u n c tio n R an do m C o lor()
R andom Color = A p p l i c a t i o n . R andB etw een(0, RGB(255, 255, 2 5 5 ))
End F u n c tio n


Excel
...


Excel
Visual Basic.

, ,

,
Excel.


, , , FAQ (Fre
quently Asked Questions). ( ),
. ,
.
,
.

874

VII.


VBA, ,
Excel:

Excel, ;

Excel;

VBE.
,

.
.
:

Excel;

Visual Basic;
;
;
, , ;
;
;
Excel.
,
.
, .
, , ,
.
,

. ,
.
, ,
.

Excel

Excel.
?
.
?
1^ ^ (View^Macros1^
Macros) <Alt+F8>.
^ (Developer^Code^Macros).

31. Excel

875

, ?

(Customize the Ribbon). (Custo
mize Ribbon) Excel (Excel Options)
(Developer) ( (Main tabs)).
.
. ?
Excel
.
Excel (Yes).
, XLSM, XLSX.
?
Excel 2010 (Minimize the Ribbon),
(Help) .
, / .
<Ctrl+Fl>. /
VBA, S en d k ey s.
Sub T o g g le R ib b o n ()
A p p l i c a t i o n . SendKeys " ^ { F l } "
End Sub

XLM-:
E x e c u te E x c e l4 M a c ro "SHOW. TOOLBAR( " " R ib b o n " " , F a ls e ) "

,
,
T rue.
?
(Add-Ins),
(Custom Toolbars).
?
, .
(Custom
Toolbars), (Add-Ins).
Excel 2010?
VBA:
A p p l i c a t i o n . D is p la y S ta tu s B a r = F a ls e

, Excel
?
.

876

VII.

<Ctrl+A> ?
.
, <Ctrl+A>
.
, ,
.
?
, .
, 1^ 1^
(Views^Workbook Views^Custom Views).
,
?
.
.
. ( ), ,
1^ ^ (Data^Data Tools'^
Data Validation), (Settings)
(Data Validation).
(Allow) (List). (Source)
, .
,
(In-Cell Dropdown) . ,
, .
,
?
. Excel (,
L i s t E n t r i e s ) . Excel 2010
, .
A p p l i c a t i o n . C a l c u l a t i o n
?
C a l c u l a t i o n A p p l i c a t i o n .
.
. Excel 2000
W o r k s h e e t E n a b l e C a l c u l a t i o n .
F a ls e , ,
.
E n a b l e C a l c u l a t i o n T ru e .
<F4>
?
. , ( )
<F4> Excel 2007 . ,
(Insert Worksheet) <F4>, Excel

31. Excel

877

(Insert Worksheet).
<Shift+Fl 1>, <F4> .
.
1^ ^ (Chart Tools^Design^Chart Styles),
, <F4>.
, Excel.
?

.
Excel (Excel Options).
(Commands Not in the Ribbon). .
, 65546 . ?
Excel 2010 1048576 16384 .
, ,
. Excel ,
,
Excel 2010. .
Excel 2010, .
.
?
Excel 2007 ,
, .
, <Ctrl+N>.
, ().
(Styles),
(Merge Styles). (Merge Styles)
,
<Ctrl+N>. .
,
. , , ,
.
?
Excel 2010
^ (File =>Print).
(Page Layout),
.

VBA.
:
A c t iv e S h e e t. P r in t P r e v ie w


,
. ^1^

878

VII.

(Page Layout^Themes^Fonts), ,
.
(Normal). , ,
.
,
(Normal)?
Excel (Excel Options),
(Advanced),
(Display Options for This Worksheet)
(Show Page Breaks).

?
.
.
VBA:
A c t iv e s h e e t . D is p la y P a g e B re a k s = F a ls e

,
. ?
, .
(No Fill),
(Automatic). .
?

(Tab Color). ,
.
VBA ?
, WAV MIDI,
Windows API (. 11).
S peech.
:
A p p lic a tio n .S p e e c h .S p e a k

(" " & A p p lic a tio n .U s e rN a m e )

Excel .
. ?
, .
(Edit Links) ( ^1^
(File^Info^Edit Links to Files)).
(Edit Links) (Break
Link). , .
, ,
, (SERIES), .
, .

31. Excel

879

,
.
Excel 5/95,
, .
, .
^ ^ (Formulas1^
Defined Name^Name Manager).
(Refers ). ,
(, #!).
.
Excel ?
Excel * . x lb ,
. ,
Excel. .
Excel. * . x l b
100 .
Excel ,
* .x l b . Excel * .x lb . (
.) ,
Excel. Excel
, * . x lb .
* . x l b
, (Add-Ins).
VBA?
VBA.
-, :
h t t p : //s p r e a d s h e e tp a g e . com
Google:
h t t p : / /g o o g l e . com

Visual Basic
VBA ?
. . ,
, ,
.
, .
, .
?
. ()
, Excel .
.
P e r s o n a l . x l s b \ X L S t a r t .

880

VII.

. ?
P e r s o n a l . x l s b ,
.
VBA .
?
,
.
. Excel.
, Excel ,
.
, ?
. VBA
. ,
.
O p tio n E x p l i c i t .
?
O p tio n E x p l i c i t , ,
,
( ). ,
, VBE Tools^Options (11^).
Editor () Require Variable
Declaration ( ).
VB.
VBA ? ?
VBA : ,
, , ..
, , ,
, .. Tools^Options (
Editor Format ( )) VBE.
VBA VBA?
. M o d u lel .
W ith A c tiv e W o rk b o o k . V B P ro je c t
. VBComponent s . Remove . VBComponent s ( " M o d u le 1 ")
End W ith

Excel. . .
, VBA VB.
Excel . ?
Excel 2002 :
VBA. .
^ ^ (File^Excel
Options^Trust Center).
(Trust Center Settings)

31. Excel

881

(Trust Center). (Macro


Settings) VBA
(Trust Access to the VBA Project Object Model).
?
,
?
VBA
. .
X J a e r ln te r fa c e O n ly ?
VBA
:
A c tiv e S h e e t. P r o t e c t U s e r ln t e r f a c e O n ly : =True

,
. ,
.
U s e r l n t e r f aceO n ly .
, ?
VBE , .
VBA, .

.
.
&
, VBA .
, .
VBA ()
:
.
Excel .
VBA . ?
, Break on All
Errors ( ).
Options () General () VBE. ,
VBA.

VBA ?
. .
.

29 . 3107

882

VII.

?
VB, .
(, ) ,
, F u n c t io n .
Sub.
?
, ,
( V a r i a n t ) . VBA
.
, ,
. .
D im , P u b l i c P r i v a t e .
.
?
:
( ).
, , .
Dim X As V a r ia n t
X = A r r a y (30, 40,

50)

, ( ).
, 3- .
Dim X (0 2) As V a r ia n t

,
V a r i a n t , ,
.
?
VBA ,
. , M y V a r,
(integer). %:
Dim M yVar%

, VBA:

I n t e g e r %;

L o n g &;

S i n g l e !;

D o u b le #;

C u rre n c y

S t r i n g $.

.
.

31. Excel

883

, ,
. , , 0,
. ?
, .
Excel (Conditional Formatting),
(Conditional For
matting), (Styles) ().
,

C h a n g e .
- , C h a n g e .
S h e e t () W o r k s h e e t _ C h a n g e ,
C h a n g e .
?
!
.
(Sub W orkbookO pen),
. ?
, , .
T h i s W o r k b o o k
().
S h e e t (), Project VBE.
, Excel
.
(Trust Center).
Excel (Excel Options).
.
?
, .
19.
VBA ,
Excel?
. , VBA ,
. .


True,
True F a lse
(.,
)


True , True

Eqv
Imp
Is
Like
Xor

884

VII.

, ?
Run A p p l i c a t i o n .
M a c r o l,
P e r s o n a l . x l s b .
Run " P e r s o n a l. x ls b ! M a c ro l"

, .
Tools'^R eferences ( ^) VBA.
, ,
.
VBA
,
. ?
. , ,
Excel (XLAM).
, .
, ,
,
. ,
Tools1^ References (^) VBE.
, ,
Excel? , Excel

? ,
\ X L S t a r t . ,
W o rk b o o k _ O p e n T h is W o r k b o o k ().
, W orkbook_Open.

?
. <Shift> ^ (File^Open).
W o rk book_B eforeC lose,
<Shift> . <Shift>
.
VBA
?
VBA ,
XLM. , XLM VBA.
1 1 myf i l e . x l s x ,
: \ f i l e s .
MsgBox E x e c u te E x c e l4 M a c ro ( " ' : \ f i l e s \ [ m y f i l e . x l s x ] JIh c t I ' !R 1 C 1 ")

, R1C1.

31. Excel

885


VBA?
:
A c tiv e W o rk b o o k . C lo se SaveC hanges: = F a ls e

S a v e d W o rk b o o k
T ru e . :
A c tiv e W o rk b o o k . Saved = T ru e

,
.
Excel
:
A p p l i c a t i o n . D is p l a y A le r t s

= F a ls e

D i s p l a y A l e r t s T ru e .
, ?
O nT im e A p p l i c a t i o n .
,
. ,
O n T im e , .
, ?
(Macro)
( ^ ^ (View1^
Macros1^ Macro)) P r i v a t e .
P r iv a t e Sub M yM acro()

.
Sub MyMacro

( O p tio n a l FakeArg as Long)

GIF?
.
1 GIF M y c h a r t . g i f .
S et C u r r e n tC h a rt = S h e e ts ( " 1 ") . C h a r t O b je c ts ( 1 ) . C h a rt
Fname = T h is W o rk b o o k . P a th & " \ M y c h a r t . g i f "
C u r r e n tC h a r t. E x p o rt F ile n a m e := Fname, F ilte r N a m e : = "G IF "

VBA VBA?
?
.
: , ().
.
,
. ,
.
, .

P u b l i c .

VII.

886

VBA .
#?. ?
, , (,
1 ) T h is W o r k b o o k ().
VB .
VBA, ,
. ?
VBA, ,
. . ,
, ,
.
.
.

. ?
, ,
. 1^1^ (View1^
Macros1^ Macros) (Macro).
, (Macro Name).
(Options)
(Macro Options). (Description)
.

?
. Excel 2010 M acroO ptions,
. ,
. 10.

. ?
VBA.
MyFunc 1 ( (Financial)):
A p p l i c a t i o n . M a c ro O p tio n s M a c ro : = "M yFunc" ,

C a te g o ry := 1

0
1
2
3
4

( )

31. Excel

887

5
6
7
8
9
10
11
12
13
14
15

( )
( )
( )
DDE/ ( )
( )

?

.

C a te g o ry

M a c r o O p t io n s .

A p p lic a tio n .M a c r o O p tio n s M a c ro : = "M yFunc" , _


C a te g o r y : = " XYZ"

,
. ,
(#1)?
M y F u n c t i o n ,
, :

M y F u n c tio n = C V E r r ( x lE r r V a lu e )

x l E r r V a l u e .
.
VBA Windows API,
. ,
. ?
, ,
64- Excel 2010.
API- PtrSafe.
API-, 32- Excel,
64- Excel 2010, .
D e c la re F u n c tio n G e tW in d o w s D ire c to ry A L ib
(B yV al lp B u f f e r As S t r i n g ,

" k e r n e l3 2 " _

B yV al n S iz e As Long) As Long

64-
Excel PtrSafe D e c l a r e .
API-,
.
, 32-, 64- Excel 2010.

888

VII.

D e c la re P trS a fe F u n c tio n G e tW in d o w s D ire c to ry A L ib " k e r n e l3 2 " _


(B yV al l p B u f f e r As S t r i n g , B yV al n S iz e As Long) As Long

VBA Excel 2007 ( )


, P t r S a f e .
API-, 32- Excel ( , Excel 2010) 64-
Excel 2010.
# I f VBA7 And Win64 Then
D e c la re P trS a fe F u n c tio n G e tW in d o w s D ire c to ry A L ib " k e r n e l3 2 " _
(B yV al l p B u f f e r As S t r i n g , B yV al n S iz e As Long) As Long
# E ls e
D e c la re F u n c tio n G e tW in d o w s D ire c to ry A L ib " k e r n e l3 2 " _
(B yV al lp B u f f e r As S t r i n g , B yV al n S iz e As Long) As Long
#End I f

D e c la r e , VBA7
W in d 6 4 T r u e ( 16- Excel 2010).
Excel D e c la r e .
, ?
<Ctrl+Alt+F9>.
Excel VBA?
. Excel
W o r k s h e e t F u n c t io n A p p l i c a t i o n . ,
SUM () , :
Ans = A p p l i c a t i o n . W o rk s h e e tF u n c tio n . Sum (Range ( 11A l : A3 ") )

1: (
), Ans.
VBA ,
. , VBA
(S q r), SQRT VBA .
?

. ,
, . v b N e w L in e
.
MsgBox " " & vbN ew Line & A p p l i c a t i o n . UserName

, ,
Excel, ?
. .
.
, ?
.
Object Browser, VBE.

31. Excel

889

<F2> Object Browser Excel


Libraries/Workbooks ( ). Classes () ()
Excel.
Members ().
,
. , :
Range ( " A l " ) .


R ange. , Tools^Options (1^

), Editor () Auto List


Members ( ). ,
. ,
:
A c t iv e s h e e t . S h a p e s ( 1 ) .

VBA ,
Visual Basic Editor.
, .

(Immediate) VBE
<F1>.
, .
? ?
?
, .
. ,
W o r k s h e e t s , W o r k s h e e t
. : W o r k s h e e ts (1 )
W o r k s h e e t W o rk b o o k s .
, W o r k s h e e ts ( " J I h c t I ).
.
F o r E a c h - N e x t.
VBA ,
subscript out o f range. . ?

. , ,
, M y S h e e t.
S et X = A c tiv e W o rk b o o k .W o rk s h e e ts ( "M yS h e e t")

?
,
VBA .
1 ,
B2:D50.
W o rk s h e e ts ( " ! " ) . S c r o llA r e a = "B 2:D 5 0"

VII.

890

,
:
W o rk s h e e ts ( " 1 " ) . S c r o llA r e a = " "

, S c r o ll A r e a
. ,
.
W orkbook_Open.
S e l e c t A p l l i c a t i o n . Goto?
S e l e c t R a n g e
. A p p l i c a t i o n . G o t o
. A p p l i c a t i o n . G o t o ,
. , G o t o
, .
?
A c t i v a t e S e l e c t
. - . ,
1:. .
, , ..
.
R ange( " " ) . A c t iv a t e

, 1: .
, .
R ange( " " ) .S e le c t


?
.
, ( ).
On E r r o r Resume N e xt
C e l l s . S p e c ia lC e lls ( x lC e llT y p e C o n s t a n t s , 2 3 ) .C le a rC o n te n ts

, 23, ,
: x l E r r o r s (16), x l L o g i c a l (4), x lN u m b e r s (1)
x l T e x t V a l u e s (2).
On E r r o r R esu m e N e x t
, ,
.
, VBA, ,
. , ,
?
C e l l s .
(.. L5):
C e lls (5,

12) .S e le c t

31. Excel

891

, Excel ^ Excel
(File>Exit Excel), Excel , .
VBA Excel?
Excel :
A p p l i c a t i o n . Q u it

?

, .
A p p l i c a t i o n . S c re e n U p d a tin g = F a ls e

S c r e e n U p d a t i n g
T r u e .
:
A p p l i c a t i o n . S c re e n U p d a tin g = F a ls e

VBA?
,
.
R a n g e ("D 1 4 :G 2 0 " ).S e le c t
A c tive W o rkb o o k.N a m e s.A d d Name: = " In p u t A r e a " , _
R e fe r s T o R lC l: = " = 1 ! R14C4: R2 0C7"

:
S h e e ts ( " 1 " ) . R ange( "D 1 4 : G20" ) . Name = " In p u tA r e a "

, ?
N a m e N a m e ,
R a n g e .
, . ,
F a l s e .
F u n c tio n RangeNam e(rng) As V a r ia n t
On E r r o r Resume N e x t
RangeName = r n g . Name. Name
I f E r r <> 0 Then RangeName = F a ls e
End F u n c tio n

, Excel 2010
.
Backstage ( ^),


VBA:
A c t iv e S h e e t. P r in t P r e v ie w

892

VII.

S t a t u s B a r A p p l i
c a t i o n . .
A p p l i c a t i o n . S ta tu s B a r = " " & F ile N u m


.
A p p l i c a t i o n . S ta tu s B a r = F a ls e
A p p lic a t io n . S t a t u s B a r = " "

VBA,
. S e l e c t .
?
. ,
- .
VBA,
. S e l e c t .
R ange( " A l " ) . S e le c t
S e l e c t i o n . Copy
R a n g e ( " B l" ) . S e le c t
A c t iv e S h e e t. P a ste

, .
R ange( " A l " ) . R ange( " B l ")

,
S e le c t.
VBA. ,
R a n g e . S o r t?
VBA .
,
.
, VBA.
VBA .
, ,
. ,
?
VBA TypeName,
S e l e c t i o n . .
If

T y p e N a m e (S e le c tio n ) <> "R ange" Then


MsgBox " !"
E x i t Sub
End I f

R a n g e S e le c tio n ,
Range, .
,

31. Excel

893

. Window,
Workbook. :
MsgBox A c tiv e W in d o w .R a n g e S e le c tio n .A d d re s s

?
.
I f A c t iv e C h a r t I s N o th in g Then
MsgBox " "
E x i t Sub
End I f

,
( , ).

VBA .
S e l e c t io n . Rows. Count .
?
. Count
(,
). , VBA
.
S e l e c t i o n .A r e a . Count,
. ,
NumRows.

NumRows = 0
F o r Each a re a I n S e le c tio n .A r e a s
NumRows = NumRows + a r e a . Rows. C ount
N e xt a re a

, .
Excel .
?
.
.
C o u n te r = G e tS e ttin g ( " X Y Z C o r p '\ " In v o ic e N u m ", " C o u n t",
C o u n te r = C o u n te r + 1
S a v e S e ttin g "XYZ C o rp " , "In v o ic e N u m ", "C o u n t", C o u n te r

0)

,
C o u n ter.
. C o u n ter
.
. ,
, . ,
, Workbook_Open.

Excel
?
, .

894

VII.

VBA
? , <Ctrl+Shift+J>
<Ctrl+Shift+
?
<Ctrl+Shift+i> VBA :

S e l e c t i o n . E n d ( x lD o w n ) .S e le c t

: x lT o L e f t , x lT o R ig h t
xlU p .
?

.
MsgBox A c t iv e S h e e t. C e lls (R o w s . C o u n t, 1 ) .E n d (x lU p ) .A d d re s s

, .
, .
W ith A c t iv e S h e e t. C e lls (R o w s . C o u n t, 1)
I f Is E m p ty ( .V a lu e ) Then
MsgBox . E n d (x lU p ) . A d dre s s
E ls e
MsgBox . A d dre s s
End I f
End W ith

VBA ,
?
. S e t .
.

Dim MyRange as Range


S e t MyRange = T h is W o rk b o o k . W o rk s h e e ts ( " 1 " ) . R an ge ( " A l ")

S e t Range
MyRange. ,
:
M yR ange.V alue = 10

,
.
, ,
?
. Dim.
. ,
, ReDim, . ReDim
P r e s e r v e .

?
, . ,
VBA , .
.

31. Excel

895

,
OnUndo .
, , ,
. .
A p p l i c a t i o n . OnUndo " " ,

"MyUndoMacro"


?

, Excel In p u tB o x . ,
, , .
, 1.
U s e rV a l = A p p lic a t io n . I n p u t B o x ( p r o m p t : = " " , T y p e := l)
I f T yp e N a m e (U se rV a l)<>"B o o le a n " Then R a n g e ("A l") = U s e rV a l

VBA InputB ox,


A p p l i c a t i o i l ?
. Excel In p u tB o x ,
.
In p u tB o x ( ).
, .

VBA,
(") . ?
, VBA
1.
=(1="" ,

, )

,
.
R a n g e ( " B l" ) .o r m u la = " =(1="", ,)"

'

.
Excel .
.
R a n g e ("B l") .F o rm u la = "=( A l= " " Y e s " " , ,)"

VBA C hr 34.
.
.
R ange( " B l " ) . F o rm u la = _
" = (A l= " Sc C hr (34)

& " " & C h r(3 4 )

& " , , ) "

, ,
. VBA
R e p la c e .
MyFormula = "= 1 = ' ' , TRUE,FALSE)"
R ange( " B l " ) . F o rm u la = R e p la c e (M y F o rm u la ,

C h r(3 4 ))

VII.

896

.
?
, VBA 0
. , 1 ,
VBA.
O p tio n Base 1

, .
.
Dim M o n th s (1 12) As S t r i n g

, Excel
XLM. ?
, . ,
Excel 2010, VBA.
, Excel XLM
. Excel 2010
A r g u m e n t D e s c r ip t io n s
M a cro O p tio n s. A d d ln s2 ,
( , ).
Excel ( )
XLM.
VBA ?
.

, .
O p tio n E x p l i c i t ,
.

Excel ,
.

W ith -E n d W ith , .

,
A p p l i c a t i o n . S c r e e n U p d a tin g = F a ls e .

,
, ,
.

UserForm
. ?
. VBA MsgBox In p u tB ox. ,
Excel I n p u t Box.

31. Excel

897

UaerForm 12
CommandButton. ,
?
,
CommandButton C lic k .

C om m andB utton_C lick.
(. 15).
UaerForm?
.
, GIF
GIF Image.
UaerForm,


() U serForm
Windows API.
.
U serF o rm _ Q u ery C lo se,
UserForm . ,
.
P r iv a t e Sub U serF orm _Q ue ryC lo se _
(C a n ce l As I n t e g e r , CloseMode As In te g e r )
I f CloseM ode = vb F o rm C on trolM en u Then
MsgBox " ."
C an cel = T ru e
End I f
End Sub

UaerForm
C o n tro lS o u rc e .
?
,
, .
, ,
. ,
, ,
.

UaerForm? Visual Basic, ,
VBA
,
C o n tr o l. ,
CommandButton.

VII.

898
P r iv a t e Sub U s e r F o r m _ I n i t i a li z e ()
Dim B u t t o n s () As CommandButton
C nt = 0
F o r Each C t l I n U s e rF o rm l. C o n tr o ls
I f T ype N am e(C tl) = "C om m andButton" Then
C nt = C nt + 1
ReDim P re s e rv e B u t t o n s (1 To C nt)
S e t B u tto n s ( C n t) = C t l
End I f
N e xt C t l
End Sub

?
. H id e U serForm ,
. U n lo a d ,
( T e r m in a te UserForm ) U s e r Form .
TJaerForm
?
U se Form
. ,
. U serForm .
Show v b M o d e le ss. .
U s e rF o rm l. Show vb M o de less


?
U se Form. 15
,
, .
Excel UserForm?
,
. .
^
(Home^Clipboard^Copy). U serForm
Im age. <F4> Properties ().
P i c t u r e <Ctrl+V>,
Im age. ,
A u t o S iz e True.
UserForm,
?
U serForm .
VBA G etO p en F ilen am e. ,
, .

31. Excel

899

L istB o x ,

. ?
,
Courier New. L is tB o x
( 14).
L is tB o x
ComboBox VBA?
, .
L is tB o x l:
L i s t B o x l . L i s t = A r r a y ( " " ,

" ",

" ")

Excel
VBA?
( ) Excel
A p p l i c a t i o n . D ia lo g s . ,
, :
A p p l i c a t i o n . D ia lo g s (x lD ia lo g F o rm a tN u m b e r) .Show

, Excel
.
( ,
) E x e c u te M s o
. ,
, .
A p p lic a tio n .C o m m a n d B a rs . E xe cu te M so ( "N u m b e rF o rm a ts D ia lo g ")

22.
, ,
. ?
E x e c u te M s o ,
. ,
(Insert Cells).
, .
A p p l i c a t i o n . CommandBars. ExecuteM so

( " C e ll s I n s e r t D i a l o g " )

UserForm
.
?
, . U serForm ,
, .
F\\e^>Export File ( ^ )
. ,
F\\e^>Import File (1^ ).

900

VII.

U se r Form
?
, API-.

UserForm,
?
, U serForm ,
, .
Use Form,
.
,
, ?
, ,
? ,
Zoom Use Form . ,
1024x768,
.
UserForm,
?
. R e f E d it.
14.
UserForm?
. L e f t
Use Form. ,
S t a r t U p P o s i t i o n 0.
,
Excel
?
.
.

W ith U s e rF o rm l
. S t a r t U p P o s it io n = 0
. L e f t = A p p l i c a t i o n . L e f t + ( 0. 5 * A p p l i c a t i o n . W id th ) _
- ( 0. 5 * .W id th )
.Top = A p p l i c a t i o n . Top + ( 0. 5 * A p p l i c a t i o n . H e ig h t ) _
- ( 0. 5 * .H e ig h t)
. Show 0
End W ith

UserForm,
?
. 15.

31. Excel

901

Excel?
Excel .

Excel ,
. (Add-Ins).

- Microsoft Office Update.

,
.


-.

?

(Add-Ins). ^ Excel (File1^ Excel Options).
Excel (Add-Ins).
(Manage) Excel (Excel Add-ins)
(Go).
(Add-Ins) <Alt+TI>. ,
(Developer), ^1^
(Developer^ Add-Ins^ Add-Ins).
^
(File^Open), (Add-Ins).
^ (File^Open),
VBA.

. ?
^^1^ (File^Info^Propertiers1^Advanced),
(Properties). (Summary).
(Title) ,
. (Comments) .
.
.
?
Excel.
,
. (AddIns) Excel . *
.

902

VII.

?
^ (File1^
Save As). (Save as )
Excel (Excel Add-in (*.xlam)). ,
.


, .
, .
?
! ,
.
, .
.
: XLSM XLAM?
. , .
?
VBA,
; VBE,
. ,
VBE ( <Alt+Fll>) Is A d d ln
T hisW orkbook () F a ls e . ,
Is A d d ln T rue .
XLSM XLAM,
XLSM? XLAM? > ?
,
. VBA .
XLSM, XLAM. XLAM VBA,
. XLAM .
?
VBE Tools^xxx Properties (^ ) ( ). Protection (),
Lock project from viewing ( ) .
? , XLAM-,
, ?
.
. Excel
,
. ,
.

31. Excel

903


VBA ?
. XML- (
RibbonX) XML-
, . ,
( , ),
.


?
Excel 2010
:

RibbonX ( );

( ,
VBA );

( , VBA
);

,
(Add-Ins).

?
,
(Customize Quick Access
Toolbar). (Quick Access Toolbar)
Excel (Excel Options), (Macros)
, . ,
(Add).
(Modify).
?

(Customize the Ribbon). (Customize
Ribbon) Excel (Excel Options)
(Macros).
(Add). ,
.
(New Group).
VBA ?
SendK eys.
<Alt> . ,
(Page Layout) :
A p p lic a tio n .S e n d K e y s

"% p {F 6 }"

904

VII.

,
?
.
Sub D is a b le A llS h o r tc u tM e n u s ()
Dim cb As CommandBar
F o r Each cb I n CommandBars
I f c b .T y p e = msoBarTypePopup Then _
c b .E n a b le d = F a ls e
N e xt cb
End Sub

...

Excel

VBA

VBA

Excel
...

Excel
Microsoft

-

, , ,
. , ,
. , ,
.
, ,
Excel.
: Excel,
Microsoft, - .

Excel
,
Excel.
Excel
<F1>. ,
Excel.
(Search).
Visual Basic,
:

, ,
<Enter>;

VIII.

908

, ,
<F1>.
Excel ,
, .
.


Microsoft
.
. ,
Microsoft. Microsoft
.


Microsoft .
, (
), Microsoft:
h t t p : / / s u p p o r t . m i c r o s o f t . com

M ic ro s o ft
Microsoft Knowledge
Base ( Microsoft).
Microsoft ,
, ,
, ..

. :
h t t p : / / s u p p o r t . m i c r o s o f t . c o m /s e a rc h

M ic ro s o ft E xcel
Microsoft Excel :
h t t p : //w w w . m i c r o s o f t . c o m / o f f ic e / e x c e l

, , ,
, , Microsoft.

M ic ro s o ft O ffic e
Office 2010 ( Excel)
Microsoft:
h ttp ://o ffic e .m ic r o s o ft.c o m

, , ,
.

. Excel

909

, .
, URL-,
, - .


Usenet ,
, .
, .
, ,
( , ,
). , ,
24 (, ,
).



Usenet
. ,
. Windows,
Outlook Express, Windows Windows Live
( ).
Microsoft ,
Excel.
Microsoft,
Microsoft ( ).
Microsoft ( m s n e w s .m ic ro s o ft.c o m )
( -).


,
Microsoft -. , -
, ,
,
.

Google Groups
:
h t t p : / / g r o u p s . g o o g le . com

Microsoft ( Excel)
:
w w w .m ic r o s o ft. c o m /c o m m u n itie s /n e w s g ro u p s /d e fa u lt.m s p x

. .1 Excel,
Microsoft (
Google Groups).

VIII.

910

1. , Excel, Microsoft

m ic r o s o f t . p u b l i c .e x c e l

Excel
Excel
OLE, DDE

, Excel Macintosh
,

Excel
Excel

Excel VBA
Spreadsheet Solutions
XLT

m ic r o s o f t . p u b l i c .e x c e l. c h a r t in g
m ic r o s o f t .p u b l i c .e x c e l. in te r o p o le d d e

m i c r o s o f t . p u b l i c . e x c e l.m a c in to s h
m i c r o s o f t . p u b l i c .e x c e l.m is c

m ic r o s o f t .p u b l i c .e x c e l.new users
m i c r o s o f t . p u b l i c .e x c e l . p r i n t i n g
m ic r o s o f t . p u b l i c .e x c e l.p ro g ra m m in g

m ic r o s o f t . p u b l i c . e x c e l.w o rk s h e e t.
fu n c tio n s
m i c r o s o f t . p u b l i c .e x c e l. te m p la te s



.
, .
, , -
.
Google Groups h t t p : / /
g r o u p s . g o o g l e . com.
? , ,
.
: E x c e l ,
. Google ,
.
,
.
, . , Google
90% , Excel.

,
.
1. , .
, .
2. . !
,
.
3. Excel.
Excel.

. Excel

911

4. .
5. .
6. . ,
. ,
.
7. , .
8. ,
,
.
9. ;
.
10. .
11. HTML.
.
12. ,
, .
,
?

-
-, Excel.
.

The S p re a d s h e e t Page
h t t p : //s p r e a s h e e t p a g e . com

- . , ,
Excel,
, . ,
, .

, E xcel
h t t p : //D a ily D o s e O f E x c e l. com

, .
, .
, .


h t t p : / / p e l t i e r t e c h . c o m /E x c e l

, m i c r o s o f t . p u b l i c . e x c e l . c h a r t i n g ,
.
, . -
Excel, .

912

VIII.


www. c p e a rs o n . c o m /e x ce l. htm
, ,
VBA, .

C o n te x tu re s
h t t p : / / c o n t e x t u r e s . /
,
Excel Access.

P o in ty H a ire d D ilb e rt
h t t p : //c h a n d o o . org/w p/
, Excel.


www.mvps. o r g /d m c ritc h ie /e x c e l/e x c e l.h tm
Excel.

E xcel
www.M rExcel. com
, Excel, ,
Excel. .


VBA
...
Excel VBA

VBA .
Excel.

Excel 2010 VBA .

.1 . VBA

t i v a t e

C a ll
C hDir
C hDrive
Close
Const
Date
D e cla re
D efBool









DLL
B oolean ,

B yte ,

D efByte

30 . 3107

VIII.

914

. . 1

DefCur

C u rre n cy
,
Date ,

D ecim al ,

D ouble ,

in t e g e r ,

Long ,

o b je c t ,

s in g le ,

s t r i n g ,

V a r ia n t ,


()

, .
,
, i f , w ith , Sub, F u n c tio n ,
P ro p e rty , Type S e le c t



,
Do - Loop
Do - For
F u n c tio n



( )

D efDate
DefDec
D efD bl
D e fIn t
DefLng
DefObj
DefSng
D e fS tr
D efV ar
D e le te S e ttin g
Dim
Do - Loop
End

Enum
Erase
E rro r
Event
E x it Do
E x it For
E x it F u n c tio n
E x it P ro p e rty
E x it Sub
F ile C o p y
For
Each - N ext
F or - N ext
F u n c tio n


F u n c tio n
Get

G oSub.. .R e tu rn
GoTo

If- T h e n - E ls e

. VBA

915
. . 1

Im plem ents

In p u t #

K ill

L et

L in e In p u t #

Load
,
L o c k .. .U n lo c k
Lset

Mid

M kD ir

Name

On E r r o r

O n .. .GoSub

O n .. .GoTo

Open

O p tio n Base
,
O p tio n Compare ,

O p tio n

E x p lic it
O p tio n P r iv a te
P r in t #
P r iv a te
P ro p e rty Get
P ro p e rty L e t
P ro p e rty Set
P u b lic
Put
R aiseE vent
Randomize
ReDim
Rem
Reset
Resume
RmDir
Rset
S a v e S e ttin g
Seek
S e le c t Case
SendKeys
Set
S e tA ttr

, P r iv a te


P ro p e rty Get
P ro p e rty L e t
P ro p e rty Set


,


( , ['])









VIII.

916

. . 1

S t a t ic

,


Sub



, ,



Stop
Sub
Time
Type
Unload
W h ile . . .Wend
W id th #
W ith
W rite #

Excel
VBA
VBA , Excel, Excel
VBA.
W o rk s h e e tF u n c tio n . , VBA
. Excel
, VBA:
Deg = A p p lic a tio n .W o r k s h e e tF u n c t io n . D e g r e e s (3 .1 4 )

W o r k s h e e t F u n c t i o n Excel 97.
Excel W o r k s h e e t F u n c t i o n ,
:
Deg = A p p l i c a t i o n . D e g re e s (3 .1 4 )

Excel 2010 VBA .

.2. VBA

Abs
A rra y
Asc
A tn
CallByName
Cbool
c b y te
Ccur
Cdate



ASCII

()
B oolean
B yte
C u rre n cy
Date

. VBA

917
. . 2

CDbl
Cdec
Choose
Chr
C in t
CLng
Cos
C re a te O b je c t
CSng
C Str
C u rD ir
Cvar
CVDate

Double
D ecim al


In te g e r
Long

OLE A u to m a tio n
s in g le
s t r i n g

V a r ia n t
Date (
, )
CVErr
,

Date

DateAdd

D a te D iff

D a te P a rt

D a te S e ria l

D ateValue

Day

DDB

D ir
,
DoEvents
,

E n v iro n

EOF
True,
E rro r
,
Exp
(),
F ile A t t r

F ile D a te T im e

F ile L e n

F ilt e r

F ix

Format

F orm atC urrency (
)
FormatDateTime
FormatNumber

F orm atP ercent
F re e F ile

VIII.

918

. . 2

FV
G e tA llS e ttin g s
G e tA ttr
GetObj e c t
G e tS e ttin g



,
OLE A u to m a tio n





,

,





True,
True,
True,
True,
True,

True, N u ll
True,
True, o le

Hex
Hour
Iif
In p u t
In p u tB o x
In S t r
In S trR e v
In t
Ipm t
IRR
Is A r r a y
Is D a te
IsE m pty
Is E r r o r
Is M is s in g
I s N u ll
IsN u m e ric
IsO b j e c t

A u to m a tio n
J o in
Lbound
Lease
L e ft
Len
Loc
LOF
Log
LTri,m
Mid
M in u te
MIRR
Month
MonthName
MsgBox

,

,
,










,

. VBA

919
. .2

Now
Nper
NPV
Oct
P a r titio n
Pmt
Ppmt
PV
QBColor
Rate
R eplace
RGB
R ig h t





, ,



RGB

,
, RGB
,

0 1




,





,



,



,
, True




, , .
,
,
/

Rnd
Round
RTrim
Second
Seek
Sgn
S h e ll
S in
SLN
Space
Spc
S p lit
Sqr
S tr
StrComp
StrC onv
S t r in g
S trR e ve rse
S w itc h
SYD
Tab
Tan
Time
Tim er
T im e S e ria l
TimeValue
T rim

VIII.

920

. .2

TypeName
Ubound
Ucase
Val
VarType
Weekday
WeekDayName
Year

,


,
,
,
,


VBA
,
. .
Excel.
. 1 . VBA

3
5
6
7

10
11
13
14
16
17
18
20
28
35
47
48
49
51

R e tu rn GoSub


(, in te g e r )
.
, . ,
, Excel
Windows (, ,
)
.
, .
, Sheets ( " 2" ) , 2






. ,
,
. ,
E x it Sub


DLL
DLL
DLL

VIII.

922

. . 1

52
53
54
55
57
58
59
61
62
63
67





/










/

w itc h .
,
Set. ,
(, A c tiv e C e ll) ,

F or

N u ll
,

,


,





Set
Set ( )

Set
Get
Get ( )

68

70
71
74
75
76
91

92
93
94
96
97
98
321
322
325
380
381
382
383

. VBA

923
. . 1

424

. ,

ActiveX (
, )





.
A u to m a tio n ,






P ro p e rty L e t , P ro p e rty Get


DLL



A u to m a tion , Visual Basic







temp


, .
.
, VBA. ,
Excel ( ) VBA.
,
( R aise E rr),
VBA

429
430
432
438
440
442
443
445
446
447
448
449
450
451
452
453
454
455
457
458
459
460
461
462
463
481
482
735
744
746
1004

-
...


-
, -

-, .
-, ,
ReadMe, -.
:

-;

, -;


,
, . ,
-:

Windows Microsoft Excel 2010;

-.

VIII.

926

-
-
.
1. - -.
. ,
. (Start)
(Run). D: \ s t a r t . . ( D
, -,
(My Computer) ( ,
Windows Vista/Windows 7).) .
2. -.
.

,
-

, -.


-
Adobe Portable Document Format (PDF).
Adobe Acrobat Reader, -.


, ,
. ,
Excel 2007 :

. x l s x Excel;

.x ls m Excel, VBA;

.x la m Excel, VBA.
, (ch a p
te r s . .. C h a p te r3 0 ), /R us,
.

XLSM- Excel
, , .
(Options)
(Enable This Content).
, -, '
- ,
, .
.

. -

927

1. (Explorer)
-, -.
2. ,
, ().
3. , .

(Paste).
- , . 3.

.
1. Excel ^ Excel (File1^ Excel Op
tions) Excel (Excel Options).
2. Excel
(Trust Center).
3. (Trust
Center Settings).
4. (Trust Center)
(Trusted Locations).
5. (Add New Location)
Microsoft Office
(Microsoft Office Trusted Location).
6. Microsoft Office (Microsoft Office
Trusted Location) (Browse) ,
, -.
7. (Subfolders
of This Location Are Also Trusted).
XLSM-,
, ,
.
, -.

a r r a y fo rm u la e x a m p le s .x l s x . ,
.

c o u n ti n g a n d summing e x a m p le s . x ls x . ,
.

m e g a fo rm u la . xlsm . ,
, , VB.

928

VIII.

named f o r m u la s .x l s x . ,
.

y e a r l y c a l e n d a r . x l s x . , ,
.

sa m p le . xlsm . ,
.

w o r k s h e e t c o n t r o l s .x l s x . ,
ActiveX ( ).

comment o b j e c t .x lsm . ,
Comment VBA.

t im in g t e s t .x lsm .
,
.

s h e e t s o r t e r . xlsm . , .

10

a r r a y a rg u m e n t .x lsm . ,
.

c o m m issio n f u n c t i o n s . xlsm . ,
.

d ra w .x ls m . ,
.

e x te n d e d d a t e f u n c t i o n s . xlsm . ,
, 1900 .

e x te n d e d d a t e f u n c t i o n s h e lp .d o c x . Word,
.

k e y p r e s s . xlsm . , API- ,
: <Ctrl>, <Shift> <Alt>.

m onth name s . xlsm . ,


.

mysum f u n c t i o n .x l s m . ,
Excel (SUM).

no a rg u m e n t. xlsm . , .

. -

929

rem ove v o w e l s . xlsm . , ,


.

u p p e r c a s e .x lsm . ,
.

w i n 3 2 a p i . t x t . ,

Win

dows API.

w indow s d i r e c t o r y .xlsm . , API-,


Windows.

11

a b o u t r a n g e s e l e c t i o n . xlsm . ,
.

\ b a t c h p r o c e s s i n g . , ,
.

c e l l t y p e f u n c t i o n .x ls m . ,
, .

c o p y m u l t i p l e s e l e c t i o n . xlsm .
, .

d a t e a n d tim e . xlsm . ,
.

d e l e t e em pty row s . xlsm . ,


.

d r i v e in f o r m a t io n . xlsm . , ,
, .

d u p l i c a t e row s .xlsm . ,
.

e f f i c i e n t l o o p i n g . xlsm .
.

f i l e a s s o c i a t i o n .x lsm . API-,
, .

h id e row s a n d co lu m n s . xlsm . , ,
, .

in p u tb o x dem o .x lsm . ,
.

in r a n g e f u n c t i o n . xlsm . ,
, .

l i s t f o n t s .x l s m . ,
.

lo o p v s a r r a y f i l l r a n g e .x ls m .
, .

930

VIII.

n e x t em pty c e l l . x l s m . , ,
.

p a g e c o u n t.x ls m . ,
, .

p r i n t e r i n f . xlsm . , API-,
.

p ro m p t f o r a r a n g e . xlsm . ,
.

r a n g e s e l e c t i o n s . xlsm . ,
.

s e l e c t by v a lu e .x l s m . , ,
.

s o r t i n g demo .x lsm . ,
.

\ sound. , ,
Excel.

s y n c h r o n iz e s h e e t s .x l s m . ,
.

\ v a l u e from a c l o s e d w orkbook. ,
.

v a r ia n t

v id e o m o d e.x lsm . API-,


.

w indow s r e g i s t r y .x lsm . ,
.

w o r k s h e e t f u n c t i o n s . xlsm .
, VBA.

t r a n s f e r . x l s m . ,
V a r i a n t .

12

d a t a form ex am p le .x lsm . ,
Excel.

g e t d i r e c t o r y . xlsm . ,
.

i n p u t b o x m e t h o d . x l s m . ,
Excel I n p u t B o x .

p ro m p t f o r f i l e . xlsm . ,
().

r ib b o n c o n t r o l nam es .x l s x .
Excel 2007 Excel 2010.

VBA

i n p u t b o x . x l s m . ,
VBA I n p u t B o x .

. -

931

13

a c t i v e x w o rk s h e e t c o n t r o l s .x ls x .
ActiveX ( ).

a l l u s e r f o r m c o n t r o l s . xlsm .
Use Form,
.

g e t name a n d s e x .x ls m .
U serForm .

new cont r o l s . . , ,
UserForm.

s p i n b u t t o n an d t e x t b o x . xlsm .
, S p in B u tto n T extB ox,
U serForm .

s p i n b u t t o n e v e n ts .x ls m .
S p in B u tto n .

u s e r f o r m e v e n ts .xlsm .
Use Form.

14

c h a n g e u s e r f o r m s i z e .x lsm .
VBA U serForm .

d a t e a n d tim e p i c k e r . xlsm .
D ate and Time P ic k e r .

l i s t b o x a c t i v a t e s h e e t.x ls m . ,
L istB o x .

l i s t b o x f i l l . x l s m . ,
L is tB o x .

l i s t b o x ite m t r a n s f e r . xlsm .
L is tB o x .

l i s t b o x move ite m s .x ls m .
L is tB o x .

l i s t b o x m u l t i c o l u m n l . xlsm .
L is tB o x , .

l i s t b o x m u ltic o lu m n 2 .x lsm .
L is tB o x , .

l i s t b o x m u l t i p l e l i s t s . xlsm .

L is tB o x .

l i s t b o x s e l e c t row s .xlsm .
( L istB ox).

l i s t b o x s e l e c t e d ite m s .x lsm .
L is tB o x .

932

VIII.

l i s t b o x u n iq u e i t e m s l . xlsm .
L is tB o x .

l i s t b o x u n iq u e ite m s2 .xlsm . l i s t b o x u n iq u e i t e m s l .
xlsm , .

\ m e d ia p la y e r . m e d i a p la y e r .x l s m
( Media Player),
MP3.

m u ltip a g e c o n t r o l dem o.xlsm .


M u ltiP a g e
U serForm .

q u e r y c l o s e dem o. xlsm .
Use Form
.

random num ber g e n e r a t o r .x lsm .


, Use Form.

ra n g e s e l e c t i o n dem o. xlsm .
Ref E d it UserForm.

r e s i z a b l e u s e r f o r m a p i.x l s m . ,
Windows API
U serForm .

s p l a s h s c r e e n .x ls m . U s e rForm , .

u s e r f o r m m e n u s.x lsm .
U serF orm .

zoom a n d s c r o l l s h e e t .x l s m .

U serForm .

zoom u s e r f o r m .x ls m .
U serForm .

15

c h a r t i n u s e r f o r m .x ls m .
Use Form.

\d a ta f o r m . En
hanced Data Form.

e x c e 1 1 i g h t b o x . x l sm. Ex
cel Use Form.

g e t a c o l o r f u n c t i o n . xlsm . ,

U serForm .

. -

933

m o d e le s s u s e r f o r m l . xlsm .
Use Form,
.

m o d e le s s u s e rf o rm 2 .x lsm . m o d e le s s
u s e r f o r m l .x ls m .

move c o n t r o l s .x lsm .
U serForm .

m sgbox e m u la tio n .x ls m . , ,
VBA MsgBox.

m u l t i p l e b u t t o n s .x lsm .
,
Use Form.

no t i t l e b a r.x ls m . API-
U serForm .

p r o g r e s s i n d i c a t o r l .x lsm .
U serForm .

p r o g r e s s i n d i c a t o r 2 . xlsm .
M u ltiP a g e
Use Form.

p r o g r e s s i n d i c a t o r 3 . xlsm .
UserForm .

r e s i z a b l e u s e r f o r m . xlsm .
U serF orm .

s e m i t r a n s p a r e n t u s e r f o r m .x ls m . ,
U serForm .

s i m u l a t e d t o o l b a r . xlsm .
U serForm .

s l i d i n g t i l e p u z z le . xlsm .
U serForm , .

s p la s h s c re e n 2 .xlsm . s p la s h s c r e e n .x ls m 14,
U serForm .

v i d e o p o k e r . xlsm . ,
Use Form.

w iz a rd dem o.xlsm . Mul


t iP a g e UserForm,
.

16

s im p le undo demo .x lsm .


VBA.

t e x t t o o l s . xlam. , Excel .

VIII.

934

t e x t t o o l s . chm. t e x t t o o l s . xlam .

\ t e x t t o o l s h e lp s o u r c e . ,
t e x t to o I s . chm.

17

b u d g e t p i v o t t a b l e .x lsm . ,
.

n o r m a liz e d d a t a . x l s x . ,
.

r e v e r s e p i v o t t a b l e .x l s m . ,
, .

s im p le p i v o t t a b l e .x l s m . ,
.

s u r v e y d a t a p i v o t t a b l e s . xlsm . ,
28 .

18

a n im a te d c h a r t s . xlsm . , VBA
.

c h a r t a c t i v e c e l l .xlsm . ,
, , .

c h a r t im age m ap .x lsm .
.

c h a r t i n u se r fo r m .x ls m . U s
e r Form. , .

c l i m a t e d a t a . x l s x . , .

d a t a l a b e l s . x l s m . ,
, .

e v e n ts - c h a r t s h e e t .x lsm . ,
, .

e v e n ts - em bedded c h a r t . xlsm . ,
.

e x p o r t a l l g r a p h i c s .x lsm . , ,
.

f o rm a t a l l c h a r t s .x lsm . ,
, .

g e t s e r i e s r a n g e s .x lsm . ,
.

h i d e an d u n h id e s e r i e s . x l s m . ,
, .

. -

935

h y p o c y c l o id

- a n im a te d .x ls m . ,
.

m o u seo v e r

m o u seo v e r e v e n t - em b ed d ed . x lsm .
M ouseO ver .

s c r o l l i n g c h a r t .x ls m .
, .

s i z e and a l i g n c h a r t s .x ls m . ,
, .

s p a r k l i n e r e p o r t , xlsm . , ,
.

u n lin k e d

v b a c l o c k c h a r t . xlsm . ,

e v e n t - c h a r t s h e e t .x l s m .
M ouseO ver .

c h a r t .x ls m . ,

.
.
19

a p p l i c a t i o n e v e n t t r a c k e r . x lsm .
.

h id e

l o g w orkbook o p e n . x lsm . ,
,
.

make fo r m u la s b o l d . x lsm .
W o rk sh eet Change.

no s h o r t c u t m e n u s.x lsm .
W orkbook_Open , Workb o o k _ B ef o r e C lo s e .

o n k e y e v e n t d em o .x lsm .

co lu m n s b e f o r e p r i n t i n g . x lsm .

.

o n tim e e v e n t d em o. x lsm .
OnTime.

sh a d e a c t i v e row and c o lu m n .x ls m . ,
W ork sh eet S e le c t io n C h a n g e
.

v a lid a te

e n t r y l .x lsm .
, , VBA (
E n a b le E v e n ts).

936

VIII.

v a l i d a t e e n tr y 2 .x l s m .
, VBA (
).

v a l i d a t e e n tr y 3 .x l s m .
Excel.
.

w o rk b o o k _ b e f o r e c l o s e w o rk a ro u n d . xlsm .
, W ork
book B e f o re C lo s e .

20

\ a u to m a te e x c e l. , Word,
, Excel.

c o n t r o l p a n e l d i a l o g s . xlsm . ,
Windows.

make m em os.xlsm . , Word,


.

p e r s o n a l i z e d e m a il - o u t l o o k . xlsm .
, Outlook (
).

p e r s o n a l i z e d e m a il - o u t lo o k ( l a t e b in d in g ) .x lsm .
,
Outlook ( ).

p e r s o n a l i z e d e m a il - se n d k e y s .xlsm . , ,
Windows.

se n d p d f v i a o u t l o o k . xlsm . ,
, PDF-, Outlook.

\ sh e 11 e x e c u te . , , ,
API- She 11 E x ecu te.
s h e l l e x e c u t ex am les . xlsm .

s t a r t c a l c u l a t o r . xlsm . ,
.

21

c h e c k a d d in .x la m . , ,
.

e x p o r t c h a r t s .x lsm . Export Charts Utility,


.

e x p o r t c h a r t s . chm. e x p o r t c h a r t s ..xlsm.

\ e x p o r t c h a r t s h e l p s o u rc e . ,
e x p o r t c h a r t s . chm.

. -

937

l i s t a d d - i n i n f o r m a t i o n . xlsm . ,
.

22

dyn am icm en u . xlsm .


DynamicMenu.

mso im age b r o w s e r . xlsm . ,


, .

o l d - s t y l e t o o l b a r . xlsm .
, Excel.

p a g e b r e a k d i s p l a y a d d - i n . xlam . ,
Excel.

p a g e b r e a k d i s p l a y .x lsm .
b r e a k d i s p l a y a d d - in .x la m .

r ib b o n c o n t r o l n a m e s .x ls x . ,
Excel 2007 Excel 2010.

r ib b o n c o n t r o l s dem o.xlsm . ,
.

r ib b o n m o d i f i c a t i o n .x l s m . ,
Excel.

23

a d d t o c e l l s h o r t c u t . xlsm . , ,
.

c o n t e x t - s e n s i t i v e s h o r t c u t m enu.xlsm . ,
- .

make x l 2 0 03 m en u s.x lsm . ,


Excel 2003.

s h o r t c u t w i t h su b m en u .x lsm . , ,
.

show f a c e i d s . xlsm . ,
F a c e ld .

show s h o r t c u t menu ite m s .x lsm . ,


.

show s h o r t c u t menu nam es .x lsm . ,


.

24

\ c e l l com m ents. ,
.

\ f u n c t i o n h e lp .
VBA.

938

VIII.

\h tm l h e lp . ,
HTML.

\m htm l f i l e . ,
MHTML- Internet Explorer.

\ t e x tb o x . ,
.

\ u s e r f o r m l . ,
U ser F o r m
S p in B u t t o n , .

\u s e r fo r m 2 . ,
U se Form,
L a b e l, .

\ u s e r f o r m 3 . ,
U serF o rm ,
ComboBox, .

\w eb b r o w se r . ,
U serForm .

\ w o rk s h e e t. ,
.

25

lo a n a m o r t i z a t i o n w i z a r d . xlam .
.

26

m u l t i l i n g u a l w iz a r d .x ls m . ,
.

27

c r e a t e f i l e l i s t .x lsm . ,
, .

e x p o r t a n d im p o r t c s v . xlsm . ,
CSV.

e x p o r t t o HTML.xlsm. ,
HTML-.

e x p o r t t o XML.xlsm. , ,
XML-.

file

f u n c t i o n s . x lsm . , F i l e E x i s t s

P a t h E x is t s .

f i l e in f o r m a t i o n . xlsm . ,
.

\ f i l t e r t e x t f i l e . ,
.

. -

939

r e c u r s i v e f i l e l i s t . x l s m . ,
, , .

show d r i v e i n f . xlsm . ,
, .

\ s im p le ADO 1. ADO
Access.

\ s im p le ADO 2. ADO
CSV.

u n z ip a f i l e .x lsm . ,
.

z ip f i l e s , x l sm. , .

28

ad d 100 b u t t o n s .x lsm . ,
100 Com m andButton
Use Form .

ad d b u t t o n a n d c o d e . xlsm . ,
, VBA,
.

c r e a t e u s e r f o r m on t h e f l y .x l s m . , ,
U serForm .

g e t o p t i o n f u n c t i o n . xlsm . , ,
Use Form (
O p tio n B u tto n ) , ,
.

l i s t a l l p r o c e d u r e s . xlsm . ,
VBA, .

l i s t VB co m p o n e n ts . xlsm . ,
VB, .

\u p d a te U s e rB o o k . , ,
VBA .

29

c s v l a s s . xlsm . , /
CSV.

k e y b o a r d c l a s s .x ls m . , ,
N um Lock, C a p s L o c k S c r o l l L o c k .

30

c h a r t c o l o r s .x l s m . ,
.

c h a r t t o g r a y s c a l e p i c t u r e . xlsm .
, .

940

VIII.

c o l o r c o n v e rs io n f u n c t i o n s . xlsm . ,
.

docum ent them e d e m o .x ls x . ,


, .

g e n e r a t e them e c o l o r s .x lsm . ,
.

rg b c o l o r dem o.xlsm . ,
RGB.

\ s h a p e o b j e c t c o l o r s . ,
.

t i n t a n d s h a d e dem o. xlsm .
T in tA n d S h ad e.


-
, .

.
,
. (
.)

. ,
.
; ,
, .

ReadMe. ReadMe,
-,
.

ActiveX, 146
ADO, 811

A
, 643
, 254
, 808

GUID, 818

HSL, 851
HTML Help, 750

I
IDE, 813


, 72
, 72
Microsoft, 908

, 694

, 593

Microsoft Office Compatibility Pack, 775

Object Browser, 209; 625

p
Project Explorer, 168

R
RGB, 850
RibbonX, 533; 695
s

SmartArt, 71
v

VBA, 162
, 213
, 229
, 230
, 229
, 215
, 216
VBE, 166; 177; 816
Visual Basic, 166

, 796
, 507; 554
, 558
, 554
, 561
, 595
, 555

, 575
, 559
, 573
, 591
, 70
, 577
, 585
, 565
, 399
, 474
, 474
, 405; 418
, 437

, 88
, 326
, 327
, 339

XLB, 117
XLM, 163

, 89
, 175; 183

942

, 164

, 82
, 85
, 88
, 84
, 87
, 82
, 477


ByVal, 267
Call, 259
Const, 224
Dim, 221
Public, 222
Rem, 214
Static, 223
Sub,254
, 164; 191; 236
Addins, 190; 660; 670
Addlns2, 675
ChartObjects, 191; 562; 563
Charts, 190; 558; 562
CommandBars, 721
Comments, 197
Dialogs, 400
Drives, 791
Names, 190
PivotCaches, 539
PivotFields, 539
Pivotltems, 539
PivotTables, 191; 539
References, 817
Shapes, 556
Sparkline Groups, 599
UserForms, 419; 828
VBComponents, 817
VBProjects, 816
Windows, 190
Workbooks, 190; 349
Worksheets, 190
, 224
, 56
, 720
, 732
, 729
, 726
, 733
, 726
, 733

, 509
, 55; 687
, 695

, 50
, 52; 558
XLM, 52
,51
, 188
, 779
, 220

, 75; 174
, 175; 183
, 90

, 105; 484
, 798
, 64; 97
, 165; 193
- , 60
, 780
, 163
, 835
CSVFileClass, 843
NumLockClass, 839

, 75; 117; 659


, 663
, 667

, 85
, 224
, 220
, 255
, 293
, 62
, 50; 163
Addin, 190; 677
Application, 190; 200; 395; 555; 721
, 604; 626
Chart, 190; 554; 555; 578
, 604
ChartObject, 191; 555; 556; 564
ChartTitle, 555
ColorFormat, 866
CommandBar, 400; 692; 715; 719
, 723
Comment, 194
Control, 721
Designer, 826
Err, 270
FileDialog, 399
FileSearch, 785
FileSystemObject, 790
Forecolor, 867
Name, 190
PageSetup, 191
PivotTable, 191


Range, 191; 202
Reference, 817
Selection, 561
Series, 567
Shape, 556; 864
Shell.Application, 793
SparklineGroup, 599
UserForm, 427; 439
, 604; 630
VBComponent, 820
VBIDE, 814
VBProject, 816
Window, 190
Workbook, 190; 555
, 603; 610
Worksheet, 190; 555
, 604; 616
WorksheetFunction, 916
, 169
, 50; 162; 164
, 816
, 230

, 388
, 168
, 168; 210

GoTo, 238
Like, 291
Mod, 227
On Error, 269
Option Explicit, 219
, 228
, 85
, 226
, 191
, 854

/ / / / Q Q
S

#/0!, 89
#!, 89
#?, 89
#/, 89
#!, 89
#!, 89
#!, 89

, 659

, 58
, 693
., 693
, 69
, 172
, 646; 790
, 74
, 228
, 168

943
, 163; 253
, 603
, 695; 701
, 254

, 644; 790
Visual Basic, 166
Windows, 118
, 78
, 51
, 788

, 74; 537
, 549
, 164; 192
-, 62
, 165; 603
, 606
, 773
, 356
, 53; 70; 599
, 76
, 53

, 79
, 79
1, 80
R1C1, 80

, 225
, 477
, 225


, 796
, 795
, 796
, 52; 858

Boolean, 216
Byte, 216
Currency, 216
Date, 216
Decimal, 216
Double, 216
Integer, 216
Long, 216
Object, 216
Single, 216
String, 216
Variant, 216
, 217; 231

944

, 517

, 401
, 509
, 510
, 418
, 418
, 406; 441
, 421
, 66
, 77
, 89
, 87
, 90
, 150
, 287
, 95
, 95
, 300; 598
, 597
, 341
EHETEKCT, 341
, 341
, 233
, 304
, 232; 289
, 567
, 299; 340
, 598
, 92
, 366
, 92
, 339
, 306; 345
VBA
ChDir, 786
ChDrive, 786
CreateObject, 646
DateSerial, 784
Dir, 786; 788
EOF, 250
FileCopy, 786
FileDateTime, 786
FileLen, 786
Format, 301
GetAttr, 786
GetObject, 646
Hf, 242
InputBox, 238; 388
InStr, 354
IsDate, 341
IsEmpty, 341
IsMissing, 306

IsNumeric, 341
Kill, 786
Mid, 291
MkDir, 786
MsgBox, 192; 234; 392; 491
Name, 786
RGB, 850
RmDir, 786
Rnd, 299
SetAttr, 786
Shell, 637
Split, 359
Sqr, 233
TypeName, 218
UCase, 232
Union, 341
WeekDay, 260

, 849
, 850
, 815

, 108
, 111
, 111

, 588

CheckBox, 408
ComboBox, 408
CommandButton, 409; 440; 824
DynamicMenu, 710
Frame, 409; 745
Image, 409; 494
Label, 409; 470; 744
ListBox, 409; 440; 449
Microsoft Windows Media Player, 468
MultiPage, 409; 466; 482; 486; 759
OptionButton, 410; 830
RefEdit, 410; 441
ScrollBar, 410; 448
SpinButton, 410; 429; 744
TabStrip, 410
TextBox, 410
ToggleButton, 410

, 87
, 150
, 88
, 202


Excel VBA
VBA (Visual Basic
for Applications),

Microsoft Excel 2010. ,

,

,
.
Excel
.

Excel
.
VBA,

,
VBA.
Excel,

Excel 2010.



Excel.


Power
Utility . -
, ,
Excel 2010.
Microsoft Excel 2010.
www.spreadsheetpage.com.


Excel,
VBA
-:





.

: Microsoft Excel 2010/VBA


:

:

www.spreadsheetpage.

WILEY
www.dialektika.comwww.wiley.com

Excel



VBA-,

Você também pode gostar