Вы находитесь на странице: 1из 369

. , .

11|>/

-
--

2006

. . , . .

Excel.



.
.
. , .
.
. , ,
.

32.973.23-018.2
004.42

. ., . .
52 Excel. . .: , 2006. 368 : . (
).
ISBN 5-469-01223-9
Microsoft Excel , ( ) , . Excel. , .
, 2006

.
.
, , , .
, , , .
ISBN 5-469-01223-9

. 194044, -. . ., 29.
05784 07.09.01.
005-93, 2; 953005 .
02.12.05. 701007,6. . . . 29,67. 3500 . 6843.
. . .
.
197110, -, ., 15.

11
16

1 . VBA
2. Microsoft Excel
3.
4.
5.
6.
7.

17
80
168
281
289
306
339

. Excel

351
367


:

Microsoft Excel


11
11
12
13
13
16
16

1 . VBA

17

cVBA
VBA
VBA
VBA
, VBA


. Object







Variant
Array

18
18
18
21
21
23
23
24
24
26
27
28
28
29
29
29
30
32
32
33
34
34
35
35
35
36






.





/

. FreeFile








VBA
VBA



API- VBA
API-
API-
Excel
Excel
Excel

,.

36
37
37
38
38
38
38
41
42
43
46
49
51
51
53
54
55
56
58
58
60
61
61
62
63
63
66
66
67
68
69
69
71
71
72
73
73
74
75
76
76
77
78


2. Microsoft Excel

80


Excel

Excel


,






, 256

-
URL-






,

,
?

















81
81
81
82
83
83
84
85
85
86
87
88
92
95
95
95
96
97
97
97
98
98
99
99
100
101
101
103
103
103
104
105
105
106
106
107
107
109
109
110
110
114
115





































,



,




115
116
118
118
119
120
120
123
124
125
127
129
131
131
131
131
132
132
133
133
134
134
136
136
137
138
139
139
140
140
142
143
143
144
144
146
147
150
151
152
153
153
154
155
155
156
156

157
157
158
159
160
161
162
163
165
166

3.

168







,



,















Excel HTML-

169
170
170
171
173
174
174
177
178
180
181
181
182
182
183
184
186
188
189
192
194
197
198
199
200
201
203
205





...







?









,



Word Excel

Excel










Excel

210
211
212
212
213
213
214
215
216
216
217
218
219
219
221
222
225
226
228
228
233
234
239
241
242
245
246
247
248
251
252
256
260
265
267
268
269
271
274

276
276
277

4.

281


, ,

282
283
285
286

5.

289


290

293

294

296

297

298
... 300

303
6.

306

307
307
311
313
315
318
323
323
337

7.

339

. Excel

351

Application

351

Chart
Range
Workbook
Worksheet

355
357
362
364
367


Excel, Microsoft Microsoft Office, . Excel :
, IT-, , , , ,
. . Excel ( , , .).
( F1
: Microsoft Excel).
,
, , Excel ( ). ,
. .

VBA ( VBA Visual Basic Alt+Fll).
,
, .


1
Microsoft Office Visual Basic for Applications (VBA).
VB .
2 ,
, ; Excel ( ).
Excel, .
,
.
3 . ,


. ,
( , ) ,
, .
, , .
, ,
. 4 ,
.
, ,
(
).
, ,
5. ,
, ,
.
6 , , .
7 ,
, . .

Excel: A p p l i c a t i o n , c h a r t , Range, Workbook
Worksheet.


Excel 2002. .
Excel, ,
,
, .
, , Excel. ,
, .


Microsoft Excel
Microsoft Excel .
Q , , .
( , , .).
Q (
OLAP) . XML-.
.
Lotus Notes, (, 1 .).
( -,
Microsoft Excel , - .).
(Word, PowerPoint, Access
.).
: , , , .
Microsoft Office: ,
, , .
VBA.
Excel , .


.
, . Excel
.
. Excel : ,
, , .
, - (, , . .).
, '
.


,
.
, ,
. Shift+FlO.
, Excel Visual Basic for Application (VBA). .
,
. , ,
.

, ,
VBA.

Q , Excel .
.
Q Microsoft
Excel , Excel. .

, .

Microsoft Excel .

,
.
Q ,
, . . .

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


. , , . Excel Windows.
Q ,
. - ,
,
.
Q , , Microsoft Excel. XLS.
(. ).
, , , .
. (. ). 16 777 216 , 65 536 256 .
VBA , () VBA. Visual Basic.
Q , . .
.
( )
, . , . ,
( : , 24, 0, 2).

, ,
, .

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


.
.

Q Microsoft Excel ,
. , , ,
() . , VBA.
Q ,
, .
() , .
, . ,
.

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

, Excel,

. ,
.


() http://www.piter.com/download/978546901223/.


, gurski@minsk.piter.com ( , ).
!
http://www.piter.com
.

VBA

1 . VBA
Microsoft Office Visual Basic for Applications (VBA).
, - ,
, , , , , , ,
. . VBA.

VBA
VBA ,
Microsoft Office. VBA Visual Basic
Alt+Fll.

VBA
, VBA Microsoft
Office . VBA
,
.
Excel VB (, ):
Q , ;
Q ;
, ;
Q , , ;
(, );
;
Q , ,

.
VBA
.

VBA
VBA . 1.1.

VBA
Microsoft Visual Basic - Microsoft ixtel.Hls - [Module 1 (Code)]
w

Insert

Format

Qebug

look

Help

&dd-InS:

i ' |14,9

2J
^ VBAProject ( Microsc
E b f & Microsoft Excel Objects
: : @ 1 (
! ! 1 (1)
: 2 (2)
i | ()
i ; $\
" ^ Forms
.:
-| UserForml
Modules

It

3 Class Modules
I Class 1

JModulel Module
;. Alphabetic | Categoreeii |

(General)

^j

jUserHame

Option Explicit
' API-
Declare Function GetUserNante Lib "advapi32 .dll" Alias
(ByVal ipEuffec String, nSize Long) Long
Sub UserNameO
Dim strBuffer As String
!

strBuffer Space(100)
1
( 1~)
netr/ , '
> * st-jrEuffe^
If GetUserNaroe(strBuffer, 100) Then
1

MsgBox RTrim(str:Buffer)
Else
HsgBox "He "
End If
End Sub

I.
. 1.1. VBA

: (Project),
(Properties) . Project () , , ( ).
Properties ()
.
VBA- Microsoft Excel :
( VBA);
Q ;
Q ;
;
;
.

VBA
VBA , , ( , , . .). Modules.

1 . VBA
,
, .
(), .


, , ( ) . Class Modules.


( Microsoft Excel Objects) , . , ,
(. ). ,
VBA
.


( Microsoft Excel Objects) , . , ,
. VB
.


( Microsoft Excel Objects) ,
,
. .

( Forms) VBA, .
: ( ).
, . .
View Code ( ) Project ().
, View Object ( ) . , ,
. 1.2.

, VBA
Microsoft visual - Microsoft Excel.ls - [Userforml (UserForm)]

te :tdlt

Insert

Format.

*3

Qebug

un

si

Sdd-Ins

ffiindow

[-fq|xj
Uelp

*1

8 ^TvBAProject ( Microsc
Microsoft Excel Objects
; ; 1 (1)
i i ] 2 (2)
! ! ( ] ()
i -$}
.3 > Forms
; *~ UserForml
i s Modules
i ' It Module 1
- U Class Modules
:
Classl

<l,,;

;.:.

| U s e r F o r m l UserForm
Alphabetic j Categorized j

. 1.2.

Properties (). Toolbox ( ) , .


.

VBA
VBA , . , VBA, .
1. , ( Option),
API-.
2. .

,
VBA
, VBA. . 1.1.

1 . VBA
1.1. VBA

, ,
(, "D:\asd.txt",
)


.
, 1.
,

Open

, (
),
VBA ( ,
, . .)

[ ]

! \ 2


(
1, !)

,
_. VBA. ,
, .
,
VBA. ( ):
Dim I S t a t i c _ [As _] [, _ [As _] ] . . .
,
Dim s t a t i c . .
. , () , As .
Dim, (. ). ( ).


, , :
Dim intPos As Integer
Dim varValue, intValue As Integer
Static strText As String
Static varl As Variant, var2 As Variant, var3 As Variant


VBA .
Rem . Rem ('). , Rem . . :
Rem
Dim intRes as Integer
Rem
intRes = 123
, ,
, (
):
1


Dim intRes As I n t e g e r
intRes = 123 '
VBA ,
:
1

Rem ,

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

1. VBA
VBA Unicode. ,
(, ).
.
1. ( ), .
2. .

VBA . ,
strmyText strMyText . , , . .

VBA:
strText
CUST0M_Data2
_

, VBA.


VBA . , , .


VBA . 1.2.
1.2. VBA

Byte ()

()
1

Integer ()

-32 768 32 767

0 255

()

Long (
)

-2 147 483 648 2 147 483 647

Single
(
)

-3.402 82338 -1.401 298-45,


1.401 298-45 3.402 82338

Double
(

)

-1.797 693 134 862 32308'-4.940 656 458 412 47-324,


4.940 656 458 412 47-324 1.797 693 134 862 32308

Currency
(
)

-922 337 203 685 477.5808 922 337 203 685 477.5807

Decimal
(
,

14

:
+/-79 228 162 514 264 337 593 543 950 335;
:
+/-7.922 816 251 426 433 759 354 395 033 5 ( 28
)

Variant
(
)

16

Decimal
.
Variant ( Variant ).

VBA
s t r i n g (). , . VBA : .
- .
, ,
, (, ). . 65 400 .
VBA. .
2 .

1 . VBA


VBA Date.
, , . ,
, Excel.
, Date , VBA . s i n g l e
( ). , 30 1899 , .

Variant
VBA Variant. VBA (
, ).
Variant
VBA . (, , . .).
Variant ( ),
Empty.

. Object
, VB , , . ( ). , .
, VBA, ,
. .
, ( Set). objRef . :
Set objNewRef = objRef
objNewRef , objRef. :
Set objNewRef = Nothing
Set objNewRef = Nothing
, .
VBA Ob j ect. , .


( ) :
Public I Private [WithEvents] _ [As [New] _] _
[, _ [As [New] _]]...
, , :

P u b l i c ( );

P r i v a t e , , - .

( )
( ):
Dim

I Static

[WithEvents] _ [As [New] _]

[, _

[As

[New]

_]]...

, ,
:
Q Dim , ;
Q s t a t i c , .
WithEvents ,
ActiveX.
_ .
_ .
[As [New] _] , Variant.
New, . New wi thEvents, ob j e ct _ .
VBA:
Public intData As Integer
Private intCount As Integer, varData
Dim strText As String
Static a, b,
Dim objRef As Object
Dim objCtrl As New Control

1. VBA

As ,
. , Dim a, b, As Integer
b Variant, Integer.


, VBA .

( ). .

Date 00:00:00 10.12.1899 (


,
).

o b j e c t ( ) Nothing,
( New).


.
VBA . Dim, s t a t i c , P r i v a t e P u b l i c .
. , V a r i a n t .

, . ,
, dblSalaryAccount =
dblSalaryAcount * 10.5 dblSararyAccount
, 5.375. , dblSalaryAcount, .
, VBA .
Option E x p l i c i t .


, Tools Options ( ) VBA Options ()
Editor () Require Variable Declaration (
).

, VB .
VBA .
:
[Public I P r i v a t e ] Const _ [As _] =
:

P u b l i c ;

P r i v a t e , , .

, , P r i v a t e .
_ .
(, "_1", 1.245 . .) , .
, VBA
. :
Const PI As Double = 3.14159265359
Public Const MyConstString = "MyConst"
Private Const As String = ""

VBA , VBA .
.
, VBA-.


. 1.3.

1 . VBA
1.3.

=

= ! + 2

= ! - !

= ! * !

= ! 1 !

= ! \ !


(
)

= ! Mod !

= !

.
!,
!

+ . VBA
&, . &,

, , , .



Boolean. - ,
True, False. , VBA, . 1.4.
1.4.

= ! = !

. True,

= ! > !

. True,
!
!

= 1 < !

. True,
!
!

= ! >- !

.
True, !
!

= ! <= 2

.
True,
!
2

= ! <> !

. True,


, Variant.
Empty, NULL. ,
: .
option
Compare. Excel : Option Compare Text
( ) Option Compare Binary ( , ). Option
Compare Binary.
VB , , Like is.
Boolean .
is ,
. . :
= ! Is 2

Li ke , . :
= Like

, ,
. 1.5.
1.5.

[ ]

[\_]

1 . VBA
, "15 2 6 " 0 0 . - "## ## [] ",
" 15 26 " Like "## ## [ ] " True.
(-). ( ): [A-z] [Z-A].

, , . 1.5,
: ([), (]), (#), (?), (*)'.


VBA , (, if-Then-Else,
). VBA ( )
. 1.6 ( , , ,
True False).
1.6. VBA

= ! Eqv !

. True,

= ] And ! . True,
True
= ! Or !

. True,

True

= ! !

. True,

= Not

. ,


.
. , .
VBA . . ,


. VBA- .


VBA , :
Public I P r i v a t e _ {[]) [As _]
[, _ ([]) [As
_]]...

Dim | S t a t i c _ ([]) [As _]


[, _ ' ([]) [As _]] ...
, ( ).
,
. , , . :
, ReDim ( ).
, :
_ _ | _
[, _ _ | _] . . .
VBA
60. .
_ _
(, 50 100).
. (
).
( , ):
Dim avarValues()
Dim a s t r V a l u e s ( 1 To 10) As S t r i n g , astrValues2(10) As S t r i n g
Dim aintValuesd To 10, 1 To 3) As Integer, aintValues (10, 3) As Integer

1. VBA


, .
, , Option Base.
:
Option Base

Option Base I

(
), .


VBA . , VBA . ReDim,
:
ReDim [Preserve] _ ([]) [As _]
[, _ ([])
[As _]]. . .


Dim ( ). ,
_ Variant.
ReDim Preserve
, , . :
ReDim astrValues(I To 10), aintValues(10, 20)
ReDim varArray(2 To 4) As Boolean

Preserve ,
. :
;
, ;
Q .


ReDim Preserve:
' ReDim
ReDim a s t r V a l u e s ( l To 5, 1 10)
1


ReDim P r e s e r v e a s t r V a l u e s ( 1 5, 1 25)
'
ReDim P r e s e r v e a s t r V a l u e s ( 1 5, 1 15)


VBA ,
. VBA ,
:
LBound(_[,
RBound{_[,

_])
_])

LBound , a RBound .
, . . _ ,
. Long.

avarValues ( Long):
lngLBound = LBound(avarValues)
lngRBound = RBound(avarValues)


VBA . . ( ):
intNum = aintValues(16)
intNum = aintValues(12, 32, 3)

Variant

VBA Variant,
.
. V a r i a n t

1 . VBA
. ,
( ), :
Dim aintValues(l To 3) As Integer
Dim varArray
' Variant
varArray - aintValues
1

varArray(1) = 1
varArray(2) - 2
varArray(3) = 3
Variant VBA ,
.
, Variant , IsArray, :
IsArray()

Boolean: True
, False .

Array

VBA . Array. :
Array (_)

, . , Variant. Array:
Dim varArray
'
varArray = Array (1, 2, 3,- 4, 5)

( ) , .
, -


, . VBA . , Workbooks Workbook
, Worksheets Worksheet . .
VBA Collection. Collection :
Dim col As New Collection

Dim col As Collection


Set col = New Collection


Add, :
.Add

[, ][, _]

[,

_]

Add . , , .
, .
Variant.
.
_ _, , .
.
, :
col.Add " V a l u e l " ,

"Keyl"

col.Add "Value2",

"Key2"

col.Add "ValueO",

,"Keyl"


Count. Long. :
lngCount = col.Count

1 . VBA


Remove:
.Remove

Remove
. , "Value2 ". Add,
col.Remove 3

col.Remove "Key2"


item,
:
.Item

()

Item
. ,
"Keyl" ( 2) :
val = col.Item("Keyl")
val = col.Item(2)

, item Collection , "Keyl" :


val = c o l ( " K e y l " )
val = c o l (2)


VB : .

, , . ,
, () . , .


. ,
, . ,
(VB
).


VBA :
[Public I Private] Type _
!
2

End Type

Public Private ( Public):


Q Public ,
( ) ;
;
Private , , .
.
Type-End Type - . Dim, s t a t i c , Private Public , .
, , , .
, . , .

As String
_ As Date
End Type
Type
As String
As String
As String

1 . VBA
As String
_ As Date
As
End Type

VBA.

,
, , , . , :
Dim worker As

VBA , :
Dim workers(15) As

15 .

, , .



. (). :
StrFirstName = worker.
strPhone = worker.

:
strFirstName = workers(15).
strPhone = workers(15).


( ):
strName = worker..
datDate = worker.._

,
, . :


worker. = ""
worker. = ""
worker. = ". , . 100, . 5"
worker. = "(095) 200 00 00"
worker._ = "12.03.1978"
worker.. = " "
worker.._ = "15.09.2005"

, :
StrFullName=": " & worker. &", : " & worker.

( ) strFullName
": , : ".

VBA .
.
, -,
( ), -, , 167 353
ActionSave.
,
.

[Public I Private] Enum _


! [= 1]
2 [ = 2]
[ =
End Enum

Public Private , (. ).
Enum .
Enum-End Enum ,
, , .

1 . VBA
,
:
, ;
, , .
:
Enum MyEnum
valuel
value2 = 100
value3
End Enum

, .
: valuel 0, value2 100, a value3 101.



.
MyEnum:
Dim EnumValue As MyEnum
Dim EnumValues(255)

As MyEnum

,
( ) . :
EnumValue = valuel
EnumValues(100) = value3


, . :
If

EnumValue = value2 Then

...

EnumValue - value2 True, EnumValue


value2 ( 100), False .


VBA : , .
.

VBA .
VB , .
VBA : For-Next, For Each-Next
, while-Wend Do-Loop. . .

For-Next
For-Next VBA . :
For = _
[]
[Exit For]
[]
Next []

[Step ]

- . ^, _, . Next ( )
,
. - Next .
_. , , ,
_ ( ). ( )
. , .
Exit For.
Next.
For-Next,
i, j :
For i = 10 1 Step - I
For j = 1 20
For = 10 To -10 Step -2
1
-
Next k
Next j
Next i

1 . VBA

For Each-Next

For Each-Next . :
For Each In
[]
[Exit For]
[]
Next []
-, . For Each-Next , . variant.
Variant .
Next ( ) , .
Exit For,
For-Next.
For Each-Next astrStrings:
For Each varltem In astrStrings
' - varltem
Next

While-Wend
While-Wend , , .
:
While
[ ]
Wend

While-Wend ,
True (
).
while-Wend:
While i < 100


'

i = i + 3
Wend

, While-Wend .

Do-Loop
Do-Loop , While-Wend.
, :
Do [While I Until ]
[]

[Exit Do]
[]
Loop

( ):
Do
[]

[Exit Do]
[]

Loop [While I Until ]


. while ,
True, Until False.
Exit Do.
Do-Loop:
Do While i < 100
i = i + 1
Do

j = j + 5
'
Loop Until j > 200
Loop

1. VBA


VBA , , If-Then-Else Select.

If-Then-Else
VBA I f-Then-Else . :
If ! Then
[1]
[ElseIf 2 Then
[2]]
[Elself Then
[]]
[Else
[]]
End If
1 - ^ . -
, , if Elself.
, , Else (, , ).
If-Then-Else:
If intAction = 1 Then
1

res = + b
Elself intAction = 2 Then
'
res = a - b
Elself intAction = 3 Then
'
res = a * b
Else
'

End If
If-Then-Else
: ,


. , ,
intAction. , 1, 2 3, , Else.
VBA If-Then-Else:
If

Then [!)

[Else 2]

, Then.
, Else (
). ifThen-Else , ( , ). ,
VBA, , .
Else , .
if-Then-Else:
If

a = 1 Then = 2 Else

a = 1

If

a = 1 Then a = 2 Else

If

a = 1 Andb = 0 Then E l s e

l : b =b +1
a - 1

: b = b + l

Select Case
Select Case , If-Then-Else, .

If-Then-Else,
. Select Case :
Select Case _
[Case _
[]]

...

[Case Else
[]]

End Select

_ .
^ ,
. _:
| _
[, | _

_
I I s
_
| I s ] . . .

1 . VBA
.
( _^).
_ . _ _ .
is .
Select Case . VBA, i s Like. ,
_.
_
,
, Case. Case- ,
Case E l s e .

, intTestValue , 1, 2, 3 5, .
:
Select Case intTestValue
Case 1 To 3, 5
1
intTestValue,_
1, 2, 3 5
Case Is < 1, Is > 3
1

intTestValue
1 3

End Select

, 5 Case-. Select Case


VBA Case , . intTestValue, 5, Case.
Select Case . , strTestValue, :
Select Case strTestValue
Case "a" To "z"


' , strTestValue

Case "A" To "Z"
' , strTestValue

Case Else
' ,

End Select



- . GoTo GoSub-Return. VBA, , .

VBA , . ,
GoTo Go Sub. :
100:
DoSomeAction:
:
,
, , GoTo, GoSub Return (. ).

GoTo
GoTo
. :
GoTo _
, GoTo, ,
GoTo GoSub. GoTo:
= 15 + b
If < 0 Then GoTo 10
'
10:
'

1 . VBA
, GOTO
, . GoTo .

GoSub-Return
Basic GoSub Return . , Basic : , .
, , , . Return.
GoSub
( GOTO) . Return GoSub.
GoSub-Return VBA ,
.
GoSub-Return :
GoSub

[]
_:
[ ]
Return

GoSub-Return (
):
= 5
b = 4
GoSub Calculate
'
Calculate:
'
2 = 2 + 2
Return

, , -
. .


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

VBA.


VBA :
[Private

| Public]

[Static]

Sub _ [(_)]

[ ]
[Exit

Sub]

[]
End Sub

P r i v a t e Public .

P u b l i c , ,
VBA.
() .

Q P r i v a t e ,
VBA, . () .
s t a t i c ,
.
s t a t i c Dim
.
_ VBA, .
_ , .
:
[ O p t i o n a l ] [ B y V a l | B y R e f ] [ P a r a m A r r a y ] _
[= ]

[()]

[As _ ]

1 . VBA
, , . 1.7.
1.7.

Optional

, . Optional
, , ,
.

ParamArray

ByVal

ByRef

, .

ParamArray


,
Variant.
ParamArray
ByVal, ByRef Optional

As

.
,
Variant

= _

Optional

. _
.
Object
Nothing.
,

Exit Sub. ,
.
, , :
Sub ProcedureExample(ByVal intNumber As Integer, Optional fFlag = True)
1

End Sub


, , :
Sub ProcedureExample(ByVal

intNumber As Integer, ParamArray varArrayO)

'
End Sub

VBA
. , VBA ( , ).


VBA Call, :
[Call] _

[_]

_
. ,
_ .
.
,
.

Call ,
Call . Call , .
.

:
Sub ProcedureExample(ByVal intNumber As Integer, ParamArray varArray(J)
'
End Sub

1 . VBA
TestExample,
ProcedureExample. TestExample :
Sub TestExample()
1

' ProcedureExample
Call ProcedureExample(123, "1", "2", "")
'

End Sub

TestExample Call,
:
' ProcedureExample
ProcedureExample 123, "1", "2", ""
, ,
. , .

.
VBA :
[Private | Public]
) ]
[As _]

[Static] Function _ [(_-

[]
[_

[Exit Functon]
[]
[_ = ]
End Function


Function Sub,
( ) , {_ = ). ,
.
, Variant.


, . , .
, _ = Exit Function.
_ = ,
(. ).
, ( , - 1 ,
):
Function dhSQR(dblValue As Double) As Double
If dblValue < 0 Then
'
dhSQR = -1
Else
'
dhSQR = Sqr(dblValue)
End If
End Function


Call, :
Call dhSQR(16.324)

dhSQR 16.324

.
.
, , , . , dblRes
5:
dblRes - dhSQR(25)
dblRes = 1 + dhSQR(16)

VBA,
IsArray, SQR Array.

1 .


. . .


. .
, , . , , :
Sub Procedure(Optional intA As Integer = 25, Optional intB As
Integer)
'
End Sub

:
Procedure 12, 56

/
Call Procedure (12, 56)

. ,
(. ).
Procedure :
Procedure 12
Procedure , 1 2
Procedure

'
'
'


VBA
.
, , . .
Procedure :
Procedure intA:=12, intB:=56

Procedure intB:=56, intA:=12



. , , :
Procedure intB:=56

. , 8:
Function dhManyArg (Optional argl, Optional arg2, Optional , _
Optional arg4, Optional arg5, Optional , Optional arg7, _
Optional arg8)
'
End Function
,
varRes = dhManyArg(,,"text",,,,,142.23)
,
v a r R e s d h M a n y A r g ( : = " t e x t " , a r g 8 : = 1 4 2 . 2 3 )


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

TestByVal(ByVal intArg As Integer)


' - ,
intArg

End Sub
TestByVal intvalue.
i n t v a l u e
, TestByVal.

1 . VBA
:
- .
, :
Sub TestByRef(ByRef

intArg As

' - ,
i n t A r g

Integer)

End Sub

TestByRef intValue.
intValue .
. , . ,
(, ) , .

VB .


VBA . ( , variant) .
1. VBA
VarType.
. . 1.8.
1.8. , VarType

VBA

vbEmpty

Variant

vbNull

Variant Null

vblnteger

Integer

VBA
vbLong


Long

vbSingle

Single

vbDouble

Double

vbCurrency

Currency

vbDate

Date

vbString

String

vbObject

Object
(, Application)

10

vbError

11

vbBooIean

Boolean

12

vbVariant

Variant (
Variant)

13

vbDataObject

14

vbDecimal

Decimal

17

vbByte

Byte

36

vbUserDefinedType

8192

vbArray

VarType vbArray , . ,
8192 + 8 = 8200. vbVariant
vbArray
Variant.
2.
TypeName.
. (
S t r i n g ) , " i n t e g e r " , " S t r i n g " , "Workbook",
"Ob j e c t " . .
. 1.9.
1.9. , TypeName

Error

Empty

Variant

Null

Null

Unknown

Nothing

,
( Nothing)

1 . VBA
3. , , TypeOf, : TypeOf i s _. True,
, _. False. , obj Worksheet,
TypeOf obj Is Worksheet True.

TypeOf , , Nothing. _ Object, True , .


VBA .
Variant .
:
CBool()
CByte()
CCur()
CDate()
CDbl()
CDec()
CInt()
CLng()
CSng()
CStr()
CVar()

( varRes Variant, strRes string):


varRes - CDec(12.4635246) / CDec(3.14169265359)
strRes - CStr (12.3535)

varRes Decimal ( CDec


Decimal), strRes "12.3535".

CBool ,
True , . CBool . Clnt, CLng CByte .

.

/
VBA /
, .-


VBA Open,
:
Open _ For __ [Access __] []
As [#] [Len=_]

. 1.10 , .
1.10. Open

Tun_docmyna

, VBA .
: Append (
), Binary ( ), Input
( ), Output
( ) Random
( )

, .
Read ( ), Write ( )
Read Write ( ). Read
Output, Write Input,
a Read Write Input, Output


. :
Lock Read ( , ), Lock Write
( , ), Lock Read Write
( ) Shared ( ,
)

1 . VBA
1.10. Open ()

1 511,

Random.
Output, Input Append ,

D: \MyTextFile. t x t
, :
Open "D:\MyTextFile.txt"
Open "D:\MyTextFile.txt"
Open "D:\MyTextFile.txt"

For Random Access Read Write As 1 Len = 100


For Input As 2
For Output As 3

. FreeFile
VBA
. .
, ( ,
1-511).

. ,
, .
VBA FreeFile, :
FreeFile([])
Long, Open . ,
1 0. 0 ( ), 1-255. 1 256-511. , .
F r e e F i l e :
Dim hFile As Long
hFile = FreeFile '
'
Open "D:\MyTextFile.txt" For Output As hFile


Open
, . (
) ,
. , , .
VBA : Reset Close. :
Reset
Close

[[#]

[,

[#]]...]

Reset ,
Open. Close ,
:
Close 1, #3, hFile

close
, .


VBA . , : , .


, , . 1.11.
1.11.

Write , _
[]

Output,
Append

,
,
,
( ).

,
.
.

1 . VBA
1.11. ()

Print , _
[]

Output,
Append

,
,
, .


.

Input , _

Input

,
Write.
, ,

Line Input , _

Input

.
,
Print

, :
Sub WriteToFile()
Open "D:\MyTextFile.txt" For Output As 1
'
.

Write #1, "", "Value", 154.32


Print #1, "1", "2", 14.28464
Close 1

End Sub

, :
Sub ReadFromFile()
Dim strVall, strVal2, dblNumber
Dim strString
Open "D:\MyTextFile.txt" For Input As 1
'
Input #1, strVall, strVal2, dblNumber
Line Input #1, strString
Close 1
End Sub

/
. 1.11 , VBA
Input, :
I n p u t (_,

[#] )

10 :
Sub TestlnputO
Dim strText As String
Open "D:\MyTextFile.txt" For Input As 1
' 10
strText = input(10, 1)
Close 1
End Sub


(Random) ,
.
, . ( ).
VBA Put Get :
Put
Get

[#],
[#],

[_] ,
[_] ,

Put
_. , .
Get _ . , .
, Put, , :
Type Record
intVal As Integer
strName As String * 100
End Type
Sub TestRandomAccess()
Dim reel As Record, rec2 As Record
' reel rec2 ...
Open "D:\MyRandomAccessFile.txt" For Random Access Read Write
As 1 Len = Len(recl)

1 . VBA
'
Put 1, , reel
Put 1, , rec2
'
Get 1, 2, 2
Get I, I, reel
Close 1
End Sub


(Binary)
, 1 . Put Get,
. input,
.


, . , , . EOF LOF:
EOF()
LOF()

EOF True, ,
, False . EOF False, . , Output, EOF True.
LOF , .
Long, .


VBA Loc
Seek, :
Loc()
Seek()

, . .


Loc , Random,
. , Binary, . , , , 128.
Seek , Random, ,

/. , .


VBA MsgBox. (, ). MsgBox :
MsgBox (_[,

] [, ]

[, _,

_])

_ ,
, , _
. _, _, , .
,
. . 1.12 , Or.
1.12. ,
VBA

vbOKOnly

OK

vbOKCancel

Cancel ()

vbAbortRetrylgnore

Abort (), Retry


() Ignore ()

vbYesNoCancel

Yes (), No ()
Cancel ()

vbYesNo

Yes () No ()

vbRetryCancel

Retry () Cancel
()

vbCritical

16

vbQuestion

32

vbExclamation

48

vblnformation

64


>

1 . VBA
1.12. , ()
VBA

vbDefaultButtonl

vbDefaultButton2

256

vbDefaultButton3

512

vbDefaultButton4

768

vbApplicationModal
vbSystemModal

( )

4096

vbMsgBoxHelpButton

16384

Help ()

vbMsgBoxSetForeground

65536

vbMsgBoxRight

524288

vbMsgBoxRtlReading

1048576

, , . ,
MsgBox, . 1.13.
1.13. , MsgBox
VBA

vbOK

OK

vbCancel

Cancel ()

vbAbort

Abort ()

vbRetry

Retry ()

vblgnore

Ignore ()

vbYes

Yes ()

vbNo

No ()


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


VBA ,
, , .


VBA On Error, ,
. :
On Error GoTo
On Error Resume Next
On Error GoTo 0
On Error (. ).
.
: , , , .
on Error ,
.


, :
On Error GoTo , . , (, )
Resume, . , ,
. Resume:
Resume

[0]

Resume N e x t
Resume

Re sume [ 0 ] , . Resume Next, ,


. Resume Resume .
, E r r ErrObject.

1 . VBA
( ,
. .).
, , .
(
:):
Function dhWriteToFloppy(strText

As String)

As Boolean

'
On Error GoTo ErrHandler
1

Open "A:\Text.txt" For Output As 1


Write #1, strText
Close 1
'
dhWriteToFloppy = True
ExitFunc:
'
Exit Function
ErrHandler:
' , -
Close 1
Dim strErrMessage As String
'
Select Case Err.Number
Case 71
strErrMessage = " "
Case 70
strErrMessage = " "
Case 61
strErrMessage = " "
Case Else
strErrMessage = Err.Description
End Select
1

MsgBox strErrMessage, vbExclamation, ""


'
dhWriteToFloppy - False
Resume ExitFunc
End Function

VBA
, True. , , False. dhWriteToFloppy ,
( )
, Exit Function.

VBA
VBA -,
. VBA-
,
.

VBA
VBA (
C++), .
VBA , , , . Insert Class Module
( ) Visual Basic. Properties (), . 1.3.
Properties - Class 1
j Class 1 ClassModule

\rj

Alphabetic } Categorized j

. 1.3.

, ,
. ciassl. , .

1 . VBA


VBA .
- ( Public). c i a s s l , , - :
Public strTag As String

, - .
,
.
, Property.
, Property Get:
[Public | Private]
[As _]
[]

[Static] Property Get _

([])

[_
= ]
[Exit Property]
[]
[ = ]
End Property

, , , Property Let:
[Public | Private] [Static] Property Let _ ([,])
[]
[Exit Property]
[]
End Property

, , , Property Set:
[Public I Private] [Static] Property Set _ {[, ])
[]
[Exit Property]
[ ]
End Property

Property ( -

VBA
Property Let Property Set) ( Property Get).
ObjectRef ObjectType
Classl ( - ob j Ref ):
Private objRef As Object
Property Set ObjectRef(objNewRef As Object)
'
Set objRef = objNewRef
End Property
Property Get ObjectRef() As Object
'
Set ObjectRef = objRef
End Property
Property Get ObjectType() As String
'
ObjectType = TypeName(objRef)
End Property


, , . ( Public) ( Private).
Class 1, :
Sub ShowInfoO
' strTag _
,
MsgBox " s t r T a g - " S s t r T a g & vbCrLf S
"Object type = " & ObjectType
End Sub


, VBA . , VBA.
Classl. :
Dim obj As C l a s s l

1 VBA
Set:
Set

obj = New Classl

:
Dim

obj As New C l a s s l

, :
obj.strTag = " "
Set obj.ObjectRef = Nothing
MsgBox obj.ObjectType
obj.Showlnfo
,
Classl:
Sub

TestClass ()
'
Dim obj As New Classl
'
Set obj.ObjectRef = New Collection
obj.strTag " Collection"
'
obj.Showlnfo
End Sub

,
. 1.4.
Microsoft Excel
strTag Collection
Object type = Collection ; .:
'
OK

1.4.

, TestClass
c l a s s l . , obj
. ( ) , .

API- VBA
, VBA, API- Windows. -

API- VBA

. Windows
API (Application Programming Interface) 1000 .

API-
API- VBA, Declare:
[Public I Private] Declare Function Lib ""
[Alias ""] [([])}
[As _]
, API- :
[Public I Private] Declare Sub Lib "" [Alias ""] _
[([] ) ]
. Public
P r i v a t e API-
. ,
API- Private. Declare . 1.14.
1.14. Declare

,
API- .
Declare Alias ,
API-
( ). Alias ,
,

(DLL), ,
"User" "User.dll"

Declare Alias,
API- DLL.
Alias "" API-
VBA ,

, .
VBA.
API- Any

API-

API-
:
Declare Function GetUserNameA Lib "advapi32.dll"
(ByVal lpBuffer As String, nSize As Long) As Long

1 . no VBA
:
Declare Function GetUserName Lib "advapi32 . d l l " Alias "GetUserNameA" _
(ByVal lpBuffer As S t r i n g , nSize As Long) As Long


GetUserNameA. GetUserName.

API-
API-, Declare Function,
:
C a l l . API-
Declare Sub,
Call ( ).
, , API- GetUserName
:
1

API-

Declare Function GetUserName Lib "advapi32 . d l l " A l i a s "GetUserNameA" __


(ByVal lpBuffer As S t r i n g , nSize As Long) As Long
Sub UserName()
Dim
'

strBuffer

strBuffer
'

As

String

= Space (100)

( API-).
,
strBuffer

If

GetUserName(strBuffer,
1

100)

Then

MsgBox

RTrim(strBuffer)

Else
MsgBox "He
End
End

"

If

Sub

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

Excel

Excel
. 1.5 , VBA.

. 1.5. Microsoft Excel

, () ,
VBA, Application. , Excel, , , , , , , ,
Application Excel.

1 .
Application .
, ( Assistant ),
, .
:
Cells , ;
CommandBars , ;
Q Comments , ;
Q Chartobjects , - ( );
charts , ;
Dialogs Excel;
sheets , ;
Q windows Excel ;
Workbooks , Excel ;
Worksheets , .
Selection ( , Application)
, . Selection . , (, , Selection Range).
Range. , .
.
Excel
.

Excel
Excel VBA Application,
Application. , :
Set objSel - Application.Selection

, Application ,
:
Set objSel = Selection

Excel
.
Excel, Workbooks, Worksheets ,
VBA, :
W o r k s h e e t s (1) .Name - " S h e e t

1"

Application
, , , . . ( Application, ,
).
, :
ActiveCell.Value = 15

ActiveSheet.Name = "This sheet is now activated"

Microsoft Excel



Microsoft Excel , (). , .


, Microsoft Excel
( XLS),
. , . .

Excel

Excel. , Excel ( ),
.
XLStart.
Microsoft Office (, : \Program F i l e s \ M i c r o s o f t
Office\OfficelO\XLStart).
Excel . .
1. , Excel.
2.
Windows ( C:\Program F i l e s \ M i c r o s o f t
Office\OfficelO\
XLStart), .
XLW (
). Excel , .

, . , ,
. , , .

,

2. Microsoft Excel
. , (, , ). . 2.1.
;![]

| D || \
. 2.1.
(, Word).
Word , ( ) .

Excel, ( ),
. , . 2.2.
S i

; D fi|jf ] jjg| f | j . #
. 2.2.


. 2.3.
[|]

. 2.3.

Excel
, , , , . , .


( ) p e r s o n a l . xls. .
1. .
2. .
3. XLStart (, C:\Program Files\Microsoft Of fice\Of ficelOX
XLStart), p e r s o n a l . x l s .
4. .
5. .
.

Excel.

/.



, , Excel . .
1. .
2.
.
3. 2 .
4. 1,
.
5. .
6. Windows .
.


VB, . ,
2.1.

2. Microsoft Excel


http://www.piter.com/download/978546901223/.

2.1.
Sub

DuplicateBookO
Dim
'

avarFileNames

As

Variant

avarFileNames = A r r a y ( " : \ " &


ActiveWorkbook.Name, " D : \ " & ActiveWorkbook.Name)
'

ActiveWorkbook.SaveAs

avarFileNames

End Sub


SaveAs Workbook .
C:HD:.

,
avarFileNames. To D:.

,

,
, .1.
( 2.2).
2.2. ,
Sub SaveAsDateO
Dim

s t r D a t e As

String

' ""
s t r D a t e = Format(Now(),
'

ActiveWorkbook.SaveAs
End

"ddmmyy")


ActiveWorkbook.Path

& " \ " & strDate

Sub

, , (, 140705.xls).


, . , ,
(,
). VBA , 2.3.
2.3.
Sub NewOneSheetBook()
Workbooks.Add xlWBATWorksheet
End Sub
, .
.


,
.
,
: Password , s t r u c t u r e
( ) windows (, ). ,
.
2.4 ( ).
2.4.
Sub Worksheet_BeforeRightClick(ByVal Target As Range,
Cancel As Boolean)
If Target.Address = "$D$2" Then
' ( "123", _
_
)
ThisWorkbook.Protect "123", True, True
'

Cancel = True
E l s e l f Target.Address = "$E$5" Then
' (
)

2. Microsoft Excel
ThisWorkbook.Unprotect

"123"

Cancel = True
End If
End Sub

D2, 5.

( ).
, ( 2.5;
).
2.5.
Sub Workbook_BeforePrint(Cancel As Boolean)
1

True Excel

Cancel = True
End Sub


.
Ctrl+P .

. , 2.6 (
).
2.6.
Sub Workbook_BeforeClose(Cancel
If

Range("Al").Value
1

As Boolean)

" " Then

. Excel

Cancel - True
End

If

End Sub

, 1 .

, . .,
. , . ( 2.7).
2.7.
Sub EraseNames()
Dim nmName As Name
Dim strMessage As String
'
If ThisWorkbook.Names.Count = 0 Then
'
MsgBox " "
Exit Sub
End If
1

,

For Each nmName In ThisWorkbook.Names
With nmName
'

strMessage = " " & .Name S " ? " & vbCr &
" " & .RefersTo
If MsgBox(strMessage, vbYesNo + vbQuestion) = vbYes Then
'
.Delete
End If
End With
Next
End Sub
,
.
,
( ) . .
.

2. Microsoft Excel
,
, .


, ,

( ).
, 2.8.
2.8.
Sub SortSheets()
Dim astrSheetNames () As String '
Dim intSheetCount As Integer
Dim i As Integer
Dim objActiveSheet As Object
1

-
If ActiveWorkbook Is Nothing Then Exit Sub
'
If ActiveWorkbook.ProtectStructure Then
'
MsgBox " " & ActiveWorkbook.Name &
" . .",
vbCritical
Exit Sub
.
End If
'
Set objActiveSheet = ActiveSheet
1

Ctrl+Pause Break
Application.EnableCancelKey = xlDisabled
'
Application.ScreenUpdating = False
intSheetCount = ActiveWorkbook.Sheets.Count
' astrSheetNames
ReDim astrSheetNames(1 To intSheetCount)
For i = 1 To intSheetCount
astrSheetNames(i) = ActiveWorkbook.Sheets(i).Name
Next i


Call Sort(astrSheetNames)
'
For i = 1 intSheetCount
ActiveWorkbook.Sheets(astrSheetNames(i)).Move
ActiveWorkbook.Sheets(i)
Next i
'
objActiveSheet.Activate
'
Application.ScreenUpdating = True
1

Ctrl+Pause Break

Application.EnableCancelKey = xllnterrupt
End Sub
Sub Sort(astrNames() As String)
' ( )
Dim i As Integer, j As Integer
Dim strBuffer As String
Dim fBuffer As Boolean
For i = LBound(astrNames) To UBound(astrNames) - 1
For j = i + 1 To UBound(astrNames)
If astrNames(i) > astrNames(j) Then
' i- j-
strBuffer - astrNames(i)
astrNames(i) = astrNames(j)
astrNames(j) = strBuffer
End If
Next j
Next i
End Sub

, . . , .
Ctrl+Pause Break. ,
, , ,
.

2. Microsoft Excel
,
. (
Sort) . , ( ).
( )
, . ,
( )
.
( 2.9), .
2.9.
Sub SortSheets2()
Dim astrSheetNames () As String '
Dim intSheetCount As Integer
Dim i As Integer
Dim objActiveSheet As Object
' -
If ActiveWorkbook Is Nothing Then Exit Sub
'
If ActiveWorkbook.ProtectStructure Then
'
MsgBox " " & ActiveWorkbook.Name &
" . .",
vbCritical
Exit Sub
End If
'
Set objActiveSheet = ActiveSheet
' Ctrl+Pause Break
Application .EnableCancelKey = xlDisabled
'
Application.ScreenUpdating - False
With ActiveWorkbook
1
"" ( )
On Error Resume Next


If .Sheets("") Is Nothing Then
.Sheets.Add.Name = ""
End If
On Error GoTo 0
' "" ( "")
intSheetCount = .Sheets.Count
For i = 1 To intSheetCount
.Sheets("") .Cells(i, 1) = .Sheets (i) .Name
Next i
1

"" _

.Sheets("").Range("Al").Sort
Keyl:=.Sheets("").Range("Al"),
Orderl:=xlAscending
1


ReDim astrSheetNames(1 intSheetCount)
For i = 1 To intSheetCount
astrSheetNames(i) = .Sheets("") .Cells (i, 1)
Next i
'
For i = 1 To intSheetCount
.Sheets(astrSheetNames(i)).Move

.Sheets(i)

Next i
End With
'
objActiveSheet.Activate
'
Application.ScreenUpdating = True
' Ctrl+Pause Break
Application.EnableCancelKey - xllnterrupt
End Sub

, , Excel
.
,
.

2. Microsoft Excel

,
256
, Excel , 256 . , , ,
. , 2.10 (
VBA).
( 256 )
( 256 ). 1- 256- , 257- 512- . .
.
, .
2.10.
Sub ImportWideSheet()
Dim rgRange As Range
Dim lngRow As Long
Dim intCol As Integer
Dim i As Integer
Dim strLine As String
Dim strCurChar As String * 1
Dim strCellValue As String

Dim wshtCurrentSheet As Worksheet

'
'
'
'
( )
' _
_

' , _

'
Application.ScreenUpdating = False
'
Workbooks.Add xlWorksheet
Set rgRange = ActiveWorkbook.Sheets(1).Range("Al")
' (
)
Open ThisWorkbook.Path & "\Primer.txt" For Input As #1
Line Input #1, strLine
'

For i = 1 Len (strLine)


strCurChar = Mid(strLine, i, 1)

If intCol 0 And intCol Mod 256 = 0 Then


1
- _

Set wshtCurrentSheet = ActiveWorkbook.Sheets.Add(,
ActiveWorkbook.Sheets(ActiveWorkbook.Sheets.Count))
Set rgRange = wshtCurrentSheet.Range("Al")
intCol = 0
End If
' -
If strCurChar = "," Then
'
rgRange.Offset(lngRow, intCol) = strCellValue
intCol = intCol + 1
strCellValue = ""
Else
'

strCellValue - strCellValue & Mid(strLine, i, 1)


' -
If i - Len(strLine) Then
' -
rgRange.Offset(lngRow, intCol) = strCellValue
intCol = 0
strCellValue = ""
End If
End If
Next i
'
Do Until EOF(l)
Set rgRange = ActiveWorkbook.Sheets(1).Range("Al")
lngRow = lngRow + 1
intCol = 0
Line Input #1, strLine
'
For i = 1 To Len(strLine)
strCurChar = Mid(strLine, i, 1)
1
-

2. Microsoft Excel
If intCol <> 0 And intCol Mod 256 = 0 Then
' -

Set wshtCurrentSheet = ActiveWorkbook.Sheets.Add (, _
ActiveWorkbook.Sheets(ActiveWorkbook.Sheets.Count))
Set rgRange = wshtCurrentSheet.Range("Al")
intCol = 0
End If
' -
If strCurChar = "," Then
1

rgRange.Offset(lngRow, intCol) = strCellValue


intCol = intCol + 1
strCellValue = ""
Else
' _

strCellValue = strCellValue & Mid(strLine, i, 1)


' -
If i = Len(strLine) Then
' -

rgRange.Offset(lngRow, intCol) = strCellValue


strCellValue = ""
End If
End If
Next i
Loop
' He
Close #1
'
Application.ScreenUpdating = True
End Sub

ImportWideSheet.
Primer. txt, , .
Excel. , 256 , -


( ,
).
, , . .
,
,
.


. .
,

. ,
255.

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

URL-
URL- . , .
.
1. Internet Explorer.
2. Excel, , ,
Ctrl+K. .
3. ALt+Tab Internet Explorer.
4. Alt+Tab Excel.
5. .
- .

2. Microsoft Excel


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

:
| !

:
I = 1! $$8: $$ 11
. 2 . 4 .


.
.
Q 255 .

,
. ,
.

, ( ).

, Ctrl+G. , . 2.5.
( !) .
Excel .

[:
$*15
!

:
1 1
'

.., j

. 2.5.


, , .
( ).
1. .
2. 2 5 100.
3. 1 2 =2 ! 5.
4. Enter.
2, 1, 100 ( , 5
2).



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


Excel . , .
, .

2. Microsoft Excel
,
, , (
). , Ctrl+Shift+, .

( ). , .


, , 2.11.
2.11.
Sub NewSheet()
Worksheets.Add
End Sub
.


. ( 2.12).
2.12.
Sub Worksheet_Bef oreRightClick (ByVal Target As Range, Cancel As Boolean)
S t a t i c intCount As Integer
'
Dim x As I n t e g e r , As I n t e g e r
'
Cancel = True
'

= Target.Left
= Target.Top
intCount = intCount + 1
ActiveSheet.Shapes.AddTextbox(msoTextOrientationHorizontal,
x, y, 35, 20).TextFrame.Characters.Text = intCount
End Sub
, .



. (, 1, 2 . .).
.

,

. ,
2.13.
2.13.
Sub AddPageHeader()
Dim i As I n t e g e r
With ThisWorkbook
'
For i = 1 .Worksheets.Count - 1
.Worksheets(i).PageSetup.LeftHeader .FullName
.Worksheets ( i ) .PageSetup.CenterHeader = Worksheets ( i ) .Name
.Worksheets(i).PageSetup.RightHeader = Now()
Next
End With
End Sub
, .

( ),
, .
.



, . dhSheetExist, 2.14. , , , .
2.14.
Function dhSheetExist(strSheetName As String) As Boolean
Dim objSheet As Object

2. Microsoft Excel

On Error GoTo HandleError ' HandleError


1

objSheet = ActiveWorkbook.Sheets(strSheetName)
' -
dhSheetExist = True
Exit Function
HandleError:
1

, ,
dhSheetExist = False
End Function
, , ( ActiveWorkbook. Sheets (strSheetName) ) ,
, HandleError. ,
. ,
( End
Function) .
( ) .
( ), . , : , , .

,
Excel ,
(,
).
, 2.15.
2.15.
Sub I s S h e e t P r o t e c t e d O
'

If

Worksheets (1) . P r o t e c t C o n t e n t s Then


MsgBox " "

Else
MsgBox " "
End
End

Sub

If


, .
.

?
, :
?
, 2.16 ( VBA).
2.16.
Sub GetPrintPagesCount()
Dim

wshtSheet

Dim

intPagesCount As

'

As Worksheet
Integer

For

Each wshtSheet

In Worksheets

intPagesCount=intPagesCount+ (wshtSheet.HPageBreaks.Count+1) *
(wshtSheet.VPageBreaks.Count + 1)
Next
MsgBox " : " & intPagesCount
End

Sub

(
HPageBreakers .Count VPageBreakers .Count ).
, ,
( : (wshtSheet. HPageBreaks . Count + 1) *
(wshtSheet.VPageBreaks.Count+1)).

, .



, . ( ). .

2. Microsoft Excel
, 1
(), c B l n o B H . , . ,
. , . ,
. , 2.17 ( ).
2.17.
Sub Worksheet_Change(ByVal Target As Range)
Dim rgData As Range
Dim c e l l As Range
Dim dblMax As Double, dblMin As Double, dblAverage As Double
'
Set rgData = Range("B2:B11")
' , _

If Not ( A p p l i c a t i o n . I n t e r s e c t ( T a r g e t , rgData) I s Nothing) Then


If Application.WorksheetFunction.CountA(rgData) > 0 Then
'
' ,

dblMin = Application.WorksheetFunction.Min(rgData)
dblMax = Application.WorksheetFunction.Max(rgData)
dblAverage = Application.WorksheetFunction.Average(rgData)
'
_
, _

For Each c e l l In rgData
If c e l l . V a l u e = dblMax Then
'
c e l l . F o n t . B o l d = True
c e l l . F o n t . C o l o r = RGB(255, 0, 0)
E l s e l f c e l l . V a l u e - dblMin Then
'
c e l l . F o n t . B o l d = False
c e l l . F o n t . C o l o r - RGB(0, 0, 255)


Else
cell.Font.Bold

= False

c e l l . F o n t . C o l o r = RGB(0, 0,
End
If

0)

If
cell.Value > dblAverage Then
'

cell.Interior.Color

= RGB(255, 255,

0)

Else
cell.Interior.Colorlndex
End

= xlNone

If

Next
Else
rgData.Interior.Colorlndex
End
End
End

= xlNone

If

If

Sub

. .


, .


, , Ctrl+D.
, . .
1 A3 5, 10 15 , Bl, B2
30, 50 70. 1 = (1: 1)
Enter
35. 2 Ctrl+D, 60 ( 2 2), : = (2 : 2). Ctrl+D : = (A3: ), 8 5.


Microsoft Excel
. .

2. Microsoft Excel
, :5 1:4.
:5, , Ctrl,
1:4. , , Al no A4
. 4 Enter,
. :5 Enter 1.
.
. 2.18.
2.18.
Sub S e t C e l l D a t a O
' A3 4
Range("A3") = " A3"
Range("B4")
End Sub

= " 4"

A3 A3, 4 4.
( 2.19) .
2.19.
Sub SetCellFormula()
' 6 "=5+5"
Range("A6") = "=5+5"
End Sub
5
5. Range ("") = "=5+5" , , Range ("A2:A5") = 2, 2:5 2.


Excel .
, Excel ,
: . , 2/5 Enter 2. ,
7/92 .92. ,
, 2/5. Excel , Enter 2/5.



. &. ,
.
, : , . . 1
, 1 . 1 ( ).
1 : =Al&" "&BI! Enter .
. , 1 : =AI&" "&1,
.

, .
2 2 , 2 Ctrl+D.
1
, 2 .


, , . , ,
(, ). , 2.20.
2.20.
Sub SelectCellRange()
Dim strSelTop As String, strSelBottom As String
1

strSelBottom = ActiveCell.Address
strSelTop Cells (1, ActiveCell.Column) .Address
' ( )
Range(strSelTop & ":" & strSelBottom).Select
End Sub

11

2. Microsoft Excel

,
( , ).


, , .
, , 2.21.
2.21.
Sub FindEmptyCell()
'
Do While Not IsEmpty(ActiveCell.Value)
ActiveCell.Offset(1, 0).Select
Loop
End Sub

, . , , , , , .



( ). ,
, , , . , 2.22.
2.22.
Sub FindMaxValue()
On Error Goto NoCell
If Selection.Count > 1 Then
1

Selection.Find(Application.Max(Selection)).Select
Else
1

ActiveSheet.Cells.Find(Application.Max(ActiveSheet.Cells)).Select
End If
Exit Sub


NoCell:
MsgBox " "
End Sub
,
. ;
, . ,
(
).


,
- . 2.23
, .
2.23.
Sub ReplaceValues()
Dim cell As Range
' _
( -1,
- 1)
For Each cell In Range ("Cl:C3") .Cells
If cell.Value < 0 Then
cell.Value = -1
Elself cell.Value > 0 Then
cell.Value = 1
End If
Next
End Sub
1:. 1, - 1 .
,
.


.
.

2. Microsoft Excel

mill

, 1 25, 2 43, 1 = (1: 2) (. 2.6).

1
2

\
43!

* =(1 2)
681
|

. 2.6.
1. , ( ), .
; ; ; (. 2.7).

j |

0
0,00
i # ##0
# ##0,00
# ##0__. ;-###0j3 .
: # ##0_ ;]-# ##0_ .

'

.
, ,
.^

OK

. 2.7.
0 1
(. 2.8).
=(1:2)

. 2.8.


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


.
, , , Enter.
. .
1. ( ).
2. .
3. CtrL+Enter.
.


Excel , .
, , , Shift,
. (. 2.9).

"
*

. 2.9.
,
,
. ,

2. Microsoft Excel
(, -, - ).
,
. Windows,
( ).
.
Shift
. .
, Excel,
, .


, . , .
1. (
).
2. , .
3. .
4. .
5. .
6. (
, , . . 1).
7. , (
).
8. .

, , .


, .


, - 1 100.
, 2.24 ( VBA).
2.24.
Sub FillCells()
Dim intStartVal As Integer
Dim intStep As Integer
Dim intEndVal As Integer
Dim intVal As Integer
Dim intCellOffset As Integer

'
'
'
'
'

'
intStartVal = 1
intStep - 1
intEndVal = 1 0 0
1

1 100
For intVal intStartVal To intEndVal Step intStep
ActiveCell.Offset(intCellOffset, 0).Value = intVal
intCellOffset = intCellOffset + 1
Next intVal
End Sub

, ( ), 1 100 (
).

, . , ( 2.25).
2.25.
Sub FillCells()
Dim intStartVal As Integer
Dim intStep As Integer
Dim intEndVal As Integer

'
'
'

Dim intVal As Integer


'
Dim intCellOffset As Integer '
Dim intCellStep As Integer
'

2. Microsoft Excel
'
intStartVal
intStep = 3
intEndVal =
intCellStep


= 3
30
= 3

' 3 30
For intVal = intStartVal To intEndVal Step intStep
ActiveCell.Offset(intCellOffset, 0).Value = intVal
intCellOffset = intCellOffset + intCellStep
Next intVal
End Sub

3 30, : 3 ( ), 6, 9,12,..., 27, 30.


, , 10 5 , ,
1 50.
V B A ( 2.26).
2.26.
Sub FillCellRect
Dim lngRows As Long, intCols As Integer '

Dim lngRow As Long, intCol As Integer
'
Dim lngStep As Long, lngVal As Long
'
lngVal = 1
lngStep = 1
' ,

lngRows = Val(InputBox(" "))
intCols = Val(InputBox(" "))
1


Application.ScreenUpdating = False
1


For lngRow = 1 lngRows


For

intCol = 1 intCols
ActiveCell.Offset(lngRow,

intCol).Value

= lngVal

ingVal = lngVal + lngStep


Next intCol
Next lngRow
'

Application.ScreenUpdating
End

= True

Sub

F i l l C e l l R e c t .
,
( 10).
0 , ( 5) . ,
, (
). ,
, ( lngVal = 1, , , 1) .


. , ,
. ( VBA) ( 2.27).
2.27.
Sub FillCellRectl()
Dim lngRows As Long, intCols As Integer
Dim lngRow As Long, intCol As Integer
Dim lngStep As Long, lngVal As Long
Dim alngValuesf) As Long
Dim rgRange As Range
'
lngVal = 1
lngStep - 1
' ,

lngRows = Val(InputBox(" "))
intCols = Val(InputBox(" "))

2. Microsoft Excel
ReDim alngValues(l To lngRows, 1 To intCols)
Set rgRange = ActiveCell.Range(Cells(1, 1), _
Cells(lngRows, intCols))
1

alngValues
For ingRow = 1 To lngRows
For intCol = 1 To intCols
alngValues(IngRow, intCol) = lngVal
lngVal = lngVal + lngStep
Next intCol
Next IngRow
1

rgRange.Value = alngValues
End Sub

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


Microsoft Excel, 2000,
, :
Q http://
Q www.
ftp://
Q mailto:
Q file://
Q news:
mail@pochta
. , , , ("). Enter ,
. .


. 2.28 ,
.
2.28.
Sub UpdateTimeO
Dim varNextCall As Variant
'
C e l l s ( 1 , 1).Value = Now
' varNextCall ,
( 1 )
varNextCall TimeSerial(Hour(Now), Minute(Now), Second(Now) + 1)
' Excel
Application.OnTime varNextCall, "UpdateTime"
End Sub
1. ,
.

, .
, ( ). 2.29
, .
2.29.
Sub Clock()
' Excel, Alarm 20:55
Application.OnTime TimeValue("20:55:00"), "Alarm"
End Sub
Sub Alarm()
MsgBox " !!!"
End Sub
Clock (20 55 ) !!!. , .

2. Microsoft Excel


VBA, - . .


,
, ,
.
( 2.30).
2.30.
Sub

ReplaceCellsData()
Dim c e l l
'

As

Range

For

Each c e l l
If

In

Gl:K2 0

[Gl:K20]

c e l l . V a l u e Like "**"

Then

c e l l . V a l u e = ""
cell.Interior.Color

= RGB(255, 255,. 0)

Else
cell.Interior.Color
End

= RGB(255,

255,

255)

If

Next
I

End Sub

,
G1:K2O, , . ( - , ).


,
.
( 2.31), .
2.31.
Sub Search ()
Dim rgResult As Range
' 1:20
Set rgResult = Range("Bl:B20").Find(9999, , xlValues)
If rgResult Is Nothing Then
MsgBox " "


Else
MsgBox rgResult.Address
End If
End Sub
1:2,
9999. . , .


, . .
, , ( 2.32).
2.32.
Sub FindAndSelect()
Dim strStartAddr As String '

Dim rgResult As Range


'
Set rgResult = Range("Bl:B10").Find("", , xlValues)
If Not rgResult Is Nothing Then
' (
)
strStartAddr = rgResult.Address
End If
Do While Not rgResult Is Nothing
'
rgResult.Interior.Color = RGB(255, 255, 0)
'
Set rgResult = Range("Bl:BIO").FindNext(rgResult)
If rgResult.Address = strStartAddr Then
1

Exit Do
End If
Loop
End Sub

1: . , , (
rgResult. Interior. Color = RGB (255, 255, 0)).

2. Microsoft Excel


:
, , .
2.33 , .
2.33.
Sub RangeBorder()
Dim rgRange As Range
Set rgRange = Range("B2:D5")
'
With rgRange.Borders(xlEdgeTop)
.Weight = xlThick
.LineStyle = xlContinuous
.Color = RGB(0, 0, 255)
End With
'
With rgRange.Borders(xlEdgeBottom)
.Weight = xlMedium
.LineStyle = xlDash
.Color = RGB(255, 0, 255)
End With
End Sub
, .


,

, . , , 2.34 ( , ).
2.34.
Sub Worksheet_SelectionChange(ByVal
1

Target As Range)

MsgBox Target.Address() & vbCr &


Target.Address(RowAbsolute:=False) & vbCr &
Target.Address(ReferenceStyle:=xlRlCl) & vbCr &
Target.Address(ReferenceStyle:=xlRlCl,
RowAbsolute:=False, ColumnAbsolute:=False,
RelativeToWorksheets(1) . C e l l s (2, 2))
End Sub


, 9,
:
$$9
$9
R9C5
R[7]C[3]
,
. , , 2 (.
RelativeTo).



, , , .
,
2.35.
2.35.
Sub CreateComments()
Dim c e l l As Range
' _
, ""
For Each c e l l In Range("Bl:B100")
If c e l l . V a l u e Like "**" Then
cell.ClearComments
cell.AddComment " "
End I f
Next
End Sub
1:1.
, ,
. ,
. , , .
, .

2. Microsoft Excel


, ( ). ,
, ( 2.36).
2.36.
Sub FillRange()
'
With Range("1:10")
' -
.Interior.Pattern = xlPatternChecker
' -
.Interior.PatternColor = RGB(0, 0, 255)
' -
.Interior.Color = RGB(255, 0, 0)
End With
End Sub

1:10
.

,
. , :
. .


,
. , 2.37.
2.37.
Sub DialoglnputData()
DimintMinAs Integer, intMaxAs Integer
Dim strlnput As String
Dim strMessage As String
Dim intValue As Integer

'
'


intMin = 1
'
intMax = 50 '
strMessage = " " & intMin & " " & intMax
' ( ,
)
Do
s t r l n p u t = InputBox(strMessage)
If s t r l n p u t = " " Then Exit Sub
'
' ,
If IsNumeric(strlnput) Then
intValue = CInt(strlnput)
' ,
If intValue >= intMin And intValue <= intMax Then
'
Exit Do
End If
End If
'
strMessage = " ." & vbNewLine &
" " & intMin & " " & intMax
Loop
'
ActiveSheet.Range("Al").Value = s t r l n p u t
End Sub

DialoginputData. .
1 50 (
).
, , . 1
ActiveSheet.Range ("Al") .Value = s t r l n p u t . 1
, , 1: 5, .


-
, . (
).
- (, 1:10)
inputRange. VBA , 2.38.

2. Microsoft Excel
2.38.
Sub Worksheet_Change(ByVal Target As Excel.Range)
Dim rglnputRange As Range
Dim cell As Range
Dim strMessage As String
Dim varResult As Variant
1

,
Set rglnputRange - Range("Al:E10")
1
,

For Each cell In Target
'
If Union(cell, rglnputRange).Address = rglnputRange.Address Then
'
varResult = IsCellDataValid(cell)
If varResult = True Then
'
Exit Sub
Else
(
'
strMessage " " & cell.Address(False, False) & ":"
S vbCrLf & vbCrLf & varResult
MsgBox strMessage, vbCritical, " "
'
Application.EnableEvents = False
cell.ClearContents
cell.Activate
Application.EnableEvents = True
End If
End If
Next cell
End Sub
Function IsCellDataValid(cell As Range) As Variant
' True,
1 12.

' ,
If Not WorksheetFunction.IsNumber(cell.Value) Then
IsCellDataValid = " "
Exit Function
End If


' ,
If Int(cell.Value) <> cell.Value Then
IsCellDataValid = " "
Exit Function
End If
'
If cell.Value < 1 Or cell.Value > 12 Then
IsCellDataValid = " 1 12"
Exit Function
End

If

'
IsCellDataValid = True
End Function
1:1
, 1 12. (, ) ).

. , 1
12, ,
1 12.


, ,
. , . , , .
, .
. .
. .
, , ,
. , (
) 2.39.
2.39.
Sub Streamlnput()
Dim strDate As String

2. Microsoft Excel
Dim strSum As String
Dim lngRow As Long
' ( ,
"" )
Do
lngRow = Range("A65536").End(xlUp).Row + 1
1

strDate = InputBox(" ")
If strDate = " " Then Exit Sub
'
strSum = InputBox(" ")
If strSum = " " Then Exit Sub
1

Cells(lngRow, 1) = strDate
Cells(lngRow, 2) = strSum
Loop
End Sub
streamlnput .
,
.
1 1 (,
) . , ( ),
( ). 2 2 , ( A3 ) . .
Cancel.


, .
.
VBA , ( 2.40).
2.40.
Sub NegSelect()
Dim cell As Range
' ,


For Each cell In Selection
If cell.Value < 0 Then
cell.Interior.Color = RGB(255, 0, 0)
Else
cell.Interior.Colorlndex = xlNone
End If
Next cell
End Sub

NegSelect.
, , .
,
, .


, , . . VBA
, 2.41.
2.41.
Sub TypeOfSelection()
Dim rgSelUnion As Range
Dim strTitle As String
Dim strMessage As String
Dim strSelType As String
Dim
Dim
Dim
Dim
Dim
Dim
Dim

intBlockCount As Integer
intCellCount As Long
intColCount As Integer
intRowCount As Long
intAreasCount As Integer
strCurSelType As String
rgArea As Range

'
'
'
' ( _
)
'
'
'
'
'

' : _
( ) ( )
intAreasCount = Selection.Areas.Count
If intAreasCount = 1 Then
strTitle = " "
Else
strTitle = " "
End If

2. Microsoft Excel
'
strSelType = dhGetAreaType(Selection.Areas(1) )
'

Set rgSelUnion = Selection.Areas(1)
For Each rgArea In Selection.Areas
strCurSelType = dhGetAreaType(rgArea)
' ,

If strCurSelType <> strSelType Then
strSelType = ""
End If
1

If strCurSelType = "Block" Then


intBlockCount = intBlockCount + 1
End If
1


Set rgSelUnion = Union(rgSelUnion, rgArea)
Next rgArea
1


For Each rgArea In rgSelUnion.Areas
Select Case dhGetAreaType(rgArea)
Case ""
intRowCount = intRowCount + rgArea.Rows.Count
Case ""
intColCount = intColCount + rgArea.Columns.Count
Case ""
intColCount = intColCount + rgArea.Columns.Count
intRowCount = intRowCount + rgArea.Rows.Count
End Select
Next rgArea
'
intCellCount = rgSelUnion.Count

'
strMessage = " :" & vbTab & strSelType & vbCrLf &
" :
" & vbTab S intAreasCount & vbCrLf &
" :
" & vbTab & intColCount & vbCrLf &
" :
" & vbTab & intRowCount & vbCrLf &


" :
" & vbTab & intBlockCount & vbCrLf s
" :
" & vbTab& Format(intCellCount, "#,###")
MsgBox strMessage, vblnformation, strTitle
End Sub
Function dhGetAreaType(rgRangeArea As Range) As String
'
If rgRangeArea.Count = Cells.Count Then
'
dhGetAreaType = ""
Elself rgRangeArea.Cells.Count = 1 Then
'
dhGetAreaType = ""
Elself rgRangeArea.Rows.Count = Cells.Rows.Count Then
1

dhGetAreaType = ""
Elself rgRangeArea.Columns.Count = Cells.Columns.Count Then
'
dhGetAreaType = ""
Else
'
dhGetAreaType - ""
End If
End Function


TypeOf Selection. ( ),
. . , , ,
.



,
Ctrl+1. . .
VBA :
. , , ( 2.42).

2. Microsoft Excel
2.42.
Sub Worksheet_Change(ByVal Target As Excel.Range)
Call UpdateToolbar
End Sub
Sub Worksheet_SelectionChange(ByVal Target As Excel.Range)
Call UpdateToolbar
End Sub
VBA ( 2.43).
2.43.
Sub

FastChangeNumberFormat()
Dim bar As CommandBar
Dim button As CommandBarButton
' ( )
On Error Resume Next
CommandBars(" ").Delete
On Error GoTo 0

'
Set bar = CommandBars.Add
With bar
.Name " "
.Visible = True
End With
1

Set button = CommandBars(" ").Controls.Add
(Type:=msoControlButton)
With button
.Caption - ""
.OnAction = "ChangeNumFormat"
.TooltipText = " "
.Style = msoButtonCaption
End With
'
Call UpdateToolbar
End Sub
Sub

UpdateToolbar ()
' ( )
On Error Resume Next

( )
CommandBars(" ").Controls(I).Caption =
ActiveCell.NumberFormat
End Sub
Sub ChangeNumFormat()
'
Application.Dialogs(xlDialogFormatNumber).Show
Call UpdateToolbar
End Sub
FastChangeNumberFormat (
) , . .
.
(
). .
, , ChangeNumFormat
.

. . , ,
.
VBA ,
2.44.
2.44.
Sub

TableSpeedT.est ()
Dim alngDataO As Long
Dim lngCount As Long
Dim dtStart As Date
Dim
Dim

'
'
' ( ) _

strArrayToTable As String '


strTableToArray As String '

2. Microsoft Excel
Dim strMessage As String
Dim i As Long
1


Range("A:A").ClearContents
' ,
lngCount = InputBox(" ")
ReDim alngData(I To lngCount)
'
For i = 1 lngCount
alngData (i) = i
Next i
1


Application.ScreenUpdating = False
dtStart = Timer
For i = 1 To lngCount
Cells(i, 1) = i
Next i
strArrayToTable = Format(Timer - dtStart, "00:00")
'
dtStart = Timer
For i = 1 lngCount
alngData(i) - Cells (i, 1)
Next i
strTableToArray = Format(Timer - dtStart, "00:00")
Application.ScreenUpdating = True
1


strMessage = ": " & StrArrayToTable & vbCrLf &
": " & StrTableToArray
MsgBox strMessage, , lngCount & " "
End Sub

( ) TableSpeedTest. , .
, ( ),
. ,
30 000 7 ,


1 ;
65 000 14 , 2 .


,
Microsoft Excel. ,
.


Excel . . ,
=(2004; 4,-11) -(2004; 3; 6)
3 6.


, , .
. , = (2: ! 1: 7) , 2 1:7.


. (,
1, 1 ).
1. 1 =1+1.
2. ,
.
3. .
4. .
5. , 1.
6. .
: Excel. ,
.

2. Microsoft Excel


, Excel ,
VBA. , 1
2, :
Range("B2").Formula

= Range("Al").Formula


Range("B2").Value

= Range("Al").Formula

Range("B2")

= Range("Al").Formula

- ( ) .


,
, . ( ) ,
() . ( ), ,
. ,
,
.
VBA ,
.
:
Names.Add Name:="CeKpeT", RefersTo:="=1!$$5",

Visible:=False

5, 1,
. ,
. ,
1 5 : =1+5, :
=1+.

(, Ctrl+Shift+A) .


:
Range("A7").Name = ""
Range("").Name.Visible

= False

7, , .



- . ,
, = (: ), 1 = (1:1).
, , : = ( : ) . , 1,
2 3, : = (1:3).
,
Excel .


. .
,
, . , . 2.10.

'

tthJU'Iiiiiv i'll

:./"\ecg

;-:
[;

11

iWmim
.-:<;

"

f~

"

?*" [!

'


::;

<"'
'

;.;

"
|

:..::[;

OK

. 2.10.

2. Microsoft Excel

.
.
:
, ( )
F9 Enter. .


.
, Excel , (, 15,434
15,43). 1 2
15,434, 15,43, =1+2
30,86, 30,868. ,
, .
. ,
.
.

, . Excel , . , 15,434 15,43 .
, .


.
. Excel .
, Excel
. , : #/ !, #/, #?, # ! . .
, .
, ,
.


.
, . Excel ,
,
(. 2.11).

-(:)
-

| .
|

... j

:j

. 2 . 1 1 .

, , : ,
, .
. ,
, .
, , .


. , (. 2.12).
|

"

"

. : ; - : " . :

'

"

"

'

'

... ^
:

- . 1

.*
.15
, xls
.
npHMep.xls

(
1
1
1
1
!

1 |
:

.75 . . . .
75

0
G6
70
7
385
15

. 2.12.

j
=(1:1)
=(1:1)
=6+
=1+
=(;)

2. Microsoft Excel

, , ( ), ,
. . , .



, , , , , .
. ,
.
, .
. , ,
= (__), __
. ,
.
.




Microsoft Excel. ,
( , VBA).
XLA,
. Excel. ,
Excel,
P e r s o n a l . xls.
( ).
, P u b l i c F u n c t i o n . x l a (


http://www.msorrice.nm.ru/downloads/PubHcFunction.xLa). - , ,
, .
, ,
.
P u b l i c F u n c t i o n . x l a ,
P u b l i c F u n c t i o n . xla Library, Office. Excel,
, . ,
, , (. 2.13).
- I 2
:

,
, ""

?".

:;-:]
i :

ls5hared(QtitputBook}
;(18 .

OK

. 2.13. PublicFunction.xla
, . , ,
Excel.


Couple ( ) , , . ( 2.45).
2.45. couple
Function Couple(Diapazon)
' ,
Diapazon ( - )

2. Microsoft Excel
1

i C e l l -
For Each i C e l l In Diapazon
'
If IsEmpty(iCell) <> True Then
'
If Couple = " " Then
Couple = i C e l l
Else
Couple = Couple & " " & i C e l l
End If
End I f
Next
End Function
, . , ,
, .

, , , .


CoupleFormat ( )
,
.
2.46.
2.46. CoupleFormat
Function CoupleFormat(Diapazon)
' ,
Diapazon ( - )
' iCell -
For Each iCell In Diapazon
'
If IsEmpty(iCell) <> True Then
'
If CoupleFormat = "" Then
CoupleFormat = iCell.Text
Else
CoupleFormat = CoupleFormat & " " & iCell.Text
End If


End If
Next
End Function
, .



. . , 04.08 .20 0 5, 04 2005. 2.47.
2.47.
Function ()
1

"dd mmmm yyyy"
Format(, "dd mmmm yyyy")
If IsDate() True Or IsDate() = True Then
'
= StrConv(, vbProperCase)
Else
'
= " "
End If
End Function
, .
, , ,
(, .). ,
37808,
0 6 2003.


ExtractNumeric ( ). . ,
25 2004 , : 252004. ( 2.48).

2. Microsoft Excel
2.48. ExtractNumeric
Function

ExtractNumeric(iCell)

' i C e l l
For iCount
'

= 1 Len(iCell)

If

IsNumeric(Mid(iCell,
'

iCount,

1))

= True Then

ExtractNumeric = ExtractNumeric & Mid(iCell,


End

iCount,

1)

If

Next
End Function

, . . , ,
, .


, Excel , .
, . ,
PublicFunction.xla. ( 2.49).
2.49.
Function ()
'

If
1

= " " Then " " :

= UCase(Left(,
'

1))

= LCase(Mid(,
'

Exit Function

2))

= &
End

Function

, . .


, , , (-


). : , 53 53 . 00 .,
27,43 2 7 . 43 . RubKop ( ), 2.50.
2.50. RubKop
Function RubKop()
'

, ,

If IsNumeric() = False
"":
E x i t Function
1

Or = " " Then RubKop *

= Len()
Fix()
= Len()
'

= -
If

0 Then

= - - 1
End
'

If

If

= 0 Then
'

= "00"
Elself
'

= 1 Then

= Right(, )
Elself
'

& "0"

= 2 Then

= Right(,

Else
'

- _

= Right(,
If

Mid(, 3,

1)

)
> 4 Then

= Left(,

2)

Else
= Left(,
End

If

2)

+ 1

2. Microsoft Excel
End I f
1

=
RubKop = & " " & " . " & " " & & " " & " . "
End Function
, . .


CoincideCount ( ) . 2.51.
2.51. CoincideCount
Function CoincideCount(Text, Search)
1

( Search)
If IsArray(Search) = True Then Exit Function
If IsError(Search) = True Then Exit Function
If IsEmpty(Search) = True Then Exit Function
' Text
For Each iCell In Text
1
,

If Not IsError(iCell) Then
1
iText - ( )
iText = LCase(iCell)
' iSearch - ( )
iSearch = LCase(Search)
'
iLen - Len (Search)
' iSearch iText
(
)
iNumber = InStr (iText, iSearch)
While iNumber > 0
'
iNumber = InStr(iNumber + iLen, iText, iSearch)
1

CoincideCount = CoincideCount + vbNull
Wend


End If
Next
End Function
, , . ( , )
. , . ,
,
.


, ,
Excel ,
. ,
, . 2.52 .
2.52.
Function () As Double
'
For Each In
'
If Not .EntireRow.Hidden And Not
.EntireColumn.Hidden Then
1


If IsNumeric() - True Then
+
End If
End If
Next
End Function
, . ,
.


.
Excel ,
,
, , .

2. Microsoft Excel
, .
( 2.53).
2.53.
Function (, )
1

For

As Double

Each In
'

If

.Address
1

.Address

Then

If

IsNumeric()

= True Then

= +
End
End

If

If

Next
End

Function

:
,
( ).


( Publ icFunction. xla),
, . ( 70
00 ., 42,15 15 .). ,
- (,
),
.
, . ,
.
, P u b l i c F u n c t i o n . x l a .



, , one-


. , ,
.
, :
4999 . 9 %, 5000 9999 .
11 %, 10 000 . 15 % ( ). , dhCalculatePercent, 2.54.
2.54. dhCalculatePercent ( 1)
Function dhCalculatePercent(lngSum As Long) As Double
1
( )
Const dblRatel As Double =0.09
Const dblRate2 As Double = 0 . 1 1
Const dblRate3 As Double = 0 . 1 5
1
( )
Const intSuml As Long = 5000
Const intSum2 As Long = 10000
' ,
If lngSum < intSuml Then
dhCalculatePercent = lngSum * dblRatel
Elself lngSum < intSum2 Then
dhCalculatePercent = lngSum * dblRate2
Else
dhCalculatePercent = lngSum * dblRate3
End If
End Function

( 2.55).
2.55. d h C a l c u l a t e P e r c e n t ( 2)
Function dhCalculatePercent(lngSum As Long) As Double
1
( )
Const dblRatel As Double = 0 . 0 9
Const dblRate2 As Double = 0 . 1 1
Const dblRate3 As Double = 0 . 1 5
1
( )
Const intSuml As Long = 5000
Const intSum2 As Long = 10000
1

,
Select Case lngSum

2. Microsoft Excel
Case Is < intSuml
dhCalculatePercent = lngSum * dblRatel
Case Is < intSum2
dhCalculatePercent = lngSum * dblRate2
Case Else
dhCalculatePercent = lngSum * dblRate3
End Select
End Function
(
,
) , . , .
,
, , ( ), .


( . .). . , , ,
.
110 % . d h C a l c u l a t e P e r c e n t
( 2.56).
2.56. dhCalculatePercent ( 3)
Function d h C a l c u l a t e P e r c e n t (Sales As Long, IsTemporal As Boolean) As Double
'

Const d b l R a t e l

As

Double

=0.09

Const d b l R a t e 2

As Double

=0.11

Const d b l R a t e 3 As
Const dblAdd As
'

Double

Double

=0.15

=1.1

Const

lngSuml

As Long = 5000

Const

lngSum2

As Long -

'
If

Sales

10000


< lngSuml

( )

Then

dhCalculatePercent

= Sales

dblRatel


Elself Sales < lngSum2 Then
dhCalculatePercent = Sales * dblRate2
Else
dhCalculatePercent = Sales * dblRate3
End If
If IsTemporal Then
' -
dhCalculatePercent = dblAdd * dhCalculatePercent
End If
End Function

dhCalculatePercent .
, . 2.14.

. 2.14. dhCalculatePercent

Sales , , IsTemporal ,
. , False, True (
110 % ).

, , , .

2. Microsoft Excel
, :
4999 . - 9 %;
Q 5000 9999 . - 1 1 % ;
10 000 . - 15 %.
: 1 %.
, 2.57
( V B A ) .
2.57.
Function
Const
Const
Const

dhCalculateCom(dblSales As Double) As Double


dblRatel = 0 . 0 9
dblRate2 = 0 . 1 1
dblRate3 = 0 . 1 5

' ( )

Select Case dblSales
Case 0 To 4999.99: dhCalculateCom = dblSales * dblRatel
Case 5000 To 9999.99: dhCalculateCom = dblSales * dblRat.e2
Case Is >= 10000: dhCalculateCom = dblSales * dblRate3
End Select
End Function
Function dhCalculateCom2(dblSales As Double, intYears As Double)
As Double
Const dblRatel = 0 . 0 9
Const dblRate2 = 0.11
Const dblRate3 = 0 . 1 5
' ( )

Select Case dblSales
Case 0 To 4999.99: dhCalculateCom2 = dblSales * dblRatel
Case 5000 To 9999.99: dhCalculateCom2 = dblSales * dblRate2
Case Is >= 10000: dhCalculateCom2 = dblSales * dblRate3
End Select
'
dhCalculateCom2 = dhCalculateCom2 +
(dhCalculateCom2 * intYears / 100)
End Function


Sub ComCalculator()
Dim strMessage As String
Dim dblSales As Double
Dim As Integer
. .
Calc:
'
dblSales = Val(InputBox(" :",
" "))
1

(
)
strMessage = " :" & vbTab & Format(dblSales, "$#,##0")
&
vbCrLf & " :" & vbTab &
Format(dhCalculateCom(dblSales) , "$#,##0") & _
vbCrLf & vbCrLf & " ?"
' (
)
If MsgBox(strMessage, vbYesNo,
" ") = vbYes Then
'
GoTo Calc
End If
End Sub

dhCalculateCom dhCalculateCom2 (
, ), ComCalculator, ( ).
.
dhCalculateCom .
, ( ) , .
dhCalculateCom2 :
.
, . ,
.
ComCalculator - .

2. Microsoft Excel
( ),
,
, Enter. ( ) .
.
, , . .
ComCalculator . .

,

, .
, , , .
, 2.58.
2.58.
Function dhCount(rgn As Range, LowBound As Double,
UpperBound As Double) As Long
Dim cell As Range
Dim lngCount As Long
1
rgn ,
LowBound UpperBound
For Each cell In rgn
If cell.Value >= LowBound And cell.Value <= UpperBound Then
1

lngCount = lngCount + 1
End If
Next
dhCount - lngCount
End Function
. ,
, . 2.15.
Rgn ,
, LowBound UpperBound . , . 2.15 ,


B5:F12, 900 7000. ,
. ,
: =count (B5:F12; 900,-7000).

[CountRfln BS:F12
LowBound 900
UpperBoundJ7000

"3J-900
*-7000

Rgn

. 2.15. dhCount


, Excel ( ). :
? , ( ,
).
d h C o u n t v i s i b l e C e l l s . VBA ,
2.59.
2.59.
Function dhCountvisibleCells(rgRange
Dim lngCount As Long
Dim c e l l As Range

As Range)

'

For Each c e l l In rgRange
1
,
If Not IsEmpty(cell) Then

2. Microsoft Excel
1

,
If Not cell.EntireRow.Hidden And Not
cell.EntireColumn.Hidden Then
'
lngCount = lngCount + 1
End If
End If
Next cell
dhCountVisibleCells - lngCount
End Function
, . ,
. ,
. ( ) :
=dhCountVisibleCells(A1:E7)
, 1:7.



(,
27.07.2005). dhGetNextMonday, 2.60.
2.60.
Function dhGetNextMonday(datDate As Date) As Date
1
( Weekday
, ,
vbMonday)
If Weekday(datDate, vbMonday) = 1 Then
'
dhGetNextMonday = datDate
Else
1

dhGetNextMonday = datDate + 8 - Weekday(datDate, vbMonday)
End If
End Function

, 27.07.2005, dhGetNextMonday
27.07.2005. Enter -


01.08.2005, 27 2005
1 2005 . , :
=dhGetNextMonday("27.07.200 5")
.
(, 38545 12. 07.2005), .


, , . ,
( ),
. dhCalculateAge,
2.61.
2.61. dhCalculateAge
Function dhCalculateAge(datDate As Date) As Long
Dim lngAge As Long
1
()
lngAge - DateDiff("yyyy", datDate, Date)
If DateSerial(Year(datDate) + lngAge, Month(datDate),
Day(datDate)) > Date Then
'
lngAge = lngAge - 1
End If
dhCalculateAge = lngAge
End Function
, , 18.08.1972,
30.07.2005, 32. :
=dhCalculateAge("18.08.1972")

,
:
? ( ). ; , 2.62.

2. Microsoft Excel
2.62. dhBooklsSaved
Function dhBooklsSaved() As Boolean
' ,
(ThisWorkbook.path "")
dhBooklsSaved = ThisWorkbook.path <> " "
End Function
.
, ,
.


, 2.63.
2.63.

Function dhAverageWithWeight(rgWeights As Range, rgValues As Range)


As Double
If (rgWeights.Count <> rgValues.Count) Then
'
dhAverageWithWeight =
Exit Function
End If
Dim i As Integer
Dim dblSum As Double
Dim dblSumWeight As Double

'
'

...
For i = 1 rgWeights.Count
'
dblSumWeight = dblSumWeight + rgWeights(i) * rgValues(i)
'
dblSum = dblSum + rgWeights(i)
Next
'
dhAverageWithWeight = dblSumWeight / dblSum
End Function
,
RgWeights RgValues, . ,
.



.
,
. ( 2.64).
2.64.
Function dhMonthName(intMonth As Integer) As String
' (intMonth
)
dhMonthName = Choose(intMonth, "", "", "",
"", "", "", "", "", "",
"", "", "")
End Function
. .


, ,
( , , 10 ,
). , 2.65.
2.65. dhNSum
Function dhNSum(ByVal intCount As Integer, _
rgValues As Range) As Double
Dim i As Integer
Dim dblSum As Double
If intCount > rgValues.Count Then
' ,

intCount = rgValues.Count
End If
' intCount
For i = 1 intCount
dblSum = dblSum + rgValues(i)
Next i
'
dhNSum = dblSum
End Function

2. Microsoft Excel
, ( ). .


- ( , ). , ( 2.66).
2.66. dhLastUsedCell
Function dhLastUsedCell(rgRange
Dim
1

lngCell

As Range)

As Long

As Long

(
)

For

lngCell
If

= rgRange.Count To 1 Step -1

Not IsEmpty(rgRange(lngCell))
1

Then

dhLastUsedCell

= lngCell

Exit Function
End
Next
'

If

lngCell

dhLastUsedCell =
End Function

, . ,
, . , . , 0.


dhLastColUsedCell. VBA ( 2.67).
2.67. dhLastColUsedCell
Function dhLastColUsedCell(rgColumn As Range)
'

As

Variant


dhLastColUsedCell = rgColumn.Parent.Cells(Rows.Count,
rgColumn.Column).End(xlUp).Value
End Function
. ,
. . ( ) , .
. :
=dhLastColUsedCell()
.


, dhLastRowUsedCell. dhLastColUsedCell. VBA ( 2.68).
2.68. dhLastRowUsedCell
Function dhLastRowUsedCell(rgRow As Range) As Variant
'
dhLastRowUsedCell = rgRow.Parent.Cells(rgRow.Row, 256).
End(xlToLeft).Address
End Function
.
, . . ( )
, . , dhLastColUsedCell.

,

, , , .
dhCountSomeCells, ( 2.69).
2.69. dhCountSomeCells
Function dhCountSomeCells(rgRange As Range, dblMin As Double,
dblMax As Double) As Long

2. Microsoft Excel
1

dblMin dblMax
Countlf
With Application.WorksheetFunction
dhCountSomeCells = .Countlf(rgRange, ">=" & dblMin) .Countlf(rgRange, ">" & dblMax)
End With
End Function
: ,
, . , , .
, :
=dhCountSomeCells(Al:G15; 10; 15)
,
A1:G15 10 15 ().



( ).
, 2.70.
2.70.
Function dhFormatEnglish(strText As String) As String
Dim i As Integer
Dim strCurChar As String * 1
' strText.

For i = 1 Len(strText)
strCurChar = Mid(strText, i, 1)
'
97 122
If Asc(strCurChar) >= 97 And Asc(strCurChar) <= 122 Then
'
dhFormatEnglish = dhFormatEnglish & UCase(strCurChar)
Else
' .
dhFormatEnglish = dhFormatEnglish & strCurChar
End If
Next i
End Function


,
. .
, , , , .


, , , . .
, (, ). , . 2.71 (
VBA).
2.71.
Function dhReverseText(strText As String) As String
Dim i As Integer
'

For i = Len (strText) To 1 Step -1
dhReverseText - dhReverseText & Mid(strText, i, 1)
Next i
End Function
Sub ReverseText()
Dim strText As String
1

strText = InputBox(" :")
'
MsgBox dhReverseText(strText), , strText
End Sub
dhReverseText
( ) ReverseText
( ).
, . , , .
, . :
=dhReverseText(A4)

2. Microsoft Excel

11

4 , . Enter .
ReverseText ( , ) 4,

Enter. .
, ReverseText.

, .
, , . , = (2: 7 ! A3) A3 2 7 .
: ( 7)
.
, 2.72.
2.72.
Function dhMaxInBook(cell As Range) As Double
Dim

sheet As Worksheet

Dim

dblMax As Double

Dim

dblResult As Double

Dim

fFirst

fFirst
1

As Boolean

= True

For

Each sheet
'

In

cell.Parent.Parent.Worksheets

dblResult

Application.WorksheetFunction.Max(sheet.UsedRange)

If

Then

fFirst
1

dblMax = dblResult
fFirst
End

If

= False

dblMax dbmResult
If dblResult > dblMax Then
dblMax = dblResult
End If
Next sheet
'
dhMaxInBook = dblMax
End Function
, . () .


, Excel . , ,
. , . dhsheetof f set,
( 2.73).
2.73. dhSheetOffset
Function dhSheetOffset(offset As Integer, cell As Range) As Variant
' cell ,
offset
dhSheetOffset = Sheets(Application.Caller.Parent.Index
+ offset).Range(cell.Address)
End Function
. ;
, (, -1). . :
dhSheetOffset(-1;9)
9, ( 2, 9 1).
: , .

2. Microsoft Excel
.
dhSheetOf f set2, ,
( 2.74).
2.74. dhSheetOffset2
Function dhSheetOffset2(offset As Integer, cell As Range) As Variant
' ( )
Do While TypeName(Sheets(cell.Parent.Index + offset))
<> "Worksheet"
If offset > 0 Then
'
offset = offset + 1
Else
'
offset = offset - 1
End If
Loop
1

cell ,
offset

dhSheetOffset2 - Sheets(cell.Parent.Index
+ offset).Range(cell.Address)
End Function
, dhSheetOf f set.


dhCellType - . , VBA,
2.75.
2.75. ,
Function dhCellType(rgRange As Range) As String
' , rgRange - ,

Set rgRange = rgRange.Range("Al")
1

Select Case True
Case IsEmpty(rgRange)


dhCellType = ""
Case Application.IsText(rgRange)
'
dhCellType = ""
Case Application.IsLogical(rgRange)
1
(True False)
dhCellType = " "
Case Application.IsErr(rgRange)
'
dhCellType = ""
Case IsDate(rgRange)
'
dhCellType = ""
Case InStrfl, rgRange.Text, ":")
'
dhCellType = ""
Case IsNumeric(rgRange)
'
dhCellType = ""
End Select
End Function

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


, ( , . .)
.
, 2.76 (
VBA).
2.76.
Function dhGetTextItem(ByVal strTextln As String, intltem As _
Integer, strSeparator As String) As String
Dim i n t S t a r t As Integer '

2. Microsoft Excel
Dim intEnd As Integer
Dim i As Integer

'
'


If intltem < 1 Then Exit Function
' , -
If strSeparator=" " Then strTextln = Application.Trim(strTextln)
'
If Right(strTextln, Len(strTextln)) <> strSeparator Then
strTextln = strTextln & strSeparator
'
For i = 1 intltem
' ( )
intStart = intEnd + 1
1

intEnd = InStr(intStart, strTextln, strSeparator)
If (intEnd = 0) Then
' ,
Exit Function
End If
Next i
'
dhGetTextltem = Mid(strTextln, intStart, intEnd - intStart)
End Function

: strTextln, intltem strSeparator. strTextln , ; intltem ; a strSeparator .


,
, . ():
=dhGetTextItem(A9;3;"-")
dhGetTextltem , 9 ,
3 , (-) .
, , , , , 2, .
, :
=dhGetTextItem(B2;3;", ")

, .


.
, .
. 2.77.
2.77. dhGetRandomValues
Function dhGetRandomValues() As Variant
Dim intRow As Integer
'
Dim intCol As Integer
'
Dim aintOutf) As Integer
' ()
Dim aintValues() As Integer '
Dim intMax As Integer
'
aintValues
Dim i As Integer
ReDim aintOut(l To Application.Caller.Rows.Count, 1 To
Application.Caller.Columns.Count)
' ...
intMax = Application.Caller.Rows.Count *
Application.Caller.Columns.Count
ReDim aintValues(1 To intMax)
' aintValues 1 intMax
For i = 1 To intMax
aintValues(i) = i
Next i
' aintOut,
aintValues
Randomize
For intRow = 1 To Application.Caller.Rows.Count
For intCol = 1 To Application.Caller.Columns.Count
' aintValues
i Rnd * intMax
If i = 0 Then i = 1
'
aintOut(intRow, intCol) = aintValues(i)
' aintValues ( _
) - _

2. Microsoft Excel
a i n t V a l u e s ( i ) = aintValues(intMax)
intMax = intMax - 1
Next i n t C o l
Next intRow
'
dhGetRandomValues = aintOut
End Function
, . . 2.16.
1
2
3
4
S
6
7
8

.1.0.

5
23
30
17
10
36
35
12
13
15

11

29
32
21
27
24
39
4
34
3

22!

D 18!
1

20]

6!
14!

7
19

38!
25!
2!
31!
9!
16!

37

261
28!

33!

. 2.16.

:
=dhGetRandomValues()

.
Ctrl+Shift+Enter. . 2.16 40
, 40 (10 4 ).


, , . ,
, ( ).
( ) ( 2.78).
2.78. dhGetRandomValuesl
Function dhGetRandomValuesl(rgSource As Range) As Variant
Dim intRow As I n t e g e r
'
Dim i n t C o l As I n t e g e r
'
Dim avarOut() As Variant
' ()


Dim
Dim
Dim
Dim

avarValuesO As Variant '


intValCount As Integer '
cell As Range
i As Integer

ReDim avarOut(l To Application.Caller.Rows.Count, 1 To


Application.Caller.Columns.Count)
1
...
intValCount = rgSource.Rows.Count * rgSource.Columns.Count
ReDim avarValuesd To intValCount)
1
avarValues

For Each cell In rgSource


i = i + 1
avarValues(i) = cell.Value
Next cell
' avarOut,
avarValues
Randomize
For intRow = 1 To Application.Caller.Rows.Count
For intCol = 1 To Application.Caller.Columns.Count
' avarValues
i = Rnd * intValCount
If i = 0 Then i = 1
'
avarOut(intRow, intCol) = avarValues(i)
Next intCol
Next intRow
1


dhGetRandomValuesl avarOut
End Function

. ():
=dhGetRandomValuesl(A1:C5)
1: 5 . ,
Ctrl+Shift+Enter. .


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


. ( 3.1-3.3) VBA-.
3.1. ( 1)
Sub A u t o _ O p e n ( )
Worksheets(1).Cells(1)

= Worksheets(1).Cells(1)

+ 1

End Sub

.2. ( 2)
Sub Auto_Open()
W o r k s h e e t s (1) . C e l l s ( 1 , 1) = W o r k s h e e t s ( 1 ) . C e l l s ( 1 ,

1)

+ 1

= Worksheets(1) .Range("Al")

+ 1

End Sub

3.3. ( 3)
Sub Auto_Open()
Worksheets(1).Range("Al")
End Sub

, Microsoft Office,
Auto_Open. , Microsoft Office .
1.
, 1 (,
, 1 52, 53). 1
,
.

3.


. ( 3.4).
3.4.
Sub GetDataFromFile()
Range("Al").Formula
End Sub

1
- "='C:\[Example.xls]! !1'

,
: \Example. x l s , 1.
, , ,
. ,
, . . , . , 3.4.
1 2 , F . x l s ( , ):
=' [ F . X 1 S C T 2 '

!A1



. ( 3.5).
3.5.
Sub ChangeStatusBarText()
Application.StatusBar = " !!!"
End Sub
. 3.1.

j
!!!

|'| \ 0

1 |gjC:\

. 3.1.


( 3.6).
3.6.
Sub ReturnStatusBarText()
Application.StatusBar False
End Sub

.
, . 3.1, ,
. ,
3.7.
3.7.
Sub MovingTextlnStatusBar()
Dim intSpaces As Integer
1

( 20 0) - _
(, )
For intSpaces = 20 0 Step -I
'
Application. StatusBar = Space (intSpaces) & " ! ! !"
'
Application.Wait Now + TimeValue("00:00:01")
' Excel
DoEvents
Next
Application.StatusBar = False
End Sub

( )
.



. , , ( 3.8).
3.8.
Sub NewTitle ()
Application.Caption = " "
End Sub

3.
. 3.2.
-
\ ]

- 10 v j

I ArialCyr

. 3.2.

. 3.2 , . , ( 3.9).
3.9. ( )
Sub NewTitle()
Application.Caption = " "
ActiveWindow.Caption = ""
End Sub

(. 3.3).
]

-'

..ArialCyr

. 3.3.

, .
( 3.10).
3.10.
Sub NewTitle()
Application.Caption = " "
ActiveWindow.Caption = " '"
End Sub

. 3.4.
] -

I ArialCyr

*|10

\:'

. 3.4.


,
( 3.11).
3.11.
Sub

ReturnTitle()
'

Application.Caption

( Excel)

= Empty

' ()'
ActiveWindow.Caption

ThisWorkbook.Name

End Sub

,
.


, . ( 3.12).
3.12.
Sub InputDialog()
Dim s t r l n p u t As String
'
s t r l n p u t = InputBox(" ", " ")
End Sub

,
. 3.5.

. 3.5.

, ( Default), ( XPOS YPos).


3.13.

3.
3.13.
Sub NewInputDialog()
Dim s t r l n p u t As S t r i n g
'

s t r l n p u t = InputBox(" ", " ",
" ", 200, 200)
End Sub
, , . 3.6.

. 3.6.

Windows.


Excel
, .
( 3.14).
3.14.
Sub Func()
[Al] = Application.Sum([B5:B10] )
End Sub
5:10, 1.


,
.
.
,
( 3.15).


3.15.
Sub

HideStringO
Rows(2).Hidden
End Sub

= True

2.
( 3.16).
3.16.
Sub HideStrings()
Rows("3:5").Hidden = True
End Sub

3, 4 5.
( ), True False,
.
. , , 3.17, .
3.17.
Sub HideCollumn()
Columns(2).Hidden = True
End Sub

2, , , (
, ).
, , ( 3.18).
3.18.
Sub HideCollumns()
Columns("E:F").Hidden = True
End Sub

F.
,
True False .
, .
, ( 3.19).

3.
3.19.
Sub HideCell ()
Range("").EntireRow.Hidden
End

True

Sub

, . , , , , .
(, 2, 2).
, . 3.20.
3.20.
Sub HideCell()
Range("B3:D4").EntireRow.Hidden
End

= True

Sub

3 4.
( ), True False,
.
, . ( 3.21).
3.21.
Sub HideCell ()
Range("").EntireColumn.Hidden = True
End

Sub

, .
, (, , ).
( 3.22).
3.22.
Sub HideCell()
Range("C2:D5").EntireColumn.Hidden = True
End Sub

D.
,
True False.

,

, , , .
, , 3.23.
3.23. ( 1)
Sub IntervalCellSelect()
Dim intFirstRow As Integer
Dim intLastRow As Integer
Dim rgCells As Range
Dim intRow As Integer

'
'
'

intFirstRow = 3
intLastRow = 300
1

""
intFirstRow intLastRow 3
For intRow = intFirstRow To intLastRow Step 3
If rgCells Is Nothing Then
1

Set rgCells - Cells (intRow, 1)
Else
'
Set rgCells = Union(rgCells, Cells(intRow, 1))
End If
Next
'
rgCells.Select
End Sub
,
3 300, .
( 3 300 )
, ( 3.24).
3.24. ( 2)
Sub IntervalCellSelect()
Dim intFirstRow As Integer
Dim intLastRow As Integer
Dim rgCells As Range

'
'
'

3.
Dim cell As Range
Dim intRow As Integer

'

intFirstRow = 3
intLastRow =-300
' ""
intFirstRow intLastRow 3
For intRow = intFirstRow To intLastRow Step 3
Set cell = Cells(intRow, 1)
Set rgCells = Union (cell,
Ilf(intRow - intFirstRow, cell, rgCells))
Next
1

rgCells.Select
End Sub

, ,
( ),
,
.
( 3.25).
3.25.
Sub SelectRange()
Range("D3:D10, A3:A10 ,
End Sub

F3").Select

D3:D10, A3:A10
F3.



, . 3.26 , .
3.26.
Sub CalculateSumO
Dim i As Integer
Dim intSum As Integer
' ""
For' i = 1 5

( )


intSum = intSum + Cells(i, 1)
Next
MsgBox " : " & intSum
End Sub

1 5,
.
. 3.7.
Microsoft Excel
248700

. 3.7.

, - , . ( 3.27).
3.27.
Sub CalculateSumf)
Dim i As Integer
Dim intSum As Integer
' "" ( )
For i = 1 5
If IsNumeric(Cells(i, 1)) Then
intSum - intSum + Cells(i, 1)
End If
Next
MsgBox " : " & intSum
End Sub

1 5,
,
.
, . 3.28 ,
.
3.28.
Sub CountOfCells()
MsgBox (Range("Al:A20,
End Sub

Dl:D20").Count)

3.

11

,
1:20 D1:D2O.


, .
( 3.29).
3.29.
Sub CountNamesO
Dim
'

intNamesCount As

Integer

intNamesCount =
If

ActiveWorkbook.Names.Count

intNamesCount = 0 Then
MsgBox " "

Else
MsgBox ": " & intNamesCount & " ."
End If
End Sub

,
. 3.8.

. 3.8.

. ( 3.30).
3.30.
Sub CountNamesO
Dim
'

intNamesCount As

Integer

intNamesCount = Names.Count
If

intNamesCount = 0 Then
MsgBox " "

,
Else
MsgBox ": " & intNamesCount & " ."
End If
End Sub



( 3.31).
3.31.
Sub FindActiveCell ()
'
MsgBox ActiveCell.Address
End Sub

, . 3.9.
Microsoft Excel
$<463
OK

. 3.9.

, :
MsgBox ActiveCell.Address(RowAbsolute:=False,

ColumnAbsolute:=False)

,

, - . , , , ( ).
( 3.32).
3.32.
Sub

FindSheetData()
'

MsgBox ActiveSheet.UsedRange.Address
End Sub

3.
, . 3.9, .
, , , 3.33.
3.33.
Sub FindStartOfDataO
With ActiveSheet
1

,

.Cells(.UsedRange.Row, .UsedRange.Column).Value =
" "
End With
End Sub
, , (
). ,
( , , 350).


, , .


, ,
, ( ).
( )
,
. , ,
, ( 3.34).
3.34.
Sub CountOfComment()
Dim intCommentCount As Integer
'

intCommentCount = ActiveSheet.Comments.Count


If intCommentCount = 0 Then
MsgBox " "
Else
MsgBox ": " s intCommentCount & " ."
End If
End Sub
, . 3.9, .


, , , , . ( 3.35).
3.35.
Sub ShowComments()
Dim cell As Range
Dim rgCells As Range
'
Set rgCells = Selection.SpecialCells(xlComments)
If rgCells Is Nothing Then
1

Exit Sub
End If
'
For Each cell In rgCells
'
cell.Next.Value = cell.Comment.Text
Next
End Sub

,
.

, .
( )
( 3.36).

3.
3.36.
Sub

ShowCommentsl()
Dim cell As Range
Dim strFirstAddress As String
Dim strComments As String

' ,
Set cell = Selection.Find("*", LookIn:=xlComments)
If Not cell Is Nothing Then
1

( )
strFirstAddress = cell.Address
Do
1

strComments = strComments & ": " &
cell.Comment.Text & Chr(13)
'
Set cell = Selection.FindNext(cell)
Loop While Not cell Is Nothing And
cell.Address <> StrFirstAddress
End If
If strComments <> "" Then
1

MsgBox strComments
Else
MsgBox " / "
End If
End Sub


, .
( 3.37).
3.37. ( 1)
Sub

ListOfComments()
Dim cell As Range
Dim rgCells As Range
Dim intRow As Integer


'
On Error Resume Next
Set rgCells = Selection.SpecialCells(xlComments)
If rgCells Is Nothing Then
'
Exit Sub
End If
'
For Each c e l l In r g C e l l s
1
""
intRow = intRow + 1
C e l l s ( i n t R o w , 3) = cell.Comment.Text
Next
End Sub

( ) ( 3.38).
3.38. ( 2)
Sub ListOfCommentsl()
Dim cell As Range
Dim strFirstAddress As String
Dim intRow As Integer
' ,
Set cell - Cells.Find("*", Lookln:=xlComments)
If Not cell Is Nothing Then
'
( )
strFirstAddress = cell.Address
Do
' ""
intRow = intRow + 1
Cells(intRow, 3) = cell.Comment.Text
'
Set cell = Cells.FindNext(cell)
Loop While Not cell Is Nothing And _
cell.Address <> strFirstAddress
End If
End Sub

, .

3.


, . , , :
, ,
, Excel .
, 3.39,
VBA .
3.39.
Sub CountOfComments()
Dim intCommentCount As Integer
'
intCommentCount ActiveSheet.Comments.Count
If intCommentCount = 0 Then
MsgBox " .",
vblnformation
Else
MsgBox " " & intCommentCount
& " .", vblnformation
End If
End Sub
Sub SelectComments()
'
Cells.SpecialCells(xlCellTypeComments).Select
End Sub
Sub ShowComments()
'
If Application.DisplayCommentlndicator = xlCommentAndlndicator Then
Application.DisplayCommentlndicator = xlCommentlndicatorOnly
Else
Application.DisplayCommentlndicator xlCommentAndlndicator
End If
End Sub
Sub ListOfCommentsToFile ()
Dim rgCells As Range
'
Dim intDefListCount As Integer '


Dim
Dim
Dim
Dim

strSheet As String
strWorkBook As String
intRow As Integer
cell As Range

'
'

'
On Error Resume Next
Set rgCells = ActiveSheet.Cells.SpecialCells(xlComments)
On Error GoTo 0
' ,
If rgCells Is Nothing Then
MsgBox " .",
vblnformation
Exit Sub
End If
'
strSheet = ActiveSheet.Name
strWorkBook = ActiveWorkbook.Name
'

intDefListCount = Application.SheetsInNewWorkbook
Application.SheetsInNewWorkbook = 1
Workbooks.Add
Application.SheetsInNewWorkbook = intDefListCount
ActiveWorkbook.Windows(1).Caption = "Comments for " & strSheet &
" in " & strWorkBook
'
Cells (1, 1) = ""
Cells (1, 2) - ""
Cells (1, 3) = ""
Range (Cells (1, 1 ) , Cells (1, 3)).Font.Bold = True
intRow = 2 '
For Each cell In rgCells
Cells(intRow, 1) = cell.Address(rowabsolute:=False,
columnabsolute:=False)
Cells(intRow, 2) = " " & cell.Formula
Cells(intRow, 3) = cell.comment.Text
intRow = intRow + 1
Next
End Sub

3.
Sub ChangeCommentColor()
'
Dim comment As comment
For Each comment In ActiveSheet.Comments
'
comment.Shape.Fill.ForeColor.SchemeColor = Int((80) * Rnd + 1)
comment.Shape.TextFrame.Characters.Font.Colorlndex = Int((56
) * Rnd + 1)
Next
End Sub
( ) :

ChangeCommentColor
, ;

Q Countof Comments ;
Q L i s t o f CommentsToFile (

, );
Q SelectComments ;
Q ShowComments / .
, . (, ,
) . .



( , ).
, , ( 3.40).
3.40.
Sub AddCustomCommandBar()
'
With Application.CommandBars(3).Controls.Add(Type:=msoControlButton)
.Faceld = 42
' Word


.Caption = ""
.OnAction = ""
End With
End Sub
. 3.10.

U 21: 100% . (),


tdo i,o \ \ ___ - <> -

- ..,

. 3.10.

( 3.41).
3.41.
Sub AddCustomButton()
'
With Application.Toolbars(1).ToolbarButtons.Add(button:=222)
.Name ""
.OnAction = ""
End With
End Sub
, , . 3.11.

"";

SI j a g g 100% , 13
*$ +-: ) __ - - .
. 3 . 1 1 .

( , . .) .


,
.
,
( 3.42).

3.
3.42.
Sub

CreateCustomControlBar()
'
With Application.CommandBars.Add(Name:="",
'
With
.Controls.Add(Type:=msoControlButton)
. S t y l e = msoButtonlconAndCaption
.Faceld = 66

Temporary:=True)

.Caption = " "


End With
'
. V i s i b l e = True
End With
End Sub
. 3.12.

. 3.12.

, .
,

. ( 3.43).
3.43.
Sub CreateCustomControlBar()
'
With Application.CommandBars.Add(Name:="", Temporary:=True,
Position:=msoBarLeft)
'
With

.Controls.Add(Type:=msoControlButton)

.Style = msoButtonWrapCaption
.Caption = " "
End With
'
With .Controls.Add(Type:=msoControlButton)


.Style = msoButtonlconAndWrapCaption
.Caption = ""
.Faceld = 225
End With
'
.Visible = True
End With
End Sub


(. 3.13).

1
2
3
4


. 3.13.

. , 3.44 ( ).
3.44.
Sub

CreateCustomControlBar()
'
With Application.CommandBars.Add(Name:=" ",
Temporary:=True)
'
With .Controls.Add(Type:=msoControlButton)
.Style = msoButtonWrapCaption
.Caption = ""
End With

' -
.Position = msoBarRight
1

.Visible = True
End With
End Sub

3.

. 3.14.

; I

. 3.14.


. (
.)
.
.



, , ,
Excel. ( 3.45).
3.45. ( 1)
Sub AddCustomMenu()
'
With Application.CommandBars(1).Controls.Add(Type:=msoControlPopup, _
Temporary:=True)
.Caption = ""
With .Controls
'
With .Add(Type:=msoControlButton)
.Faceld = 280
.Caption = ""
.OnAction = "1"
End With
'
With .Add(Type:=msoControlPopup)
.Caption = " "
With .Controls
'

With .Add(Type:=msoControlButton)
.Faceld = 1643
.Caption = ""
.OnAction = "2"
End With


'

With

.Add(Type:=msoControlButton)

.Faceld = 1000
.Caption = ""
.OnAction
End
End
End
End
End
End

= ""

With

With

With

With

With

Sub

, (!, 2 ), .
Excel , . 3.15.

j3

. 3.15.
1, 2 , , ,
, , .
(. . 3.15) Excel
, 3.46.
3.46. ( 2)
Sub AddCustomMenul()
' "" ,

With MenuBars("Worksheet").Menus.Add(Caption:="")
'
.MenuItems.Add Caption:="", OnAction:="1"
'
With .MenuItems.AddMenu(Caption:=" ")
'
.MenuItems.Add Caption:="", OnAction:="2"

3.
.Menultems.Add Caption:="",
End With
End With
End Sub

OnAction:=""

( 3.47).
3.47. ( 3)
Sub AddCustomMenu2()
' "" ,

With MenuBars("Worksheet").Menus.Add(Caption:="")
'
.Menultems.Add Caption:="", OnAction:="1"
'
With .Menultems.AddMenu(Caption:=" ")
'
With .Menultems.Add(Caption:="")
'
.OnAction - "2"
End With
1


With .Menultems.Add(Caption:="")
'
.OnAction - ""
End With
End With
End With
End Sub
,
1, 2 .

,
. , 3.48
( , ).
3.48. ( 1)
Sub VerifyFileLocation()
Dim strFileName As String


Dim strFileTitle As String
'
strFileTitle = "primer.xls"
strFileName = ":\\1.xls"
' ( Dir
, )
If Dir (strFileName)

"" Then

MsgBox " " & strFileTitle & " "


Else
MsgBox " " & StrFileTitle & " "
End If
End Sub

,
,
(. 3.16).
Microsoft Excel
primer,xl<
:.:!;.::.,:...

UK.

. 3.16.

, 3.49 ( ).
3.49. ( 2)
Sub VerifyFileLocationl()
Dim strFileName As String
1

strFileName = ":\\1.xls"
1

( Dir
, )

If Dir(strFileName)

"" Then

MsgBox " " & strFileName & " "


Else
MsgBox " " & strFileName & " "
End If
End Sub

, . 3.16, .

3.
. , , 3.50.
3.50.
Sub FileSearchO
Dim strFileName As String
Dim strFolder As String
Dim strFullPath As String
'
strFolder - InputBox(" :")
If strFolder = "" Then Exit Sub
'
strFileName = Application.InputBox(" :")
If strFileName = "" Then Exit Sub
' "\"
If Right(strFolder, 1) "\" Then strFolder = strFolder & "\"
'
strFullPath = strFolder & strFileName
1

VBA
MsgBox " VBA..." & vbCrLf & vbCrLf &
dhSearchVBA(strFullPath), vblnformation, strFullPath
1
FileSearch
MsgBox " FileSearch..." & vbCrLf &
vbCrLf & dhSearchFileSearch(strFolder, strFileName), vblnformation, _
strFullPath
'
FileSystemObject
MsgBox " FileSystemObject..." & vbCrLf &
vbCrLf & dhSearchFileSystemObject(strFullPath), vblnformation,
strFullPath
End Sub
Function dhSearchVBA(varFullPath As Variant) As Boolean
' VBA
dhSearchVBA = Dir (varFullPath) <> ""
End Function
Function dhSearchFileSearch(varFolder As Variant, varFileName
As Variant) As Boolean

FileSearch
With Application.FileSearch
'
.NewSearch
'
.FileName = varFileName
'
.Lookln = varFolder
'
.Execute
dhSearchFileSearch = .FoundFiles.Count <>
End With
End Function
Function dhSearchFileSystemObject(varFullPath As Variant) As Boolean
Dim objFSObject As Object
' FileSystemObject
Set objFSObject = CreateObject("Scripting.FileSystemObject")
dhSearchFileSystemObject = objFSObject.FileExists(varFullPath)
End Function
,
, ( ) . . ,
: ,
True, False.
, FileSearch, (
). , . ,
( dhSearchFileSearch
). ,
, .


VB , , .
,
( 3.51).

3.
3.51.
Sub D e l e t e F i l e O
K i l l ": \\. . x l s "
End Sub
p r i m e r . x l s , :\.

( 3.52).
3.52.
Sub DeleteFiles()
' XLS
Kill "" & "*.xls"
End Sub
:
, XLS.
,
, .



, ,
.
( 3.53).
3.53.
Sub

SheetNamesAsHyperLinks()
Dim s h e e t As Worksheet
Dim c e l l As Range
With ActiveWorkbook
'

For Each sheet In ActiveWorkbook.Worksheets
Set c e l l = W o r k s h e e t s ( 1 ) . C e l l s ( s h e e t . I n d e x , 1)
.Worksheets(1).Hyperlinks.Add A n c h o r : = c e l l , A d d r e s s : = " " ,
SubAddress:="'" & sheet.Name & " ' " & " ! A 1 "
c e l l . F o r m u l a = sheet.Name
Next


End With
End Sub

. 3.17 , .

1 1
2 2
3

. 3.17.



. .
, 3.54.
3.54. ( 1)
Sub DeleteEmptyStrings()
Dim intLastRow As Integer
Dim intRow As Integer

'
'

'
intLastRow = Worksheets(ActiveSheet.Index).UsedRange.Row +
Worksheets(ActiveSheet.Index).UsedRange.Rows.Count - 1
'
intRow = Worksheets(ActiveSheet.Index).UsedRange.Row
'
Do While intRow <= intLastRow
If ActiveSheet.Rows(intRow).Text = "" Then
'
ActiveSheet.Rows(intRow).Delete
1

,
, -
intLastRow - intLastRow - 1
Else
' -
intRow = intRow + 1
End If
Loop
End Sub

3.
,
, . , 1 10, 5 7 ,
5 7
, 11,12,13,14,..., 65 536 .

( 3.55). .
,
.
3.55. ( 2)
Sub DeleteEmptyStringsl()
Dim intRow As I n t e g e r
Dim intLastRow As I n t e g e r
'
intLastRow m ActiveSheet.UsedRange.Row +
ActiveSheet.UsedRange.Rows.Count - 1
'
For intRow - intLastRow To 1 Step -1
If ActiveSheet.Rows(intRow).Text = "" Then
ActiveSheet.Rows(intRow).Delete
End If
Next intRow
End Sub
- .


,
, . 3.56 , .
3.56.
Sub SaveAsTextO
Dim c e l l As Range
1

(
, - )


Open ThisWorkbook.Path & "\" & ThisWorkbook.Name & ".txt"
For Output As #1
'
For Each cell In ActiveSheet.UsedRange
If Not IsEmpty(cell) Then
Print #1, cell.Address, cell.Formula
End If
Next
' He
Close #1
End Sub
( , ) ( 3.57).
3.57.
Sub SaveAsTextl()
Dim cell As Range
1

(
, - )
Open ThisWorkbook.Path & "\" & ThisWorkbook.Name & ".txt"
For Output As #1
'
For Each cell In ActiveSheet.UsedRange
If Not IsEmpty(cell) Then
Print #1, cell.Address, cell.FormulaLocal
End If
Next
' He
Close #1
End Sub

, , .
: Primer. xls,
Primer. x l s . t x t . , , , .


, .

3.
:
, .
VBA , 3.58.
3.58.
Sub ExportAsText()
Dim lngRow As Long
Dim intCol As Integer
'
Open "C:\primer.txt" For Output As #1
1
()
For lngRow = 1 Selection.Rows.Count
' lngRow
For intCol = 1 Selection.Columns.Count
Write #1, Selection.Cells(lngRow, intCol).Value;
Next intCol
1

Print #1, ""
Next lngRow
1
He
Close #1
End Sub
Sub ImportTextO
Dim strLine As String
Dim strCurChar As String * 1
Dim strValue As String
Dim lngRow As Long
Dim intCol As Integer
Dim i As Integer

'
'
'
'
'

'
Open "C:\primer.txt" For Input As #1
' ,
, ( )
Do Until EOF(l)
'
Line Input #1, strLine
'
For i = 1 Len(strLine)
strCurChar = Mid(strLine, i, 1)
If strCurChar = "," Then


' - .

ActiveCell.Offset(lngRow, intCol) = strValue
intCol = intCol + 1
strValue = ""
Elself i = Len(strLine) Then
' -
(
, )
If strCurChar <> Chr(34) Then
strValue = strValue & strCurChar
End If
'
ActiveCell.Offset(lngRow, intCol) = strValue
strValue = ""
Elself strCurChar Chr(34) Then
'
( )
strValue strValue & strCurChar
End If
Next i
'
intCol = 0
lngRow = lngRow + 1
Loop
'
Close #1
End Sub


ExportAsText ImportText.
primer. txt, : \.
ImportText.
ExportAsText , . , (
).
, ().

, , - ,

3.

rvti

. , 3.59.
3.59.
Sub MultAllCells ()
Dim

dblMult As Double

Dim

cell

'

As Range

dblMult = InputBox (" , ")


1

For

Each c e l l
If

In S e l e c t i o n

IsNumeric(cell.Value)
'

And c e l l . V a l u e <> " " Then

cell.Value = cell.Value

* dblMult

Else
MsgBox " " & c e l l . A d d r e s s
End

& " "

If

Next
End

Sub

.
, Al, B2 10, 15 20 . , , . , . 3.18.
Microsoft Excel
,

Cancel I

. 3.18.

,
. 2, Al, B2 20, 30 4 0.
, -
, .

Excel HTML-

Excel
HTML-

Excel HTML- (,
). ,
.
, HTML- (. 3.19).
"\
2-

3
4

77
25|

44 j
171

345:"

4151

25]

. 3.19. Excel

, 3.60.
3.60. HTML-
Sub ExportAsHtml()
Dim strStyle As String
Dim strAlign As String
Dim strOut As String
Dim cell As Object
Dim strCellText As String
Dim lngRow As Long
Dim
Dim
Dim
Dim

lngLastRow As Long
strTemp As String
objWordApp As Object
i As Long

'
'
'
'
'
'



HTML-


'

lngLastRow = Selection.Row
1

For Each cell In Selection
'
lngRow = 11.Row
1
, <tr>
If lngRow <> lngLastRow Then
strOut = strOut & vbTab & "</tr>" & vbCrLf & vbTab &
"<tr>" & vbCrLf

3.
1


lngLastRow = lngRow
End If
'
If Not IsNull(cell.Font.Size) Then
strStyle = " style-" & "font-size: " & IntdOO *
cell.Font.Size / 19) & "%;"
End If
' <b>
If cell.Font.Bold Then
strCellText - "<b>" & strCellText & "</b>"
End If
'
If cell.HorizontalAlignment = xlRight Then
'
strAlign = " align=" & "right"
Elself cell.HorizontalAlignment = xlCenter Then
'
strAlign = " align=" & "center"
Else
' ( )
strAlign = ""
End If
1


strCellText = cell.Text
1
, ( strTemp
StrCellText)
If cell.Orientation <> xlHorizontal Then
strTemp = ""
'
- <br>
For i = 1 Len(strCellText)
strTemp = strTemp & Mid$(strCellText, i, 1) & "<br>"
Next i
strCellText = strTemp
strStyle = ""
End If
strOut = strOut & vbTab S vbTab & "<td" & strStyle & strAlign
& ">" & strCellText & "</td>" & vbCrLf

Excel HTML-
Next
' <tr> </tr> -
strOut = vbTab & "<tr>" & vbCrLf & strOut & vbTab & "</tr>" & vbCrLf
' <table>
strOut = "<table border=l cellpadding=3 cellspacing=l>" & vbCrLf &
strOut & vbCrLf & "</table>"
' Word HTML-
Set objWordApp = CreateObject("Word.Application")
objWordApp.documents.Add
objWordApp.Selection = strOut
objWordApp.Selection.Copy
objWordApp.Visible = True
Set objWordApp = Nothing
End Sub

, , HTML-.
, . 3.19, HTML-:
<table border=l cellpadding=3 cellspacing=l>
<tr>
<td style=font-size: 52%;>77</td>
<td style=font-size: 52%;>345</td>
</tr>
<tr>
<td
<td
</tr>
<tr>
<td
<td
</tr>
<tr>
<td
<td
</tr>

style=font-size: 52%; align=right>25</td>


style=font-size: 52%;>851</td>

style=font-size: 52%;>44</td>
style=font-size: 52%;>415</td>

style=font-size: 52%;>17</td>
style=font-size: 52%;>25</td>

</table>

, -, HTML-. Microsoft Word,


.

3.

HTML- .
, -, . , 3.61.
3.61. -
Sub ExportAsHtmlFile()
Dim strStyle As String

'

Dim strAlign As String

'

Dim strOut As String

' HTML-

Dim cell As Object

'

Dim strCellText As String

'

Dim lngRow As Long

'

Dim lngLastRow As Long

'

Dim strTemp As String


Dim strFileName As String

' HTML-

Dim i As Long
'
strFileName = Application.GetSaveAsFilename(
InitialFileName:="Primer.htm",
fileFilter:="HTML Files(*.htm), *.htm")
' , ( ,
)
If strFileName = "" Then Exit Sub
lngLastRow = Selection.Row
'
For Each cell In Selection
'
lngRow = cell.Row
' , <tr>
If lngRow <> lngLastRow Then
strOut = strOut & vbTab & "</tr>" & vbCrLf & vbTab &
"<tr>" & vbCrLf
1

lngLastRow = lngRow
End If
'
If Not IsNull(cell.Font.Size) Then

Excel HTML-
s t r S t y l e - " style=" & "font-size: " & Int(100 *
c e l l . F o n t . S i z e / 19) & "%;"
End I f
' <b>
If cell.Font.Bold Then
strCellText = "<b>" & strCellText & "</b>"
End If
1

If cell.HorizontalAlignment = xlRight Then


'
strAlign > " align=" & "right"
Elself cell .Hor-izontalAlignment = xlCenter Then
'
strAlign = " align=" & "center"
Else
' ( )
strAlign ""
End If
'
strCellText = cell.Text
' , ( strTemp
strCellText)
If cell.Orientation <> xlHorizontal Then
strTemp = ""
' _
- <br>
For i = 1 Len(strCellText)
strTemp = strTemp & Mid$(strCellText, i, 1) & "<br>"
Next i
strCellText = strTemp
strStyle - ""
End If
strOut = strOut & vbTab & vbTab S "<td" & strStyle &
strAlign & ">" & strCellText & "</td>" & vbCrLf
Next
' <tr> </tr> -
strOut = vbTab & "<tr>" & vbCrLf & strOut & vbTab & "</tr>" & vbCrLf
1

<table>
strOut = "<table border=l cellpadding=3 cellspacing=l>"
& vbCrLf & strOut & vbCrLf & "</table>"

3.
' HTML-
Open strFileName For Output As 1
Print #1, strOut
Close 1
1


MsgBox Selection.Count & " " &
strFileName
End Sub
ExportAsHtmlFile,
Primer.htm ( ,
,
HTML-).
Windows ,
( , ). ,
-.


, Excel .
,
3.62.
3.62.
Sub CustomSearch ()
Dim strFindData As String
Dim rgFound As Range
Dim i As Integer
'
strFindData = InputBox(" ")
'
For i = 1 Worksheets.Count
With Worksheets(i).Cells
' i-
Set rgFound = .Find(strFindData, LookIn:=xlValues)
If Not rgFound Is Nothing Then
' -
Sheets (i) .Select
rgFound.Select
Exit Sub


End If
End With
Next
' .
MsgBox (" ")
End Sub

, . 3.20.
Microsoft Excel

. 3.20.

(, . .),
, . . ,
, . 3.21.
Microsoft !

. 3.21.

, ,
.


,
. ( 3.63).
3.63.
Sub EnableAutoFilter()
On Error Resume Next
Selection.AutoFilter
End Sub

3.
. ,
.


,
.



. ( 3.64).
3.64.
Sub ChangeNumberFormat()
Selection.NumberFormat = "0.00"
End Sub


(, 54 54, 00).
( 3.65).
3.65.
Sub T h r e e N u l l S e p a t a t o r ( )
Selection.NumberFormat = " # , # # "
End Sub

, , 1234567 1 234 5 67. , , .


-
, ( 3.66).
3.66.
Sub ChangeNumerFormatEx()
Selection.NumberFormat = "#,##0.00"
End Sub




. , 3.67.
3.67.
Sub

LastCharUpO
'
With A c t i v e C e l l . C h a r a c t e r s ( S t a r t : = L e n ( S e l e c t i o n )
, Length:=1) .Font
. S u p e r s c r i p t = True
End With
End Sub

, ,
3. , (, 72 ).


, .
( 3.68).
3.68.
Sub ChangeSelGrid()
1

1

With Selection.Borders(xlEdgeLeft)
.LineStyle = xlContinuous
.Weight = xlThin
.Colorlndex = xlAutomatic
End With
'
With Selection.Borders(xlEdgeRight)
.LineStyle = xlContinuous
.Weight = xlThin
.Colorlndex = xlAutomatic
End With
1

With Selection.Borders(xlEdgeTop)
.LineStyle = xlContinuous
.Weight = xlThin

3.
.Colorlndex = xlAutomatic
End With
'
With Selection.Borders(xlEdgeBottom)
.LineStyle = xlContinuous
.Weight = xlThin
.Colorlndex = xlAutomatic
End With
'
'
With Selection.Borders(xllnsideVertical)
.LineStyle = xlContinuous
.Weight = xlHairline
.Colorlndex = xlAutomatic
End With
1


With Selection.Borders(xlInsideHorizontal)
.LineStyle = xlContinuous
.Weight = xlHairline
.Colorlndex = xlAutomatic
End With
End Sub
. 3.22.

. 3.22.
, , .



, , . , , ( ).
, 3.69.


3.69.
Sub InsertCustomText()
'
ActiveCell = " "
Selection.Font.Bold - True
1

Cells(ActiveCell.Row, ActiveCell.Column + 3).Select
ActiveCell.FormulaRlCl = ". . "
Selection.Font.Bold = True
' " "

Cells(ActiveCell.Row + 3, ActiveCell.Column - 3).Select
ActiveCell = " "
Selection.Font.Bold - True
'
Cells(ActiveCell.Row, ActiveCell.Column + 3).Select
ActiveCell = ". . "
Selection.Font.Bold = True
End Sub

, (. 3.23).

"

"

. .

. .

. 3.23.
, .


. ( 3.70).
3.70.
Sub ShowFontDialog()
'
Application.Dialogs(xlDialogActiveCellFont).Show
End Sub

3.
, . ,
.


,
, , 3.71.
3.71.
Sub ShowInfoO
Dim i As I n t e g e r
'
Range("Al") =
'
Range("Bl") =


ActiveWorkbook.Name

ActiveSheet.Name

'
For i = 1 ActiveWorkbook.Sheets.Count
A c t i v e S h e e t . C e l l s ( i , 3) = i
Next i
End Sub
. 3.24.
...:::.

1 .xls
2
3
4

.| .

!
1

,1! J
2!
3
i

. 3.24.

1 , 1
, .


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


3.72.
Sub

ResultToWindowO
'
Worksheets(I).Activate
'
Range("A2") = 5
Range("A3") = "=2+3"
1

MsgBox Range("A3").Formula + " = " + str(Range("A3").Value)


End Sub

. 3.25.
Microsoft Excel
=2+3 = 8

LJOK
. 3.25.
, 2 5, A3 8.



( ).
( 3.73). Windows API GetSystemMetrics.
, ( 0 , 1
). GetSystemMetrics .
3.73.
' API-
Declare Function GetSystemMetrics Lib "user32"
(ByVal nlndex As Long) As Long
' ,

Const SM_CXSCREEN = 0
Const SM CYSCREEN = 1

3.
Sub GetMonitorResolution()
Dim lngHorzRes As Long
Dim lngVertRes As Long
'
lngHorzRes = GetSystemMetrics(SM_CXSCREEN)
lngVertRes = GetSystemMetrics(SM_CYSCREEN)
'
MsgBox " : " & lngHorzRes & "x" & lngVertRes
End Sub
( GetMonitorResolution)
, .

?

, .
( 3.74).
3.74.
Sub WorkBooksList()
Dim book As Object
'
For Each book In Workbooks
MsgBox (book.Name)
Next
End Sub
. , , , . . .
,
( 3.75).
.
3.75.
Sub

SheetsOfBookO
Dim s h e e t As Object
1

For Each s h e e t In ActiveWorkbook.Sheets
MsgBox (sheet.Name)
Next
End Sub


, .
, , , .


Excel ? , , ,
3.76.
3.76.
Dim intSpacesLeft As Integer
Sub Start ()

'


intSpacesLeft = 10
'
MovingString
End Sub
Sub MovingString()
If intSpacesLeft > 0 Then
'
Range("Al").Value = Space(intSpacesLeft) & "!"
intSpacesLeft = intSpacesLeft - 1
' Excel,
1
Application.OnTime Now + TimeValue("00:00:01") , "MovingString"
End If
End Sub

start 1 !.


VBA . , 3.77
1 !, 30 .
3.77.
Sub Movinglmage()
Dim i As Integer
Dim image As Object

3.
1

( "1")
With Range("Al")
' :
1

.Value = "!"
1

.Font.Bold True
'
.Font.Color = RGB(233, 133, 229)
'
.Font.Size = 16
'
.Orientation = 30
'
.EntireColumn.AutoFit
1

.
' (
)
Set image = ActiveSheet.Pictures.Paste(Link:=False)
'
.Clear
End With
' (
)
With image
.Top - 0
.Left = 0
End With
MsgBox "!"
With image
'
For i = 0 100
.Top = i
.Left = i
Next
'
.Delete


End With
1

Set image = Nothing
End Sub
, , ! (. 3.26) .

. 3.26.


,
( )
.
, , 10 5
. ( 3.78).
3.78.
Sub BlinkingCell()
Static intCalls As Integer

' 10 ,

If intCalls < 10 Then
intCalls = intCalls + 1
' ,
If Range("Al").Interior.Color <> RGB(255, 0, 0) Then
1
,

Range("Al").Interior.Color =!RGB(255, 0, 0)

3.
Else
1


Range("Al").Interior.Color = RGB(0, 255, 0)
End If
' 5
Application.OnTime Now + TimeValue("00:00:05"), "BlinkingCell"
Else
'
Range("Al").Interior.Colorlndex = xlNone
intCalls = 0
End If
End Sub

BlinkingCell Al (. 3.27).

_i

__

_J

. 3.27.


? , ,
, . , .
,
3.79 (
VBA).
3.79.
Sub RotatingAutoShapes()
Static fRunning As Boolean
' ,
If fRunning Then
'
fRunning = False
End
End If

,
fRunning = True
Dim
Dim
Dim
Dim
Dim

cell As Range
intLeftBorder As Long
intRightBorder As Long
intTopBorder As Long
intBottomBorder As Long

Dim alngVertSpeed(1 To 2) As Long


Dim alngHorzSpeed (1 To 2) As Long
Dim ashShapes(l To 2) As Shape
Dim i As Integer

'
'
'
'
'

'
'
1

'

'
Set ashShapes(l) = ActiveSheet.shapes(1)
Set ashShapes(2) = ActiveSheet.shapes(2)
' :
'
alngVertSpeed(1) = 3
alngHorzSpeed(1) 3
'
alngVertSpeed(2) = 4
alngHorzSpeed(2) = 4
'
Set cell = Range("B2")
intLeftBorder = cell.Left
intRightBorder = cell.Left + cell.Width
intTopBorder = cell.Top
intBottomBorder = cell.Top + cell.Height
'
Do
1


For i = 1 2
With ashShapes(i)
'
If .Left + .Width + alngHorzSpeed(i) > intRightBorder Then
1

.Left = intRightBorder - .Width

3.
1



alngHorzSpeed(i) = -alngHorzSpeed(i)
End If
'
If .Left + alngHorzSpeed(i) < intLeftBorder Then
'
.Left = intLeftBorder
'

alngHorzSpeed(i) = -alngHorzSpeed(i)
End If
r

'
If .Top + .Height + alngVertSpeed(i) > intBottomBorder Then
1

.Top = intBottomBorder - .Height
'

alngVertSpeed(i) = -alngVertSpeed(i)
End If
'
If .Top + alngVe.rtSpeed(i) < intTopBorder Then
1

.Top = intTopBorder
'

alngVertSpeed(i) = -alngVertSpeed(i)
End If
'
.Left = .Left + alngHorzSpeed(i)
.Top = .Top + alngVertSpeed(i)
' (

)
.IncrementRotation alngVertSpeed(i)
' Excel
DoEvents
End With
Next
Loop
End Sub


2 ( 2
, ,
).

, .
, , . - .



Colorindex ( ). ( 3.80).
3.80.
Sub ShowColorTable()
Dim intColor As Integer
'
Range("Al").Value = ""
Range("Bl").Value = " Colorindex"
1


Range ("A2") .Select
For intColor = 1 To 56
' ""
With ActiveCell.Interior
.Colorindex = intColor
.Pattern - xlSolid
.PatternColorlndex = xlAutomatic
End With
' ""
ActiveCell.Offset (0, 1).Value = intColor
1

ActiveCell.Offset(1, 0).Activate
Next

3.
1

"1" ( )
Range("Al").Select
ActiveWindow.ScrollRow - 1
End Sub
, . 3.28.

1
^ Colorlndex

. 3.28.

, Colorlndex. , 56 .


VBA, ,
.
, , 3.81.
3.81.
Sub SimpleCalculator()
Dim strExpr As String
'
strExpr = InputBox(" ?")
1

MsgBox strExpr & " = " & Application.Evaluate(strExpr)
End Sub


, . 3.29.
Microsoft Excel
*;: ?
Cancel

125+
. 3.29.

, , Enter. (. 3.30).
I Microsoft Excel
25+93=118
OK
. 3.30.

strExpr = inputBox (" ?") , , strExpr = InputBox (" "), . 3.31.


Microsoft !

. 3 . 3 1 .

(. 3.32).
Microsoft Excel
70

. 3.32.

3.



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


. , . ( 3.82).
3.82.
Sub Workbook_Open()
'
strMenuName = "MyCommandBarName"
'
CreateCustomMenu
End Sub
Sub Workbook_BeforeClose(Cancel As Boolean)
'
DeleteCustomMenu
End Sub
. .
3.83.
3.83.
Public strMenuName As String '
Private cbrcBar As CommandBarControl
Sub CreateCustomMenu()
Dim cbrMenu As CommandBar


Dim cbrcMenu As CommandBarControl

' ""

Dim cbrcSubMenu As CommandBarControl

' ""

,
DeleteCustomMenu
'
Set cbrMenu = Application.CommandBars.Add(strMenuName, msoBarTop,
True, True)
1

""

Set cbrcMenu = cbrMenu.Controls.Add(msoControlPopup, , , , True)


With cbrcMenu
.Caption = ""
End With
'
With cbrcMenu.Controls.Add(Type:=msoControlButton,
Temporary:=True)
.Caption = "&1"
.OnAction - "CallMenul"
End With
'
With cbrcMenu.Controls.Add(Type:=msoControlButton,
Temporary:=True)
.Caption = "2"
.OnAction = "CallMenu2"
End With
'
Set cbrcSubMenu = cbrcMenu.Controls.Add(Type:=msoControlPopup,
Temporary:=True)
With cbrcSubMenu
.Caption = "1"
.BeginGroup = True
End With
'
With cbrcMenu.Controls.Add(Type:=msoControlButton,
Temporary:=True)
.Caption = "/"
.OnAction = "MenuOnOff"
.Style = msoButtonlconAndCaption
.Faceld = 463
End With

3.
1


With cbrcSubMenu.Controls.Add(Type:=msoControlButton,
Temporary:=True)
.Caption = ""
.OnAction = "CallSubMenul"
.Style = msoButtonlconAndCaption
.Faceld = 2950
.State = msoButtonDown
End With
' ( _
"/") , _

Set cbrcBar = cbrcSubMenu.Controls.Add(Type:=msoControlButton,
Temporary:=True)
With cbrcBar
.Caption = "2"
.OnAction = "CallSubMenu2"
1

.Enabled = False
End With
'
Set cbrcSubMenu = cbrcSubMenu.Controls.Add(Type:=msoControlPopup,
Temporary:=True)
With cbrcSubMenu
.Caption ""
.BeginGroup = True
End With
'
With cbrcSubMenu.Controls.Add(Type:=msoControlButton,
Temporary:=True)
.Caption = ""
.OnAction - "CallLastMenul"
.Style msoButtonlconAndCaption
.Faceld = 71
.State = msoButtonDown
End With
'
With cbrcSubMenu.Controls.Add(Type:=msoControlButton,
Temporary:=True)
.Caption = ">2"
.OnAction = "CallLastMenu2"
.Style = msoButtonlconAndCaption


.Faceld = 72
.Enabled = True
End With
'
cbrMenu.Visible = True
Set cbrcSubMenu Nothing
Set cbrcMenu = Nothing
Set cbrMenu = Nothing
End Sub
Sub DeleteCustomMenu()
'
On Error Resume Next
Application.CommandBars(strMenuName).Delete
On Error GoTo 0
End Sub
Sub CallMenul()
' 1
MsgBox " 1!", vblnformation, ThisWorkbook.Name
End Sub
Sub CallMenu2()
' >2
MsgBox " 2!", vblnformation, ThisWorkbook.Name
End Sub
Sub CallSubMenul()
1

MsgBox " 1!", vblnformation, ThisWorkbook.Name


End Sub
Sub CallSubMenu2()
' 2
MsgBox " 2!", vblnformation, ThisWorkbook.Name
End Sub
Sub CallLastMenul()
' 1
MsgBox " 1! ", vblnformation, ThisWorkbook.Name
End Sub

3.
Sub CallLastMenu2()
' 2
MsgBox " 2 ! " , vblnformation,
End Sub

ThisWorkbook.Name

Sub MenuOnOff ()
' "-1-2"
cbrcBar.Enabled = Not cbrcBar.Enabled
End Sub
, CreateCustomMenu ( ). . 3.33.

. 3.33.

:
(. 3.34). / /
! 2.
l.xls
1!

. 3.34.


DeleteCustomMenu ( , DeleteCustomMenu).
Visual Basic ( , ).


, .
,
( )
.
VBA , 3.84.
3.84.
Sub CreateMenuO
Dim

cbrMenu As CommandBar

Dim

cbrcNewMenu As CommandBarControl

'

Call
'

DeleteMenu

Set

cbrMenu = CommandBars.Add(MenuBar:=True)

With cbrMenu
.Name = " "
. V i s i b l e = True
End
'

With

""

CommandBars("Worksheet Menu Bar").FindControl(ID:=30002).Copy


CommandBars(" ")
'

- ""

Set

cbrcNewMenu = cbrMenu.Controls.Add(msoControlPopup)

cbrcNewMenu.Caption = "^"
'

With

cbrcNewMenu.Controls.Add(msoControlButton)

.Caption = "&
.OnAction
End
'

With

With

cbrcNewMenu.Controls.Add(Type:=msoControlButton)

.Caption = "&"
End
End

"

= "DeleteMenu"

Sub

With

3.
Sub DeleteMenuO
1
(, )
On Error Resume Next
CommandBars(" ").Delete
On Error GoTo 0
End Sub

CreateMenu.
,
( )
. .
.

,
, ,
.
. ,
, 3.85 ( ).
3.85.
Public Sub PossessiveCase()
1

Dim strNamel As String, strName2 As String, strName3 As String
strNamel - dhGetName(ActiveCell, 1)
strName2 = dhGetName(ActiveCell, 2)
strName3 = dhGetName(ActiveCell, 3)

'
'
'

-
If strNamel = "" Or strName2 = "" Or strName3 = "" Then Exit Sub
'
Cells(ActiveCell.Row, ActiveCell.Column) = dhPossessive(
strNamel, strName2, strName3)
End Sub
Public Sub DativeCaseO
'
Dim strNamel As String, strName2
strNamel = dhGetName(ActiveCell,
strName2 = dhGetName(ActiveCell,
strName3 - dhGetName(ActiveCell,

As String, strName3 As String


1)
2)
3)

,
' -
If Len(strNamel) = 0 Or Len(strName2) = 0 Or Len(strName3) = 0
Then Exit Sub
Cells(ActiveCell.Row, ActiveCell.Column) = dhDative(
strNamel, strName2, strName3)
End Sub
Function dhPossessive(strNamel As String, strName2 As String,
strName3 As String) As String
Dim fMan As Boolean
' ,
fMan = (Right(strName3, 1) = "")
'
If Len(strNamel) > 0 Then
If fMan Then
1

Select Case Right(strNamel, 1)


Case "", "", "", ""
dhPossessive = strNamel
Case ""
dhPossessive=Mid(strNamel, 1, Len(strNamel) -2) +""
Case Else
dhPossessive strNamel + "a"
End Select
Else
1

Select Case Right(strNamel, 1)


Case "", "", "", "", "", "", "", "", "", "",
"", "", "", "", "", "", "", "", "", "",
"", "", ""
dhPossessive = strNamel
Case " "
d h P o s s e s s i v e = M i d ( s t r N a m e l , 1, Len(strNamel) - 2 ) S ""
Case Else
dhPossessive = Mid(strNamel, 1, Len(strNamel) - 1 ) & ""
End S e l e c t
End If
d h P o s s e s s i v e = dhPossessive & " "
End If

3.
1


If Len(strName2) > 0 Then
If fMan Then
'
Select Case Right(strName2, 1)
Case "", ""
dhPossessive = dhPossessive & Mid(strName2,
1, Len(strName2) - 1) & ""
Case Else
dhPossessive = dhPossessive & strName2 & "a"
End Select
Else
1

Select Case Right(strName2, 1)
Case "a"
Select Case Mid(strName2, Len(strName2) - 1, 1)
Case "", ""
dhPossessive = dhPossessive & Mid(
strName2, 1, Len(strName2) - 1) & ""
Case Else
dhPossessive = dhPossessive & Mid(strName2,
1, Len(strName2) - 1) & ""
End Select
Case ""
If Mid(strName2, Len(strName2) - 1, 1) = "" Then
dhPossessive = dhPossessive & Mid(strName2,
1, Len(strName2) - 1) & ""
Else
dhPossessive = dhPossessive & Mid(strName2,
1, Len(strName2) - 1) & ""
End If
Case ""
dhPossessive = dhPossessive & Mid(strName2,
1, Len(strName2) - 1) & ""
Case Else
dhPossessive = dhPossessive & strName2
End Select
End If
dhPossessive = dhPossessive & " "
End If
'
If Len(strName3) > 0 Then
If fMan Then
dhPossessive = dhPossessive & strName3 & "a"

,
Else
dhPossessive dhPossessive & Mid(strName3, 1,
Len(strName3) - 1) & ""
End If
End If
End Function
Function dhDative(strNamel As String, strName2 As String,
strName3 As String) As String
Dim fMan As Boolean
' ,
fMan - (Right(strName3, 1) = "")
1


If Len(strNamel) > 0 Then
If fMan Then
1

Select Case Right(strNamel, 1)
Case "", "", "", ""
dhDative = strNamel
Case ""
dhDative=Mid(strNamel, 1, Len(strNamel) -2) +""
Case Else
dhDative = strNamel + "y"
End Select
Else
'
Select Case Right(strNamel, 1)
Case "", "", "", "", "", "", "", "", "", "",
"", "", "", "", "", "", "", "", "", "", "", _
"", ""
dhDative = strNamel
Case ""
dhDative = Mid(strNamel, 1, Len(strNamel) - 2) & ""
Case Else
dhDative = Mid(strNamel, 1, Len(strNamel) - 1) & ""
End Select
End If
dhDative = dhDative & " "
End If
'
If Len(strName2) > 0 Then
If fMan Then

jLVT-1

3.
1


Select Case Right(strName2, 1)
Case "", ""
dhDative = dhDative & Mid(strName2, 1,
Len(strName2) - 1) & ""
Case Else
dhDative - dhDative & strName2 & "y"
End Select
Else
1

Select Case Right(strName2, 1)
Case "", ""
If Mid(strName2, Len (strName2) - 1, 1) = "" Then
dhDative = dhDative & Mid(strName2, 1,
Len(strName2) - 1) & ""
Else
dhDative = dhDative & Mid(strName2, 1,
Len(strName2) - 1) & "e"
End If
Case " "
dhDative - dhDative & Mid(strName2, 1,
Len(strName2) - 1) & ""
Case Else
dhDative = dhDative & strName2
End Select
End If
dhDative = dhDative & " "
End If
'
If Len(strName3) > 0 Then
If fMan Then
dhDative = dhDative & strName3 & "y"
Else
dhDative = dhDative& Mid(strName3, 1, Len(strName3) -1) & "e"
End If
End If
End Function
Function dhGetName(strString As String, intNum As Integer)
' intNum
strString
Dim strTemp As String
Dim intWord As Integer
Dim intSpace As Integer

strTemp = Trim(strString)
' ( )
For intWord = 1 intNum - 1
'
intSpace = InStr(strTemp, " ")
If intSpace = 0 Then
'
intSpace = Len(strTemp)
End If
' strTemp intWord
strTemp = Trim(Right(strTemp, Len (strTemp) - intSpace))
Next intWord
' ( )
intSpace = InStr(strTemp, " ")
If intSpace = 0 Then
intSpace = Len (strTemp)
End If
dhGetName = Trim(Left(strTemp,

intSpace))

End Function

,
PossessiveCase; DativeCase (
).

. .

, , ,
.
.

. VB
( 3.86).

3.
3.86.
' API-
Declare Function GetProfileStringA Lib "kernel32"
(ByVal lpAppName As String, ByVal lpKeyName As String,
ByVal ipDefault As String, ByVal lpReturnedString As
String, ByVal nSize As Long) As Long
Sub ()
Dim strFullInfo As String * 255
Dim
Dim
Dim
Dim
Dim
Dim

strlnfo As String
strPrinter As String
strDriver As String
strPort As String
strMessage As String
intPrinterEndPos As Integer

' API-
'
'
'
'

Dim intDriverEndPos As Integer


1

strFullInfo = Space (255)


'
Call GetProfileStringA("Windows", "Device", "", strFullInfo, 254)
'
' strlnfo <_>,<>,<>:
strlnfo = Trim(strFullInfo)
' ( )
intPrinterEndPos=Application.Find(",", strlnfo, 1)
intDriverEndPos =Application.Find(", ", strlnfo, intPrinterEndPos + 1)
'
strPrinter = Left(strlnfo, intPrinterEndPos - 1)
1

strDriver = Mid(strlnfo, intPrinterEndPos + 1, intDriverEndPos
- intPrinterEndPos - 1)
1
( ":")
strPort = Mid(strlnfo, intDriverEndPos + 1, InStr(l, strlnfo, ":")
- intDriverEndPos - 1)
'
strMessage = ":" & Chr(9) & strPrinter & Chr(13)
strMessage strMessage & ":" & strDriver & Chr(13)


strMessage = strMessage & " s t r P o r t : " & Chr(9) & s t r P o r t
1

MsgBox strMessage, vblnformation, " "
End Sub
API- GetProf ileStringA. - s t r F u l l l n f <_>,<>,<>:.
(
), , .


, . , ( 3.87).
3.87.
Sub TimeAndDate()
Dim strDate As String, strTime As String
Dim strGreeting As String
Dim strUserName As String
Dim intSpacePos As Integer
strDate = Format(Date, "Long Date")
strTime = Format(Time, "Medium Time")
1
-
If Time < TimeValue("12:00") Then
strGreeting = " , "
Elself Time < TimeValue("17:00") Then
strGreeting = " , "
Else
strGreeting = " , "
End If
1


strUserName = Application.UserName
intSpacePos = InStr(l, strUserName, " ", 1)
1
,
If intSpacePos = 0 Then intSpacePos = Len(strUserName)
strGreeting = strGreeting & Left(strUserName, intSpacePos)

3.
1


MsgBox strDate & vbCrLf & strTime, vbOKOnly, strGreeting
End Sub

. , , ,
( ).


Word Excel
, Word , Excel. , , , .
.
, (. 3.35).

1 | 1 500001
2 2 40000;
35000;
3 3
4
i
5

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


i
|

_7_
. 3.35.
|


( ).


VBA , 3.88.
3.88. Word Excel
Sub ReportToWord()
Dim intReportCount As Integer
Dim strForWho As String
Dim strSum As String

Word Excel
Dim
Dim
Dim
Dim
Dim
Dim

strProduct As String
strOutFileName As String
strMessage As String
rgData As Range
objWord As Object
i As Integer

'
'
'
'

' Word
Set objWord = CreateObject("Word.Application")
'
Set rgData = Range("Al")
strMessage = Range("E6")
' 1
intReportCount = Application.CountA(Range(":"))
For i = 1 To intReportCount
'
Application.StatusBar = " " & i
'
strForWho = rgData.Cells(i, 1).Value
strProduct = rgData.Cells(i, 2).Value
strSum = Format(rgData.Cells(i, 3).Value, "#,000")
'
StrOutFileName = ThisWorkbook.path & "\" & strForWho & ".doc"
' Word
With objWord
.Documents.Add
With .Selection
1

.Font.Size = 14
.Font.Bold = True
.ParagraphFormat.Alignment = 1
.TypeText Text:="O T 4 E T"
'
.TypeParagraph
.TypeParagraph
.Font.Size = 12
.ParagraphFormat.Alignment 0
.Font.Bold = False

3.
.TypeText Text:=":" & vbTab &
Format(Date, "mmmm d, yyyy")
'
. TypeParagraph
.TypeText Text:="KoMy: " & vbTab & strForWho
'
.TypeParagraph
.TypeText Text:="OT:" & vbTab & Application.UserName
'
.TypeParagraph
.TypeParagraph
.TypeText strMessage
.TypeParagraph
.TypeParagraph
'
.TypeText Text:=" :" & vbTab & strProduct
.TypeParagraph
1

.TypeText Text:="Ha :" & vbTab &
Format(strSum, "$#,##0")
End With
1


.ActiveDocument.SaveAs FileName:=strOutFileName
End With
Next i
1

Word

objWord.Quit
Set objWord = Nothing
'
Application.StatusBar = False
'
MsgBox intReportCount & " "
& ThisWorkbook.path
End Sub


ReportToWord. (
). , , .


1. doc, 2 . doc
3. doc. 1. doc . 3.36
( ).


: 20, 2005
:
1
:
Lesha




:

:
$50 000
. 3.36. Word, Excel

Lesha , . , .



. ( VBA) ,
3.89.
3.89.
Sub ListOfMenues()
Dim intRow As Integer
'
Dim cbrBar As CommandBar
'
Cells.Clear
intRow = 1

'

' _

For Each cbrBar In CommandBars

3.
1


Cells(intRow, 1) = cbrBar.Index
'
Cells(intRow, 2) = cbrBar.Name
1

Select Case cbrBar.Type


Case msoBarTypeNormal
Cells(intRow, 3) = " "
Case msoBarTypeMenuBar
Cells(intRow, 3) = " "
Case msoBarTypePopup
Cells(intRow, 3) = " "
End Select
'
Cells(intRow, 4) = cbrBar .Builtln
1


intRow = intRow + 1
Next
End Sub
(
) . 3.37.
''.'

.;.:

1
2
3

1,-1

"

1 Worksheet Menu Ba
2 Chart Menu Bar

3 Standard


4 Formatting
_
5 Pivottabie
' 6 Chart

Reviewing
;
8 Forms

9 Stop Recording

in

>

. 3.37.
.


Excel
, .
( 3.90).


3.90.
Sub ListOfMenues()
Dim intRow As Integer

' ,

Dim cbrcMenu As CommandBarControl

'

Dim cbrcSubMenu As CommandBarControl

'

Dim cbrcSubSubMenu As CommandBarControl

'

Cells.Clear
'
intRow = 1
1

On Error Resume Next

'

For Each cbrcMenu In CommandBars(1).Controls


1

cbrcMenu

For Each cbrcSubMenu In cbrcMenu.Controls


' cbrcSubMenu
For Each cbrcSubSubMenu In cbrcSubMenu.Controls
'
Cells(intRow, 1) = cbrcMenu.Caption
'
Cells(intRow, 2) = cbrcSubMenu.Caption
'
Cells(intRow, 3) = cbrcSubSubMenu.Caption
'
intRow = intRow + 1
Next cbrcSubSubMenu
Next cbrcSubMenu
Next cbrcMenu
End Sub

ListOfMenues ( ) .


,
, 3.91.

3.
3.91.
Sub

ListOfContextMenues()
Dim intRow As Long
Dim intControl As Integer
Dim cbrBar As CommandBar
'
Cells.Clear
'
intRow = 1
'
For Each cbrBar In CommandBars
If cbrBar.Type = msoBarTypePopup Then
'
Cells(intRow, 1) = cbrBar.Index
'
Cells(intRow, 2) = cbrBar.Name
'

For intControl = 1 cbrBar.Controls.Count
Cells(intRow, intControl + 2) =
cbrBar.Controls(intControl).Caption
Next intControl
'
intRow = intRow + 1
End If
Next cbrBar

'
Cells.EntireColumn.AutoFit
End Sub



( ,
) , , . -


, - . ,

: , . ,
, .
( 3.92).
3.92.
Sub Worksheet_SelectionChange(ByVal
'

Target As Excel.Range)

If Union(Target, Range("Al:D5")).Address =
Range("Al:D5").Address Then
'

CommandBars("AutoSense").Visible

= True

Else
'

CommandBars("AutoSense").Visible
End
End

= False

If

Sub

,
A1:D5 ( ).
, 3.93.
CreatePanel.

3.93.
Sub CreatePanel()
Dim cbrBar As CommandBar
Dim button As CommandBarButton
Dim i As Integer
' ( )
On Error Resume Next
CommandBars("AutoSense").Delete
On Error GoTo 0
'
Set cbrBar = CommandBars.Add

3.
1

For i = 1 4
Set button = cbrBar.Controls.Add(msoControlButton)
With button
.OnAction = "ButtonClick" & i
.Faceld = i + 37
End With
Next i
cbrBar.Name = "AutoSense"
End Sub
Sub ButtonClick3()
'
On Error Resume Next
ActiveCell.Offset(1, 0).Activate
End Sub
Sub ButtonClickl()
'
On Error Resume Next
ActiveCell.Offset(-1, 0).Activate
End Sub
Sub ButtonClick2()
'
On Error Resume Next
ActiveCell.Offset(0, 1).Activate
End Sub
Sub ButtonClick4()
'
On Error Resume Next
ActiveCell.Offset(0, -1).Activate
End Sub

AutoSense ,
. , A1:D5.
,
.

, .
, ,
.
.
.

1. .

VBA ( 3.94).
3.94.
Sub HidePanels()
Dim

cbrBar As CommandBar

Dim

intRow As I n t e g e r

'

Application.ScreenUpdating
'

False

Cells.Clear
1

intRow 1
For

'

Each cbrBar
If

In CommandBars

cbrBar.Type
If

= msoBarTypeNormal Then

cbrBar.Visible Then
cbrBar.Visible = False
Cells(intRow,

1) = cbrBar.Name

intRow = intRow + 1
End
End

If

If

Next
1

Application.ScreenUpdating
End

Sub

= True

3.
Sub

ShowPanelsO
Dim
'

cell

As Range

'

Application.ScreenUpdating
'

= False

On Error Resume Next


For Each c e l l In Range("A:A").SpecialCells(
xlCellTypeConstants)
CommandBars(cell.Value).Visible
Next
'

cell

Application.ScreenUpdating
End

= True

= True

Sub

: HidePanels
ShowPanels. , . 1 .

( - ).

, . , .

1 (. 3.38).
( 3.95).
3.95.
Sub Workbook_Open()
'
Call CreateCustomMenu
End Sub
Sub Workbook_BeforeClose(Cancel As Boolean)
'
Call DeleteCustomMenu
End Sub

-
.
D
!
1

1

/ 1 FacelD
1 &
2
10
!
, ,
1
3
2!&
{
4
3!&
GoToAssumptions
_J
3;&
GoToModel
5
GoToScenarios
6
3
3 &
GoToNotes
7
ViewScenarios
8
2 &
DataEntry

387
9
2 &

&
Printing
10
4!
11
2 &
ViewCharti
3 ^
12
433
ViewChart2
436!
3 &
13
3 ^ ViewCharG
14
427]
2 8.

15
Helpi
16
3 ^
\
Help2
17
3 ^

Help3
18
3 &
\ 41
< \"/
is
:

. 3.38.

( 3.96) .
3.96.
Sub CreateMenuO
Dim sheet As Worksheet
Dim intRow As Integer
Dim
Dim
Dim
Dim
Dim
Dim

cbrpBar As CommandBarPopup
objNewItem As Object
objNewSubltem As Object
intMenuLevel As Integer
strCaption As String
strAction As String

Dim flsDevider As Boolean


Dim intNextLevel As Integer
Dim strFacelD As String




cbrpBar
objNewItem

1

1

'
' _

'
'
'
'
'
'

'
Set sheet = ThisWorkbook.Sheets("")
' ( )
Call DeleteMenu

3.
'
intRow = 2
1

Do Until IsEmpty(sheet.Cells(intRow, 1))
'
With sheet
1


intMenuLevel = .Cells(intRow, 1)
1

strCaption = .Cells (intRow, 2)


'
strAction = .Cells(intRow, 3)
' ?
flsDevider = .Cells(intRow, 4)
' ( )
strFacelD .Cells(intRow, 5)
'
intNextLevel = .Cells(intRow + 1, 1)
End With
'
Select Case intMenuLevel
Case 1
'
Set cbrpBar = Application.CommandBars(1).
Controls.Add(Type:=msoControlPopup,
Before:=strAction,
Temporary:=True)
cbrpBar.Caption = strCaption
Case 2
'
If intNextLevel = 3 Then
1
,

Set objNewItem =
cbrpBar.Controls.Add(Type:=msoControlPopup)
Else
'
Set objNewItem =
cbrpBar.Controls.Add(Type:=msoControlButton)
objNewItem.OnAction = strAction
End If
1

objNewItem.Caption = strCaption

( )
If strFacelD "" Then
objNewltem.Faceld = strFacelD
End If
' ,
If flsDevider Then
objNewItem.BeginGroup = True
End If
Case 3
'
Set objNewSubltem =
objNewItem.Controls.Add(Type:=msoControlButton)
'
objNewSubltem.Caption = strCaption
1
( )
objNewSubltem.OnAction = strAction
1
( )
If strFacelD <> "" Then
objNewSubltem.Faceld = strFacelD
End If
1
,
If flsDevider Then
objNewSubltem.BeginGroup = True
End If
End Select
'
intRow = intRow + 1
Loop
End Sub
Sub DeleteMenu()
Dim sheet As Worksheet
Dim intRow As Integer
Dim strCaption As String

'
'
'

Set sheet = ThisWorkbook.Sheets("")


'
intRow = 2
' , "",
( 1)
On Error Resume Next
Do Until IsEmpty(sheet.Cells(intRow, 1))

3.
If sheet.Cells(intRow, 1) = 1 Then
strCaption = sheet.Cells(intRow, 2)
Application.CommandBars(1).Controls(strCaption).Delete
End If
intRow = intRow + 1
Loop
On Error GoTo 0
End Sub
CreateMenu
DeleteMenu .
.
, . 3.38 , . 3.39.
J
2

:*;;:

ijj.fi;

: | '

. 3.39.


, . .
, :
, , , , . (
)
. A2:D5.
: , .
, , ( 3.97).


3.97.
Sub Worksheet_BeforeRightClick(ByVal Target As Excel.Range,
Cancel As Boolean)
' ,
If Union(Target.Range("Al"), Range("A2:D5")).Address =
Range("A2:D5").Address Then
'
CommandBars("MyContextMenu").ShowPopup
Cancel = True
End If
End Sub

, 3.98.
3.98.
Sub Workbook_Open()
'
Call CreateCustornContextMenu
End Sub
Sub Workbook_BeforeClose(Cancel As Boolean)
'
Call DeleteCustomContextMenu
End Sub

3.99.
3.99.
Sub CreateCustomContextMenu()
'
Call DeleteCustomContextMenu
'
With CommandBars.Add("MyContextMenu", msoBarPopup, , True).Controls
'
1
" "
With .Add(msoControlButton)
.Caption = "& ..."
.OnAction = "ShowFormatNumber"
.Faceld = 1554
End With

3.
1

""
With .Add(msoControlButton)
.Caption = "^..."
.OnAction = "ShowFormatAlignment"
.Faceld = 217
End With
1
""
With .Add(msoControlButton)
.Caption = "..."
.OnAction = "ShowFormatFont"
.Faceld = 291
End With
1
""
With .Add(msoControlButton)
.Caption = "&..."
.OnAction = "ShowFormatBorder"
.Faceld = 149
.BeginGroup = True
End With
1
""
With .Add(msoControlButton)
.Caption = "&..."
.OnAction "ShowFormatPatterns"
.Faceld = 1550
End With
' ""
With .Add(msoControlButton)
.Caption = "&3..."
.OnAction = "ShowFormatProtection"
.Faceld - 2654
End With
End With
End Sub
Sub DeleteCustomContextMenu()
1

On Error Resume Next
CommandBars("MyContextMenu").Delete
End Sub
Sub ShowFormatNumber()
'
Application.Dialogs(xlDialogFormatNumber).Show
End Sub


Sub ShowFormatAlignment()
'
Application.Dialogs(xlDialogAlignment).Show
End Sub
Sub ShowFormatFont()
'
Application.Dialogs(xlDialogFormatFont).Show
End Sub
Sub ShowFormatBorder()
'
Application.Dialogs(xlDialogBorder).Show
End Sub
Sub ShowFormatPatterns()
' ()
Application.Dialogs(xlDialogPatterns).Show
End Sub
Sub ShowFormatProtection ()
'
Application.Dialogs (xlDialogCellProtection).Show
End Sub
(CreateCustomContextMenu)
(DeleteCustomContextMenu), , .
CreateCustomContextMenu , . 3.40.

..,

...
..,

...
...
..,

. 3.40.

A2:D5.
.

3.



(, ). , , 3.100.
3.100.
' API-

Declare Function SHBrowseForFolder Lib "shell32.dll"
Alias "SHBrowseForFolderA" (lpBrowselnf As BROWSEINFO) As Long
' API- ,
SHBrowseForFolder,
Declare Function SHGetPathFromlDList Lib "shell32.dll"
Alias "SHGetPathFromlDListA" (ByVal pidl As Long, ByVal
pszPath As String) As Long
' SHBrowseForFolder
Type BROWSEINFO
hwndOwner As Long
' ( )
pidlRoot As Long
'
strDisplayName As String
strTitle As String
'
ulFlags As Long
'
1
VBA
lpfn As Long
lParam As Long
ilmage As Long
End Type
Sub BrowseFolder()
Dim strPath As String
Dim strFile As String
Dim intRow As Long

' ,
'

'
strPath = dhBrowseForFolder()
If strPath - "" Then Exit Sub
If Right(strPath, 1) <> "\" Then strPath = strPath S "\"
'
ActiveSheet.Cells.ClearContents


ActiveSheet.Cells (I, 1) = " "
ActiveSheet.Cells(I, 2) = ""
ActiveSheet.Cells (1, 3) = "/"
ActiveSheet.Range("A1:C1").Font.Bold = True
' ...
1

strFile = Dir(strPath, 7)
intRow = 2
Do While strFile <> ""
' ""
ActiveSheet.Cells(intRow, 1) = strFile
' ""
ActiveSheet.Cells(intRow, 2) = FileLen(strPath & strFile)
' ""
ActiveSheet.Cells(intRow, 3) = FileDateTime(strPath & strFile)
'
strFile = Dir
intRow = intRow + 1
Loop
End Sub
Function dhBrowseForFolder() As String
Dim biBrowse As BROWSEINFO
Dim strPath As String
Dim lngResult As Long
Dim intLen As Integer
' BROWSEINFO
1
-
biBrowse.pidlRoot = 0&
1

biBrowse.strTitle = " "
'
biBrowse.ulFlags = &H1
1


lngResult = SHBrowseForFolder(biBrowse)
'
If lngResult Then
1
( )
strPath - Space$(512)

3.
If SHGetPathFromlDList(ByVal lngResult, ByVal strPath) Then
' Chr(O)
intLen - InStr (strPath, Chr$(0))
'
dhBrowseForFolder = Left(strPath, intLen - 1)
Else
' He
dhBrowseForFolder = ""
End If
Else
1
""
dhBrowseForFolder = ""
End If
End Function
API- Windows SHBrowseForFolder SHGetPathFromlDList.

, ( 0
). , .

BrowseFolder. ,
Windows
.
, (. 3.41).

_ I
1
/
624640 24.02.2004 12:52!
2 01 .doc
02 .doc
1712640 24.02.2004 15:01)
: 03 : 177664 19.02.2004 11:27
216576 24.02.2004 16:25:
5 04 .doc
J l 05 419840 24.02.2004 15:12:
06 .doc
416256 24.02.2004 15:11!
07 0 6yxy4eTe.doc
90624 24.02.2004 16:191
08 KOfleKc.doc
836096 23.02.2004 16:27:
10 09 .doc 1137664 24.02.2004 12:35:
11 10 . doc
987136 24.02.2004 12:49!
. 3 . 4 1 .


, ( ), .
. ( 3.101).


3.101.
1

API-

Declare Function SHBrowseForFolder Lib "shell32.dll"


Alias "SHBrowseForFolderA" (lpBrowselnfo As BROWSEINFO) As Long
' API- ,
SHBrowseForFolder,
Declare Function SHGetPathFromlDList Lib "shell32.dll"
Alias "SHGetPathFromlDListA" (ByVal pidl As Long, ByVal
pszPath As String) As Long
1

SHBrowseForFolder

Type BROWSEINFO
hwndOwner As Long

' ( )

pidlRoot As Long

'

strDisplayName As String
strTitle As String

'

ulFlags As Long

'

' VBA
lpfn As Long
lParam As Long
ilmage As Long
End Type
Sub BrowseFolderl()
Dim strPath As String

' ,

Dim strFile As String


Dim intRow As Long
1

'

strPath = dhBrowseForFolder()
If strPath = "" Then Exit Sub
If Right(strPath, 1) <> "\" Then strPath = strPath & "\"
'
ActiveSheet.Cells.ClearContents
ActiveSheet.Cells(1, 1) = " "
ActiveSheet.Cells(1, 2) - ""
ActiveSheet.Cells (1, 3) = "/"
ActiveSheet.Range("A1:C1").Font.Bold = True

3.
1

...
'
strFile = Dir(strPath, 7)
intRow = 2
Do While strFile <> ""
' ""
ActiveSheet.Cells(intRow, 1) = strPath & strFile
' ""
ActiveSheet.Cells(intRow, 2) = FileLen(strPath & strFile)
' ""
ActiveSheet.Cells (intRow, 3) - FileDateTime(strPath & strFile)
1

strFile = Dir
intRow intRow + 1
Loop
End Sub
Function dhBrowseForFolder() As String
Dim biBrowse As BROWSEINFO
Dim strPath As String
Dim lngResult As Long
Dim intLen As Integer
' BROWSEINFO
' -
biBrowse.pidlRoot = OS
'
biBrowse.strTitle = " "
1

biBrowse.ulFlags &H1
'
lngResult - SHBrowseForFolder(biBrowse)
'
If lngResult Then
' ( )
strPath = Space$(512)
If SHGetPathFromlDList(ByVal lngResult, ByVal strPath) Then
1
Chr(O)
intLen = InStr(strPath, Chr$(0))
1

dhBrowseForFolder = Left(strPath, intLen - 1)


Else
'
dhBrowseForFolder = " "
End

If

Else
' ""
dhBrowseForFolder = " "
End

If

End Function


BrowseFolderl. . 3.42.
:'<--

1
2
3
4


/
:\3\01 . 624640 24.02.2004 12:52!
C:\3aKOHbi\D2 1712640 24.02.2004" 15:01
:\3\03 177664 f9"02"2004TiT27|
:\3\04 216576 24.02.2004 16:25!
6 :\3\05 419840 24.02.2004 15:12!
:\3\06 . 416256 24.02.2004 15:11!

. 3.42.

,
.



.
, ( 3.102).
3.102.
Sub DrivesInfoO
Dim objFileSysObject As Object

'

Dim objDrive As Object

'

Dim intRow As Integer

'

'
Set objFileSysObject = CreateObject("Scripting.FileSystemObject")
1

Cells.Clear
'
intRow = 1

3.
1


On Error Resume Next
For Each objDrive In objFileSysObject.Drives
'
Cells(intRow, 1) = objDrive.DriveLetter
'
Cells(intRow, 2) = objDrive.IsReady
1

Select Case objDrive.DriveType
Case 0
Cells(intRow, 3) = ""
Case 1
Cells(intRow,
Case 2
Cells(intRow,
Case 3
Cells(intRow,
Case 4
Cells(intRow,
Case 5

3) = ""
3) = ""
3) = ""
3) = "CD-ROM"

Cells(intRow, 3) = "RAM"
End Select
'
Cells(intRow, 4) = objDrive.VolumeName
1

Cells(intRow, 5) = objDrive.TotalSize
1

Cells(intRow, 6) = objDrive.AvailableSpace
intRow = intRow + 1
Next
End Sub

Drivesinf . ,
. 3.43.
1
2
3
4
5

| | D I
E
!
1 _F
: |:
i
|
i ( [SYSTEM 10487197696 j 21977866241
D ! [ iWORK | 9523748864 1 49189765121
: iCD-ROM i
{

. 3.43.


, , , ,
.
, .


,
, ,
.
,
Excel . , 3.103 ( VBA).
3.103.
Sub CalculateAverage()
Dim strFistCell As String
Dim strLastCell As String
Dim strFormula As String
1

If ActiveCell.Row = 1 Then Exit Sub


1

strFistCell = ActiveCell.Offset(-1,

0).End(xlUp).Address

strLastCell - ActiveCell.Offset(-1,

0).Address

strFormula = "=AVERAGE(" & strFistCell & ":" & strLastCell & " ) "
'
ActiveCell.Formula = strFormula
End Sub

,
; , . , 5, , 2, A3 4 ( 1 ).

3.
4, 5 .



.
( 3.104).
3.104.
Sub ListOfFonts()
Dim cbrcFonts As CommandBarControl
Dim cbrBar As CommandBar
Dim i As Integer
1

(
"")
Set cbrcFonts = Application.CommandBars("Formatting").
FindControl(ID:=1728)
If cbrcFonts Is Nothing Then
' "" -
Set cbrBar = Application.CommandBars.Add
Set cbrcFonts = cbrBar.Controls.Add(ID:=1728)
End If
' ( )
Range("A:A").ClearContents
' ""
For i = 0 cbrcFonts.ListCount - 1
Cells (i + 1, 1) = cbrcFonts.List(i + 1)
Next i
' "",

On Error Resume Next
cbrBar.Delete
End Sub
.
.

. ,
Microsoft Office.


( ) , XLS.
, : TextOl. txt, TextO2 . t x t
TextO3. txt. ,
TextOl. t x t (. 3.44).
,0<1

| f | TEXTOl -
:

001

: 002
003
004
;oos
006
007
008
009
010
Oil
012

:oi3
:014
015
016
017
018

.019
:
020
021
022

: 023
024
025

12455
13223
8733
2873
11833
22833
5437
5842
8700
12873
1680
3349
6517
9124
1509
5683
6654

595

2599
164

9776
4510
9451
9706
8023

""

j 1, _-

. 3.44. TextOl .txt

, .
Excel,
, . VBA , 3.105.
3.105.
Sub ImportTextFiles()
Dim

fsSearch

As FileSearch

Dim

strFileName As String

Dim

strPath As String

3.
Dim i As Integer
'
strFileName = ThisWorkbook.path & "\"
strPath = "text??.txt"
1

FileSearch
Set fsSearch = Application.FileSearch
'
With fsSearch
'
.Lookln = strFileName
1

.FileName = strPath
1
,
.Execute
1
,
If .FoundFiles.Count - 0 Then
MsgBox " "
Exit Sub
End If
End With
'
For i = 1 To fsSearch.FoundFiles.Count
Call ImportTextFile(fsSearch.FoundFiles(i))
Next i
End Sub
Sub ImportTextFile(FileName As String)
'
Workbooks.OpenText FileName:=FileName,
Origin:=xlWindows,
StartRow:=l,
DataType:=xlFixedWidth,
Fieldlnfo:=
Array(Array(0, 1), Array(3, 1), Array(12, 1))
'
Range("Dl").Value = "A"
Range("D2").Value = "B"
Range("D3").Value = "C"
Range("El:E3") .Formula = "=COUNTIF(B:B, Dl) "
Range ("F1.-F3") .Formula = "=SUMIF (B:B, Dl, C:C) "
End Sub

Excel

importTextFiles.
Excel .
1, 02 . . 3.45
1.
] Microsoft Excel - 1
j

D * , # Gk v

& 4ai , - -? - '

| Arial Cyr

F3

=(:;;:)

! K&JCLJ a

~| "

D
_JA

2455|

10

II
2

11
14

. 3.45. 01

1: F1:F3 , .

Excel, 2000.

, , .

, , . .

Excel

. ,
Excel .

3.

Excel 2002 . , 2002.


VBA
( 3.106).
3.106.
Sub ShowSymbolTable ()
On Error Resume Next
' Charmap.exe -
Shell "Charmap.exe", vbNormalFocus
If Err <> 0 Then
MsgBox " .", vbCritical
End If
End Sub
ShowSymbolTable,
(. 3.46).

:

1 V

3 % &

5 7 8 9 : ',

I
] 1

<

)
=

*
>

3 8

2
\/

>

<

<:

'

<

ft

/0

Y 1
i

"

. 3.46.

Z [
V- V
1-1

'

f *
=

<

4 z
i TI
t {

...

1 2 3 4

:
i

. 13 X 3 S
w
V
V f {

t -> 1

1(

1 !
1

Excel
,
.
,
3.107.
3.107.
1
1

API-:

Declare Function OpenProcess Lib "kernel32"


(ByVal dwDesiredAccess As Long, ByVal blnheritHandle As Long,
ByVal dwProcessId As Long) As Long
'
Declare Function GetExitCodeProcess Lib "kernel32"
(ByVal hProcess As Long, lpExitCode As Long) As Long
'
Declare Function CloseHandle Lib "kernel32"
(hProcess) As Long
Sub ShowSymbolTablel()
Dim lProcessID As Long
Dim hProcess As Long
Dim lExitCode As Long
On Error Resume Next
' (Charman.exe).

lProcessID = Shell("Charmap.exe", 1)
If Err <> 0 Then
MsgBox " Charman.exe", vbCritical, ""
Exit Sub
End If
1
(lProcessID).
(handle)
hProcess = OpenProcess(&400, False, lProcessID)
' , ,
( Charman.exe ,
GetExitCodeProcess &103)
Do
GetExitCodeProcess hProcess, lExitCode
DoEvents
Loop While lExitCode = &H103
'
CloseHandle (hProcess)

3.
'
MsgBox "Charmap.exe "
End Sub
SnowSymbolTablel, , ,
. 3.46.
, Charmap.exe .


,
( , ). ,
.
, ,
12 , .
, .
.
VBA
, 3.108.
3.108.
Sub CreatePanel ()
Dim i As Integer
On Error Resume Next
1
( )
CommandBars(" ").Delete
On Error GoTo 0
' " "
With CommandBars.Add
.Name = " "
'
With .Controls.Add(Type:=msoControlDropdown)
' (, , )
.Caption = "DateDD"
.OnAction = "SetMonth"


.Style = msoButtonAutomatic
'
For i = 1 12
.Addltem Format(DateSerial(1, i, 1), "mmmm")
Next i
'
.Listlndex = 1
End With
1


.Visible = True
End With
End Sub
Sub SetMonth ()
'
On Error Resume Next
With CommandBars(" ").Controls("DateDD")
ActiveCell.Value = .List(.Listlndex)
End With
End Sub

: CreatePanel
SetMonth. (. 3.47), .

__.

1
3

5"
__

"
8
9:
10
11
":

.,

**" X h

HI

|
|

. 3.47.

,
.

3.



. ,
, - .
, .


, , ,
, . ,
Ctrl+Shift+C.
VBA , ( 3.109).
3.109.
Sub AddMenuItem()
Dim cbrpMenu As CommandBarPopup
' ( )
Call DeleteMenuItem
' ""
Set cbrpMenu = CommandBars(1).FindControl(ID:=30007)
If cbrpMenu Is Nothing Then
' He
MsgBox " ."
Exit Sub
Else
1

With cbrpMenu.Controls.Add(Type:=msoControlButton)
'
.Caption = " &, "
1

.Faceld = 348
' ( )
.ShortcutText = "Ctrl+Shift+C"
'
.OnAction = "ExecuteCommand"


'
.BeginGroup = True
End With
End If
' Ctrl+Shift+C
Application.MacroOptions
Macro:="ExecuteCommand",
HasShortcutKey:=True,
ShortcutKey:="C"
End Sub
Sub ExecuteCommand()
' ( )
On Error Resume Next
Cells.SpecialCells(xlCellTypeConstants, 23).ClearContents
End Sub
Sub DeleteMenuItem()
'
On Error Resume Next
CommandBars(1).FindControl(ID:=30007).
Controls(" &, ").Delete
End Sub
: AddMenuitem ( , ), DeleteMenuItem ( ) ExecuteCommand ( ).
, . 3.48.
,
, .
,
, ExecuteCommand.
, DeleteMenuItem.


, ,
.
.
, VBA ,
3.110.

3.
|

F7

X? ...
<

...
...

. ,,.


...
...

...

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

+: Wt+C

. 3.48.

3.110.
Dim AppObject As New Classl
Sub AddCommand()
Dim cbrpBar As CommandBarPopup
' ( )
Call DeleteCommand
1

""

Set cbrpBar = CommandBars(1).FindControl(ID:=30004)


If cbrpBar Is Nothing Then
' He
MsgBox " ."
Exit Sub
Else
'
With cbrpBar.Controls.Add(Type:=msoControlButton)
.Caption = "& "
.OnAction = "GhangeGridlinesState"
End With


End If
' AppObject
Set AppObject.AppEvents = Application
End Sub
Sub

DeleteCommand()
' ( )
On Error Resume Next
CommandBars(1).FindControl(ID:=30004).
Controls '& ").Delete

End Sub
Sub

GhangeGridlinesState()
' _
( - , - )
If TypeName(ActiveSheet) - "Worksheet" Then
ActiveWindow.DisplayGridlines =
Not ActiveWindow.DisplayGridlines
'
Call CheckGridlines
End If

End Sub
Sub

CheckGridlines()
Dim button As CommandBarButton
On Error Resume Next
' " " ""
Set button - CommandBars(1).FindControl(ID:=30004).
Controls("& ")
1

If ActiveWindow.DisplayGridlines Then
1

button.State = msoButtonDown
Else
1

button.State = msoButtonUp
End If
End Sub
VBA
( 3.111).

3.
3.111.
Public WithEvents AppEvents As Application
'
Sub AppEvents_SheetActivate(ByVal Sh As Object)
Call CheckGridlines
End Sub
'
Sub AppEvents_WorkbookActivate(ByVal Wb As Excel.Workbook)
Call CheckGridlines
End Sub
1

Sub AppEvents_WindowActivate
(ByVal Wb As Workbook, ByVal Wn As Window)
Call CheckGridlines
End Sub
AddCommand (
) , / (. 3.49).

|
...
< :
...

..,

. 3.49.
,
. .

DeleteCommand ( ).

4.
Microsoft Excel, ,
. , .


,
. , . ( 4.1).
4.1.
Sub RunAssistantDance()
Static intAction As Integer
' ( 16)
DoAssistantAction intAction
intAction = intAction + 1
If intAction < 16 Then
' 3
Application.OnTime Time + TimeValue("00:00:3") ,
"RunAssistantDance"
End If
End Sub
Sub DoAssistantAction(intAction As Integer)
Dim astAssistant As Assistant
Set astAssistant = Application.Assistant
'
astAssistant.Top = Application.ActiveWindow.Top
+ Application.ActiveWindow.Height / 2
astAssistant.Left = Application.ActiveWindow.Left
+ Application.ActiveWindow.Width / 2
'
astAssistant.On = True
astAssistant.Visible = True
' intAction
Select Case intAction
Case 0
astAssistant.Animation = msoAnimationAppear

, ,
Case 1
astAssistant.Animation
Case 2
astAssistant.Animation
Case 3
astAssistant.Animation
Case 4
astAssistant.Animation
Case 5
astAssistant.Animation
Case 5
astAssistant.Animation
Case 6
astAssistant.Animation
Case 7
astAssistant.Animation
Case 8
astAssistant.Animation
Case 9
astAssistant.Animation
Case 10
astAssistant.Animation
Case 11
astAssistant.Animation
Case 12
astAssistant.Animation
Case 13
astAssistant.Animation
Case 14
astAssistant.Animation
Case, 15
astAssistant.Animation
End Select
End Sub

- msoAnimationCheckingSomething
= msoAnimationBeginSpeaking
= msoAnimationCharacterSuccessMajor
= msoAnimationEmptyTrash
= msoAnimationGestureDown
= msoAnimationGestureLeft
= msoAnimationGestureRight
= msoAnimationGestureUp
= msoAnimationGetArtsy
= msoAnimationGetAttentionMajor
= msoAnimationGetAttentionMinor
= msoAnimationGetTechy
= msoAnimationGetWizardy
= msoAnimationGoodbye
= msoAnimationGreeting
= msoAnimationDisappear

RunAssistantDance , .
.

,
,
, - ,

4.
. , 4.2.
4.2.
Sub AssistantMessage()
Dim strTitle As String
Dim strMessage As String

'
'


strTitle = " - "
strMessage = "{cf 249}{ul 1} {1 0}?"
& vbCr & "{cf 6} He !"
'
With Application.Assistant
'
.On = True
. V i s i b l e = True
'

With

.NewBalloon

.BalloonType
'

= msoBalloonTypeButtons

"OK"

. b u t t o n = msoButtonSetOK
'

. Icon = msoIconAlert
'

.Heading = s t r T i t l e
1

.Text
1

= strMessage

.Show
End
End
End

With

With

Sub

, . 4.1.
. ,
,
, - (. ).
*

I \ ]

-4
. 4.1.


, , . ( 4.3).
4.3.
Sub AssistantCheckboxes()
Dim i As Integer
Dim strMessage As String
With Assistant
1

.On = True
.Visible = True
'
With .NewBalloon
' ...

.BalloonType = msoBalloonTypeButtons
1

.Heading = " "


1

.CheckBoxes(I).Text = ""
.CheckBoxes(2).Text - ""
.CheckBoxes(3).Text = " "
.button = msoButtonSetOkCancel

'
If .Show = msoBalloonButtonOK Then

4 .
1



For i = 1 3
If .CheckBoxes(i).Checked Then
strMessage strMessage &
.CheckBoxes(i).Text & vbCr
End If
Next
' (
)
If Len(strMessage) = 0 Then
MsgBox "No choice."
Else
MsgBox strMessage
End If
End If
End With
End With
End Sub

(. 4.2).

~
D
":
)|

. 4.2.



, . ( 4.4).


4.4.
Sub AssistantChooseColor ()
Dim intChoise As Integer
With Assistant
1

.On = True
.Visible = True
With .NewBalloon
' ...
1

.BalloonType = msoBalloonTypeButtons
'
.Heading = " ?"
'
.Labels (I) .Text = ""
'
.Labels(2).Text = ""
1

.Labels(3).Text - ""
'
.button = msoButtonSetNone
'
intChoise = .Show
'
MsgBox ": " & .Labels(intChoise).Text
End With
End With
' ( )
Select Case intChoise
Case 1
1

ActiveSheet.Cells.Interior.Color = RGB(255, 0, 0)
Case 2
'
ActiveSheet.Cells.Interior.Color = RGB(255, 255, 0)
Case 3
'
ActiveSheet.Cells.Interior.Color = RGB(0, 255, 0)
End Select
End Sub

4.
, . 4.3.

?
;

. 4.3.

, .
.
.

5.

Microsoft Excel
.
, , , .


, .
, (. 5.1), .

.'

D.

' '

'

1 ! 2 3! 4j
-; 1
15450!
42870
21014:
2
874521
25845 . 96214
25250
41521
:
4
14130:
25896
36985
45214

. 5 . 1 .

() . ( , , 1:4).
,
5.1.
5.1.
Sub CreateChart()
'
With Charts.Add
1


.SetSourceData Source:=Worksheets(1).Range("Al:E4")
'
.HasTitle = True
.ChartTitle.Text = " "
'
.Activate
End With
End Sub
, . 5.2.

. 5.2.
, (1:4),
.
, 1 ( , 1 ).
(. . 5.1) . ( 5.2).
5.2.
Sub CreateEmbeddedChart()
'
With Worksheets(1).ChartObjects.Add(100, 60, 250, 200)
'
.Chart.ChartType = xl3DArea
1

.Chart.SetSourceData Source:=Worksheets(1).Range("Al:E4")
End With
End Sub
. 5.3.
, .
. 5.3
, , , .

5.
.,.,1... . : ,..;> ...[-.
.....,'.] . . ... i

i_;j__?L._
; 1
2 ! !4 ;
i
15450
42870!
21014;
87452?
!
25250
415?
258457
2111

1
1413
25896J
36985;
452114*

L
1

. 5.3.

5.3.
Sub CreateCharOnSelection ()
' ( )
With ActiveSheet.ChartObjects.Add( _
Selection.Left + Selection.Width,
Selection.Top + Selection.Height, 300, 200).Chart
'
.ChartType = xlColumnClustered
1
-
.SetSourceData Source:=Selection, PlotBy:=xlColumns
1

.HasLegend = False
'
.HasTitle = True
.ChartTitle.Characters.Text = " "
1

.Parent.Select
End With
End Sub

. 5.4
, , .
, ,
.
.


!.:...1_.,._.:_

:...._.. JL...:..L.: : ,1 1.

[! ;2 3 4
!
155001
23400!
14200:
9700
?
1

?^30
15200

!
10900/
14500J
17000
Si'icC

II

. 5.4.


?
, . , 5.4 . gif.
5.4.
Sub SaveChartO
'

If

ActiveChart
'

I s Nothing Then

MsgBox " "


Else
1

. . .

ActiveChart.Export ActiveWorkbook.path
End

& "XflMarpaMMa.gif",

"GIF"

If

End Sub


.
.
. , 5.5.
5.5.
Sub

InteractiveSaveChart()
Dim strFileName As String

'

5.
' ,
If ActiveChart Is Nothing Then
'
MsgBox " "
Else
'
strFileName = Application.GetSaveAsFilename(
ActiveChart.Name & ".gif", " GIF (*.gif), *.gif", 1,
" GIF")
' ,
If strFileName "" Then
'
ActiveChart.Export StrFileName, "GIF"
End If
End If
End Sub
, , . GIF (. ), Windows
.



,
.
, ( ), (. 5.5).
__i
1

I/.-C. 1

:1 |2 ( s

2 1^311]1^111[1131121

. 5.5.

, 5.6. .
5.6.
Sub CreateChart()
'
Charts.Add


'
1

ActiveChart.ChartType = xlLineMarkers
1

ActiveChart.SetSourceData Range("Bl:E2"), xlRows


ActiveChart.Location xlLocationAsObject, Name
'
With ActiveChart
1

.HasTitle = True
.ChartTitle.Characters.Text = Name
'
.Axes(xlCategory, xlPrimary).HasTitle = True
.Axes(xlCategory, xlPrimary).AxisTitle.Characters.Text
- Sheets(Name).Range("Al").Value
'
.Axes(xlValue, xlPrimary).HasTitle - True
.Axes(xlValue, xlPrimary).AxisTitle.Characters.Text
= Sheets(Name).Range("A2").Value
'
.HasLegend = False
.HasDataTable = True
.DataTable.ShowLegendKey = True
'
With .Axes(xlCategory)
.HasMajorGridlines =
.HasMinorGridlines =
End With
With .Axes(xlValue)
.HasMajorGridlines =
.HasMinorGridlines =
End With
'
End With
End Sub

True
False

True
False

Sub DeleteChart()
'
ActiveSheet.ChartObj ects.Delete
End Sub


createChart. .

5.
: ( , ).
CreateChart,
DeleteChart (
).
. 5.6.
.,.;' ,
J
D
. j
!
F
(
G
J
1 [1 Man 2 : !4;
>3400;
14200;
9700;
2
15500
3
;
1
4
:
1
]
S : .
'
5
:
R
7

.
8

9
10

11

i-

l"

'

j'''!
<

''

*-

|
[__ 1 | 15500

| 23400

| 14200

9700

. 5.6.
.
GIF. .

i n t e r a c t i v e S a v e C h a r t ( ).
,
Windows .
, .


,
. , .
,
, ( 5.7).


5.7.
Sub ShowSheetCharts()
Dim strMessage As String
Dim i As Integer
1

For i = 1 To ActiveSheet.ChartObjects.Count
strMessage = strMessage & ActiveSheet.ChartObjects(i).Name _
& vbNewLine
Next i
'
MsgBox strMessage
End Sub


.
, ( ). ,
, 5.8.
5.8. ,
Sub ShowBookCharts()
Dim crt As chart
Dim strMessage As String
'
For Each crt In ActiveWorkbook.Charts
strMessage = strMessage & crt.Name & vbNewLine
Next
'
MsgBox strMessage
End Sub

, .


.
.
( 5.9).

5.
5.9.
Sub RandomChartColors()
Dim intGradientStyle As Integer, intGradientVariant As Integer
Dim i As Integer
' ,
If ActiveChart Is Nothing Then Exit Sub
1


For i = 1 ActiveChart.SeriesCollection.Count
With ActiveChart.SeriesCollection(i)
' ()
intGradientStyle = Int(Rnd * 7) + 1
If intGradientStyle = 6 Then intGradientStyle = 1
If intGradientStyle = 7 Then
intGradientVariant = Int(Rnd * 2) + 1
Else
intGradientVariant = Int(Rnd * 4) + 1
End If
1

.Fill.TwoColorGradient Style:=intGradientStyle,
Variant:=intGradientVariant
' (
)
.Fill.ForeColor.SchemeColor = Int(Rnd * 57) + 1
.Fill.BackColor.SchemeColor = Int(Rnd * 57) + 1
End With
Next i
End Sub

, .


, . , , ( 5.10).
5.10.
Sub TransparentChart()
Dim shpShape As Shape
Dim dblColor As Double


Dim
Dim
Dim
Dim

srSerie As Series
intBorderLineStyle As Integer
intBorderColorlndex As Integer
intBorderWeight As Integer

' ,
If ActiveChart Is Nothing Then Exit Sub
'
For Each srSerie In ActiveChart.SeriesCollection
If (srSerie.ChartType = xlColumnClustered Or
srSerie.ChartType = xlColumnStacked Or
srSerie.ChartType = xlColumnStackedlOO Or
srSerie.ChartType m xlBarClustered Or
srSerie.ChartType = xlBarStacked Or _
srSerie.ChartType = xlBarStackedlOO) Then
1

dblColor - srSerie.Interior.Color
'
intBorderLineStyle = srSerie.Border.LineStyle
'
intBorderColorlndex = srSerie.Border.Colorlndex
'
intBorderWeight = srSerie.Border.Weight
'
Set shpShape = ActiveSheet.shapes.AddShape
(msoShapeRectangle, 1, 1, 100, 100)
With shpShape
'
.Fill.ForeColor.RGB = dblColor
'
.Fill.Transparency = 0.4
'
.Line.Visible = msoFalse
End With
1

shpShape.CopyPicture Appearance:=xlScreen,
Format:=xlPicture
'

With srSerie
1

.Paste

5.

WWi
1


.Border.Weight - intBorderWeight
1

.Border.LineStyle = intBorderLineStyle
'
.Border.Colorlndex = intBorderColorlndex
End With
'
shpShape.Delete
End If
Next srSerie
End Sub

. . F i l l . Transparency = 0.4
40 %.
. , . 5.7 ,
60 % ( . 5.4 ).

35000

.......

:.......

..

:
_

30000 25000

20000
15000 10000 5000 -

. 5.7.




, . ,
. ,
, ,
.


, ,
, . . 5.8.
:

!_._ 1___!__1
::;v c L

. ( :i

1 4;
_1__|6.
4;
;
!

1
2 !
j
3 ] ! { j 4 .
34 [:
1
25000:^
3100;|
1500i
29600!
4:
25000!
3200!
25400!
3100]
3250!
31850^
5
1 2
|'"'2
3200!
'25400!
28400!
6 i 3!
17400!
3600!
7400!
J6
7 !
4;
3;'
17400j
3600!
2500 i
28700!
9200!
40400!
~7~)

2500!
28700!
20740!
8 ! 4!
3140
9100:
8500i
8
3140! 69900!
9100!
51240:
29850; 150990:
^
i 8:
j
f
'i
3"1 i
51240!
69900!

::::: i:::::::.x:::...::j

''?

. 5.8.
, , , 5.11.
5.11.
Sub

ManyCharts()
Dim intTop As Long, i n t L e f t As Long
Dim i n t H e i g h t

As Long, intWidth As Long

Dim s h e e t As Worksheet
Dim lngFirstRow As Long
'
Dim i n t S e r i e As I n t e g e r
'
Dim s t r E r r o r S h e e t s As S t r i n g ' ,

intTop = 1

intLeft = 1

intHeight - 180

intWidth = 300

' ,
For Each sheet In ActiveWorkbook.Worksheets
If sheet.Name <> ActiveSheet.Name Then
'
lngFirstRow 3
'
intSerie = 1
On Error GoTo DiagrammError
'

5.
With ActiveSheet.ChartObjects.Add
(intLeft, intTop, intWidth, intHeight).Chart
Do Until IsEmpty(sheet.Cells(lngFirstRow + intSerie, 1))
'
.SeriesCollection.NewSeries
'
.SeriesCollection(intSerie).Values =
sheet.Range(sheet.Cells(lngFirstRow + intSerie, 2),
sheet.Cells(lngFirstRow + intSerie, 4))
'
.SeriesCollection(intSerie).XValues =
sheet.Range("B3:D3")
' ( "" )
.SeriesCollection(intSerie) .Name = sheet.Cells (
lngFirstRow + intSerie, 1)
intSerie = intSerie + 1
Loop
1

.ChartType = xl3DColumnClustered
.ChartGroups(1).GapWidth

=20

.PlotArea.Interior.ColorIndex = xlNone
.ChartArea.Font.Size = 9
1

.HasLegend = True
1

.HasTitle = True
.ChartTitle.Characters.Text = sheet.Range("Al")
'
.Axes(xlValue).MinimumScale = 0
.Axes(xlValue).MaximumScale = 120000
' ()
.Axes(xlValue).MajorGridlines.Border.
LineStyle = xlDot
End With
On Error GoTo 0
'

intTop = intTop + intHeight
AfterError:
End If
Next sheet


If strErrorSheets " " Then
1
,
MsgBox " :" & Chr(13)
& strErrorSheets, vbExclamation
End If
Exit Sub
DiagrammError:
1
,
( )
strErrorSheets = strErrorSheets & sheet.Name & Chr(13)
'
ActlveSheet.ChartObj ects(ActiveSheet.ChartObj ects.Count).Delete
'
Resume AfterError
End Sub
.
, . , , .
, 1 (, . 5.8
4, 4). ,
, .


Excel , . , .
, , , . 5.9.
VBA ( 5.12).
5.12.
Sub ShowLabelsO
Dim rgLabels As Range
'
Dim chrChart As Chart
'
Dim i n t P o i n t As Integer
' ,
'
Set chrChart = ActiveSheet.ChartObjects(1).Chart

5.

. 5.9.
'
On Error Resume Next
Set rgLabels = Application.InputBox
(prompt:=" ", Type:=8)
If rgLabels Is Nothing Then Exit Sub
On Error GoTo 0
'
chrChart.SeriesCollection(1).ApplyDataLabels
Type:=xlDataLabelsShowValue,
AutoText:=True,
LegendKey:=False
'
For intPoint = 1 chrChart.SeriesCollection (1) .Points.Count
chrChart.SeriesCollection (1).
Points(intPoint).DataLabel.Text = rgLabels(intPoint)
Next intPoint
End Sub
Sub DeleteLabels()
'
ActiveSheet.ChartObjects(1).Chart.SeriesCollection(1).
HasDataLabels
False
End Sub

: ShowLabels (
) DeleteLabels ( ).


ShowLabels , .
. 5.10 .

i |
100J
119!

3 -

S Anp
'6-
{
8

'
90!
250"

50]
165;

"
210"
170!
200
300!
218?
161!'

300

[.,,

200

300

. 5.10.

2:9.



Microsoft Excel.


, , , .


. , 6.1.
, .
6.1.
Const
Const
Const
Const

dhcMinCol
dhcMaxCol
dhcMinRow
dhcMaxRow

=
=
=
=

1
35
1
35

'
'
'
'

Sub C l e a r ( )
1

Range (Cells (dhcMinRow, dhcMinCol), _
Cells(dhcMaxRow, dhcMaxCol)).Select
Selection.Clear
'
ClearGrid
Range("Al").Select
End Sub
Sub ClearGrid()
1
( )...
'
Selection.Interior.Colorlndex = xlNone
1

Selection.Borders(xlDiagonalDown).LineStyle = xlNone
Selection.Borders(xlDiagonalUp).LineStyle xlNone
Selection.Borders(xlEdgeLeft).LineStyle = xlNone
Selection.Borders(xlEdgeTop).LineStyle = xlNone
Selection.Borders(xlEdgeBottom).LineStyle = xlNone

6.

rwi

Selection.Borders(xlEdgeRight).LineStyle = xlNone
Selection.Borders(xllnsideVertical).LineStyle = xlNone
Selection.Borders(xlInsideHorizontal).LineStyle = xlNone

End Sub
Sub DrowCrosswordGrid()
1

'
Selection.Interior.Colorlndex - 35
'
Selection.Borders(xlDiagonalDown).LineStyle = xlNone
Selection.Borders(xlDiagonalUp).LineStyle = xlNone
' ,
,

On Error Resume Next
1


With Selection.Borders(xlEdgeLeft)
.LineStyle = xlContinuous
.Weight = xlThln
.Colorlndex = xlAutomatic
End With
'
With Selection.Borders(xlEdgeRight)
.LineStyle = xlContinuous
.Weight = xlThin
.Colorlndex = xlAutomatic
End With
'
With Selection.Borders(xlEdgeTop)
.LineStyle = xlContinuous
.Weight = xlThin
.Colorlndex = xlAutomatic
End With
'
With Selection.Borders(xlEdgeBottom)
.LineStyle = xlContinuous
.Weight - xlThin
.Colorlndex = xlAutomatic


End With
'
With Selection.Borders(xllnsideVertical)
.LineStyle = xlContinuous
.Weight = xlThin
.Colorlndex = xlAutomatic
End With
'
With Selection.Borders(xlInsideHorizontal)
.LineStyle = xlContinuous
.Weight = xlThin
.Colorlndex = xlAutomatic
End With
End Sub
Sub DisplayGrid()
'
ActiveWindow.DisplayGridlines = True
End Sub
Sub HideGridO
'
ActiveWindow.DisplayGridlines = False
End Sub
Sub AutoNumberO
' ,
Dim intRow As Integer
'
Dim intCol As Integer
'
Dim cell As Range

' (
(intRow, intCol))

Dim fTop As Boolean

' = True, cell

Dim fBottom As Boolean

' = True, cell

Dim fLeft As Boolean

' = True, cell

Dim fRight As Boolean

' = True, cell

Dim intDigit As Integer

'

intDigit = 1

' 1

' ,
, _
( )

6.
For intRow = dhcMinRow To dhcMaxRow
For intCol = dhcMinCol To dhcMaxCol
'
Set cell = Cells(intRow, intCol)
' , ( )
If cell.Interior.Colorlndex = 35 Then
fLeft = False
fRight = False
fTop = False
fBottom = False
On Error Resume Next
' ...
1

fTop = cell.Offset(-1, 0).Interior.Colorlndex = 35


'
fBottom = cell.Offset(1, 0).Interior.Colorlndex - 35
'
fLeft = cell.Offset(0, -1).Interior.Colorlndex = 35
'
fRight = cell.Offset(0, 1).Interior.Colorlndex = 35
On Error GoTo 0
1


If (Not fTop And Not fLeft) Or
(Not fBottom And Not fLeft And fRight) Or
(Not fLeft And fRight) Or
(Not fTop And fBottom) Then
1


SetDigit intDigit, cell
intDigit = intDigit + 1
End If
End If
Next intCol
Next intRow
End Sub
Sub SetDigit(intDigit As Integer, cell As Range)
1
intDigit , cell
cell.Value = intDigit
1
,


cell.Font.Size = 6
1

cell.HorizontalAlignment = xlLeft
cell.VerticalAlignment = xlTop
End Sub i
Sub ToPrintO
1

Cells.Interior.Colorlndex = xlNone
End Sub
Sub ToNumberO
'
UserForml.Hide
UserForm2.Show
End Sub
6.1 ( ):
Q DrowCrosswordGrid ;
Q Clear ;

ClearGrid ;

AutoNumber ;

DisplayGrid ;

Q HideGrid ;

ToPrint ;

Q S e t D i g i t ( AutoNumber );

ToNumber (. ).

. ,
. .


,
.
, . 6.1.

6.
[-

( ?-9

. 6 . 1 .

( , , , ):

DisplayGrid;

Q HideGrid;
c l e a r ;
Q DrawCrasswordGrid;
Q c i e a r G r i d ;
ToNumber.
( )
, . 6.2.
( ):
Q AutoNumber;
Q c l e a r ;
Q ToPrint.
, ,
, . , ()
.
, . .

- . ; / : .

::

...

. 6.2.



. .
, (. 6.3).
!A|B|O|D|E|F|G|H| HJlKltlMlNlOlPlHiIJJJJ>

i
|

. 6..

. 6.4.
(. . 6.2).
. (. 6.5).
,
(. 6.6).

6.
D F G 1 J L N 0 Q R S

;
1

2
3
4
5

11
12
13
14
. 6 .4 <

: C.I-OI.E! F
1
(
2
S
3

.
13

3
22
4 2)
5
2?
2
6
31

36
8

9 39
10 11
16

12 i'i
S1
6U
13

-11

5*

SS

J
8

N 0
9

10

|R
13

12

13

S
15

16

23

21

25

<

31

31

33

11

12

" I

IT

52

S3

I
I
5

. 6.5.

1
2
3
4
5
6
7
8
9
10
11
12

D FjG
2

15

17
21

K|L
8

10

0
It

:Q R

12

13

11

s
IS

T U
i6

13

IS

22

21

25

26
2

28

23

30

31

32

33

31

35

35

37

10

35
12

13

11
15

16

50
51

17

IS

51

S3

53

56

57

la

1
16

. 6.6.


.
, ,
( ) .
,
.


Windows , , . , Excel, .
, , .
, :
, , .
( 6.2).
6.2.
Sub Worksheet_SelectionChange(ByVal
Target As Range)
Dim i n t C o l As I n t e g e r , intRow As I n t e g e r
Dim intMinesAround As I n t e g e r
Dim fInGameField As Boolean
1

,
fInGameField = (Target.Row >= 2) And (Target.Row <= 7) _
And (Target.Column >= 2) And (Target.Column < 7)
'
If Target.Value = "*" And fInGameField Then
1
-
T a r g e t . F o n t . C o l o r - RGB(0, 0, 0)
T a r g e t . I n t e r i o r . C o l o r = RGB(255, 0, 0)
' !
EndGame
E l s e l f flnGameField Then
' .
T a r g e t . I n t e r i o r . C o l o r = RGB(0, 0, 255)
T a r g e t . F o n t . C o l o r = RGB(0, 255, 0)
T a r g e t . F o n t . S i z e = 16

6.
' ( )
For intCol = Target.Column - 1 To Target.Column + 1
For intRow = Target.Row - 1 To Target.Row + 1
If Target.Worksheet.Cells(intRow, intCol).Value = "*"
Then
'
intMinesAround = intMinesAround + 1
End If
Next
Next
'
Target.Value = intMinesAround
End If
End Sub
, , ( 6.3).
6.3.
Sub NewGame()
'
'
InitGame
Dim intRow As Integer, intCol As Integer
Dim intMinesCount As Integer
'
' (
"*" ,
)
For intMinesCount = 1 10
' ( 2 7)
intRow = Int((6 * Rnd) + 1) + 1
' ( 2 7)
intCol = Int((6 * Rnd) + 1) + 1
1

,
If Cells(intRow, intCol) <> "*" Then
Cells(intRow, intCol).Font.Color =
Cells(intRow, intCol).Interior.Color
Cells(intRow, intCol).Value = "*"
Else
' -
intMinesCount = intMinesCount - 1
End If


Next
1

Application.StatusBar = " " & intMinesCount
End Sub
Sub InitGame()
' ()
Dim intRow As Integer, intCol As Integer
1


Cells.Interior.Color = RGB(0, 200, 75)
'
Cells.Font.Color = RGB(0, 0, 0)
'
Cells.Font.Size = 18
' -
Cells .HorizontalAlignment = xlCenter
'
For intRow = 2 7
For intCol = 2 7
Cells(intRow, intCol).Interior.Color = RGB(200, 200, 200)
Cells(intRow, intCol).Value = ""
Next
Next
End Sub
Sub EndGame()
' ()
Dim intRow As.Integer, intCol As Integer
' .
( "*"
)
For intRow = 2 7
For intCol = 2 7
If Cells(intRow, intCol).Value = "*" Then
Cells(intRow, intCol).Font.Color = RGB(0, 0, 0)
End If
Next
Next
MsgBox ""
End Sub

6.
B2:G7.
(
, ) NewGame (
).
. 6.7 .

...
5

a
9
H

*
* BBI
F

: - mm

A
1 *

-'^' 1

G:

1 *1

iilllSS

1
....

iSillli3
1

Jliiilll

< >\\ \ \2 /"/

. 6.7.

,.


NewGame. .
.
, .
(
).


, . , , . ,
: - , .
, , Main Data. Main
, .
, (-


). , , - : " " . .
Data . 6.8 (

).

?
2 3
2 .
5 6
?
4
5
6
7
............ \ Main /Data/ 1'

D
7

.7

. 6.8. Data

. Main , 6.4.
6.4.
Sub StartGame()
Dim intLastRow As Integer
Dim intRow As Integer

'
'

Dim intYesRow As Integer

' ,

Dim intNoRow As Integer

' ,

Dim strText As String

' _

Dim strNewName As String


'
Dim strNewQuestion As String '
Dim intRes As Integer
'
MsgBox " . .", vbOKOnly,
" "
' .
intLastRow-1 - ,
intLastRow = Worksheets("Data").Range("Dl").Value + 1
'
intRow = 1

6.
Do While intRow < intLastRow
' ""
strText = Worksheets("Data").Cells(intRow, 1).Value
' , _
, ""
intYesRow = Worksheets("Data").Cells(intRow, 2).Value
' ,
, ""
intNoRow = Worksheets("Data").Cells(intRow, 3).Value
If intYesRow > 0 Then
' strText .
intRes = MsgBox(strText, vbYesNo, "")
If intRes = vbYes Then
'
intRow = intYesRow
Else
'
intRow = intNoRow
End If
Else
' . strText -
. ,
intRes = MsgBox(" " & strText & "?", vbYesNo, "")
If intRes = vbYes Then
'
MsgBox "! !", vbOKOnly,
" "
Exit Do
Else
1
, .
,
strText
'
strNewName = InputBox(". ?",
" ")
If strNewName <> "" Then
' ,
strNewQuestion = InputBox(" , " &
" '" & strNewName &
"' '" & strText & " + ", " ")
If strNewQuestion "" Then
' ,


intRes = MsgBox(" " &
" - " & strNewName & "'", vbYesNo,
" ?")
'
Worksheets("Data").Cells(intLastRow, 1 ) .
Value = strNewName
1
,
,
Worksheets("Data").Cells(intLastRow + 1 , 1 ) .
Value = strText
'
Worksheets("Data").Cells(intRow, 1 ) .
Value = strNewQuestion
'
,

If intRes = vbYes Then
' -
Worksheets ("Data") .Cells(intRow, 2 ) .
Value = intLastRow
Worksheets ("Data") .Cells(intRow, 3 ) .
Value = intLastRow + 1
Else
' -
Worksheets ("Data") .Cells(intRow, 2 ) .
Value = intLastRow + 1
Worksheets("Data").Cells(intRow, 3 ) . _
Value = intLastRow
End If
1

Worksheets("Data").Range("Dl").Value =
intLastRow + 2
End If
End If
1
.
MsgBox " !", vbOKOnly, " "
Exit Do
End If
End If
Loop
End Sub

6.
Main ( ) startGame. , . 6.9.

. .

. 6 . 9 .

,
, .
, ,
, ,
. .
, , , . . , , , ,
, .
( ). , . , .
, ,
, .
. ,
,
, . ( ).
(), ( ).
.
,
. ( ) . ( ) , , ,
. ( )
.
t
, D1 , . ( ) .

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


, VBA , , ,
.
VBA ( 6.5).
6.5.
Const
Const
Const
Const
Const
Const
Const
Const
Const
Const
Const

dhcSum As Integer =
dhcAvg As Integer = 1
dhcMax As Integer = 2
dhcMin As Integer = 3
dhcCount As Integer = 4
dhcSumPlus As Integer = 5
dhcSumMinus As Integer = 6
dhcCountFull As Integer = 7
dhcCountNotNull As Integer = 8
dhcCountPlus As Integer = 9
dhcCountMinus As Integer = 10

Sub CalcColors()
1

Load frmColorCalc
frmColorCalc.Show
End Sub

6.
Public Function ColorCalc(strRange As String,
lngColor As Long, fBackBolor As Boolean,
intMode As Integer, Optional fAbsence As Boolean) As Double
'

Dim rgData As Range
Dim i As Integer
Dim Values () As Variant
Dim intCount As Integer
Dim cell As Range
Dim varOut As Variant


'
'
'
'

Set rgData = Range(strRange)


ReDim Values(1 To rgData.Count)
' . , _
, Values
For Each cell In rgData.Cells
' :
If fBackBolor = True Then
'

If fAbsence Then
' ,

If cell.Interior.Color <> lngColor Then
intCount = intCount + 1
Values(intCount) cell.Value
End If
Else
' ,

If cell.Interior.Color = lngColor Then
intCount = intCount + 1
Values (intCount) = cell.Value
End If
End If
1
-
Else
'


If fAbsence Then
' ,

If cell.Font.Color <> lngColor Then
intCount = intCount + 1
Values (intCount) = cell.Value
End If
Else
' ,

If cell.Font.Color lngColor Then
intCount = intCount + 1
Values (intCount) = cell.Value
End If
End If
End If
Next cell
1

, intMode

For i = 1 intCount
Select Case intMode
Case dhcSum, dhcAvg
'
varOut = varOut + Values(i)
Case dhcSumPlus
'
If Values(i) > 0 Then varOut = varOut + Values(i)
Case dhcSumMinus
'
If Values(i) < 0 Then varOut = varOut + Values(i)
Case dhcMax
'
If Values(i) > varOut Then varOut = Values(i)
Case dhcMin
'
If i = LBound(Values) Then varOut = Values(i)
If Values(i) < varOut Then varOut = Values(i)
Case dhcCount
1

varOut = varOut + 1
Case dhcCountFull

6.
'
If Not IsEmpty(Values(i)) Then varOut = varOut + 1
Case dhcCountNotNull
'
If Not IsEmpty(Values(i)) And Values(i) <> 0 Then
varOut " varOut + 1
Case dhcCountPlus
'
If Values(i) > 0 Then varOut = varOut + 1
Case dhcCountMinus
'
If Values(i) < 0 Then varOut = varOut + 1
End Select
Next i
'
If intMode = dhcAvg Then
'
ColorCalc = varOut / intCount
Else
ColorCalc = varOut
End If
End Function
:
Q ColorCalc ( );
Q CalcColors (. ).
VBA ,
6.6.
6.6.
Dim lngCurColor As Long ' ,
()
Dim intMode As Integer '
Sub cmbApplyColor_Click()
If cboOtherColor.Value >= 0 Then
'
lngCurColor = cboOtherColor.Value
SetColorSum
End If
End Sub


Sub cmbColorl_Click()
'
lngCurColor - cmbColorl.BackColor
SetColorSum
End Sub
Sub cmbColor2_Click()
'
lngCurColor = cmbColor2.BackColor
SetColorSum
End Sub
Sub cmbColor3_Click()
'
lngCurColor = cmbColor3.BackColor
SetColorSum
End Sub
Sub cmbColor4_Click()
'
lngCurColor = cmbColor4.BackColor
SetColorSum
End Sub
Sub cmbColor5_Click()
1

lngCurColor = cmbColor5.BackColor
SetColorSum
End Sub
Sub cmbColor6_Click()
'
lngCurColor = cmbColor6.BackColor
SetColorSum
End Sub
Sub cmbColor7_Click()
'
lngCurColor = cmbColor7.BackColor
SetColorSum
End Sub

6.
Sub cmbColor8_Click()
'
lngCurColor = cmbColor8.BackColor
SetColorSum
End Sub
Sub cmbColor9_Click()
1

lngCurColor = cmbColor9.BackColor
SetColorSum
End Sub
Sub cmbColorlO_Click()
'
lngCurColor = cmbColorlO.BackColor
SetColorSum
End Sub
Sub cmbColorll_Click()
'
lngCurColor = cmbColorll.BackColor
SetColorSum
End Sub
Sub cmbColorl2_Click()
'
lngCurColor = cmbColor12.BackColor
SetColorSum
End Sub
Sub SetColorSum()
'
Dim strFormula As String
'
If txtResCell.Value = "" Then
MsgBox " ",
vbCritical, "!"
txtResCell.SetFocus
Exit Sub


Elself txtRange.Value = "" Then
MsgBox " ",
vbCritical, "!"
txtRange.SetFocus
Exit Sub
End If
1

strFormula = "=ColorCalc(" & """" & txtRange.Value & "


& "," & lngCurColor & "," & CInt(tglType.Value) & ","
& intMode & "," & CInt(chkVarify.Value) & " ) "
'
Range(txtResCell.Value).Formula = strFormula
End Sub
Sub cmbExit_Click()
'
Unload Me
End Sub
Sub cboCalcTypes_AfterUpdate()
1
-

intMode = cboCalcTypes.Listlndex
End Sub
Sub cboOtherColor_Change()
' ""
If cboOtherColor .Text <> "" Then
1

lngCurColor = Val(cboOtherColor.Value)
End If
End Sub
Sub tglType_Click()
'
If tglType.Value =
'
tglType.Caption
Else
'
tglType.Caption

-1 Then

= ""

= ""

6.
End If
GetColors
End Sub
Sub txtRange_AfterUpdate ()
1
-
,
GetColors
End Sub
Sub txtRange_BeforeUpdate(ByVal Cancel As MSForms.ReturnBoolean)
' ,

Dim rgData As Range
Dim cell As Range
1

,
If txtRange.Text = "" Then
MsgBox " !",
vbCritical, " "
Cancel - True
End If
If txtResCell.Text = "" Then Exit Sub
On Error GoTo Errl
' (
)
Set rgData = Range(txtRange.Text)
For Each cell In rgData.Cells
If cell.Address(False, False) =
Range(txtResCell.Text).Address(False, False) Then
1

MsgBox " " &
" ", vbCritical,
"!"
Cancel = True
Exit Sub
End If
Next cell
Exit Sub
Errl:
'
If Err.Number = 1004 Then


MsgBox " ", vbCritical,
" "
Cancel = True
Exit Sub
Else
MsgBox Err.Description, vbCritical, " "
Cancel - True
Exit Sub
End If
End Sub
Sub txtResCell_BeforeUpdate(ByVal Cancel As MSForms.ReturnBoolean)
' ,

Dim rgData As Range
Dim cell As Range
' ,
If txtRange.Text "" Then
MsgBox " !",
vbCritical, " "
Cancel = True
End If
If txtResCell.Text = "" Then Exit Sub
On

Error GoTo Errl


(
)
Set rgData = Range(txtRange.Text)
For Each cell In rgData.Cells
If cell.Address(False, False) =
Range(txtResCell.Text).Address(False, False) Then
'
MsgBox " " &
" ", vbCritical,
"!"
Cancel = True
Exit Sub
End If
Next cell
Exit Sub
1

Errl:
'

6.
If Err.Number = 1004 Then
MsgBox " ", vbCritical,
" "
Cancel = True
Exit Sub
Else
MsgBox Err.Description, vbCritical, " "
Cancel = True
Exit Sub
End If
End Sub
Sub UserForm_Activate()
'
Dim intFunc As Integer
Dim strFunc As String
'
cboCalcTypes.Addltem "0"
cboCalcTypes.List(0, 1) - ""
cboCalcTypes.Addltem "1"
cboCalcTypes.List(1, 1) = ""
cboCalcTypes.Addltem "2"
cboCalcTypes.List(2, 1) = ""
cboCalcTypes.Addltem "3"
cboCalcTypes.List(3, 1) = ""
cboCalcTypes.Addltem "4"
cboCalcTypes.List(4, 1) = " "
cboCalcTypes.Addltem "5"
cboCalcTypes.List(5, 1) = " "
cboCalcTypes.Addltem "6"
cboCalcTypes.List (6, 1) = " "
cboCalcTypes.Addltem "7"
cboCalcTypes.List(7, 1) = " "
cboCalcTypes.Addltem "8"
cboCalcTypes.List(8, 1) = " "
cboCalcTypes.Addltem "9"
cboCalcTypes.List(9, 1) = " "
cboCalcTypes.Addltem "10"
cboCalcTypes.List(10, 1) = " "


cboOtherColor.Addltem "255"
cboOtherColor.List(0, 1) = ""
cboOtherColor.Addltem "52479"
cboOtherColor.List(1, 1) = ""
cboOtherColor.Addltem "65535"
cboOtherColor.List(2, 1) - ""
cboOtherColor.Addltem "32768"
cboOtherColor.List(3, 1) = ""
cboOtherColor.Addltem "1677 6 960"
cboOtherColor.List(4, 1) = ""
cboOtherColor.Addltem "16711680"
cboOtherColor.List(5, 1) = ""
cboOtherColor.Addltem "16711935"
cboOtherColor.List(6, 1) = ""
cboOtherColor.Addltem "16777215"
cboOtherColor.List(7, 1) = ""
cboOtherColor.Addltem "0"
cboOtherColor.List (8, 1) ""
If Selection.Cells.Count = 1 Then
1
. ,
ColorCalc
intFunc = InStr(Selection.Formula, "ColorCalc (")
If intFunc > 0 Then
1

txtResCell.Text = Selection.Address(False, False)


' ...
'
strFunc = Mid(Selection.Formula, intFunc + 11)
intFunc = InStr(strFunc, """")
txtRange.Text = Left(strFunc, intFunc - 1)
1

( )

strFunc
intFunc
strFunc
intFunc

=
=
=
=

Mid(strFunc, intFunc + 2)
InStr(strFunc, ",")
Mid(strFunc, intFunc + 1)
InStr(strFunc, ",")

tglType.Value = Left(strFunc, intFunc - 1)

6.
'
strFunc = Mid(strFunc, intFunc + 1)
strFunc Left(strFunc, Len(strFunc) - 1)
intFunc = InStr (strFunc, ",")
cboCalcTypes.Text cboCalcTypes.List(Val(Left$( _
strFunc, intFunc - 1)), 1)
strFunc = Mid(strFunc, intFunc + 1)
chkVarify.SetFocus
chkVarify.Value = CBool(strFunc)
lblChoose.Visible = True
GetColors
Else
1

txtRange.Value = Selection.Address(False, False)
' .

cboCalcTypes.Text = ""
End If
Else
. '
txtRange.Value = Selection.Address(False, False)
' .

cboCalcTypes.Text = ""
End If
End Sub
Sub GetColors ()
' ,

Dim rgCells As Range
Dim i As Integer
Dim intColorNumber As Integer
'

Dim lngCurColor As Long
'
Dim fColorPresented As Boolean '
lngCurColor
Dim Ctrl As Control
Dim strCtrl As String
Dim fBackColor As Boolean
' = True,
,
= False -


fBackColor - tglType.Value
On Error Resume Next
'
For Each Ctrl In Me.Controls
If Left(Ctrl.Name, 8) = "cmbColor" Then
Ctrl.Visible - False
End If
Next ctrl
On Error GoTo ErrRange
Set rgCells = Range(txtRange.Text)
On Error GoTo 0
'
If fBackColor = False Then
lngCurColor = rgCells.Cells(i).Font.Color
Else
lngCurColor = rgCells.Cells(i).Interior.Color
End If
'
cmbColorl.BackColor = lngCurColor
cmbColorl.Visible = True
'
,
intColorNumber = 2
For i = 2 rgCells.Cells.Count
fColorPresented = False
1

i-
If fBackColor = False Then
lngCurColor = rgCells.Cells(i).Font.Color
Else
lngCurColor = rgCells.Cells(i).Interior.Color
End If
' ,
For Each ctrl In Me.Controls
If Left(ctrl.Name, 8) = "cmbColor" And
Ctrl.Visible = True Then
If lngCurColor = ctrl.BackColor Then
1
i-
fColorPresented = True

6.
Exit For
End If
End If
Next Ctrl
If Not fColorPresented Then
1
lngCurColor -
intColorNumber = intColorNumber + 1
strCtrl = "cmbColor" & intColorNumber
Me.Controls(strCtrl).BackColor = lngCurColor
Me.Controls(strCtrl).Visible = True
End If
Next i
Exit Sub
ErrRange:
'
If txtRange.Text = "" Then
MsgBox " ",
vbCritical, "!"
Else
MsgBox " ",
vbCritical, "!"
End If
'

txtRange.SetFocus
End Sub

, 6.6, , . 6.10.
( VBA Properties ()):
f rmColorCalc;
( )
cmbColorl cmbColorl2;

Q txtRange;

txtResCell;

cboOtherColor, ColumnCount 2;
Q , , cmbApplyColor;
Q cboCalcTypes,
ColumnCount 2;

chkvarif ;

Q ToggleButton tglType.

. 6.10.
, .
(, , )
CalcColors, . .


, CalcColors, , , . 6.10.
.
(, 5:15). ,
.
, ; . . , , , ,
, , , , . , .
,
.

6.
, .
, , . ,
, () .
:
Q ;

Q ;

Q ();
();
Q ();

();

D ();
Q ().
.
, , , :
=ColorCalc("D14:F17";255;0;0;0)

ColorCalc ;

D14: F17 (
);

2 5 5 , ( );
Q 0 () ,
( -1);
Q 0 () , ( ); , CalcColor;
Q 0 () , ,
( 1, , ; , ).
.
ColorCalc.

7.
, Excel, .
,
. .
- ?
, , Microsoft.
, ?
, . . , .
, Excel.
Excel
. . . , , ?
. : ,
.
, ,
, , , .
- Excel?
, Excel , .
.
,
Microsoft Office Update. Excel ( , ), .', .
Excel ?
Excel .

. , , -

7 .
.
. ,
, .
Excel ?
Microsoft Excel :
0 1 2 3 4 5 6 7 8 9

+ - ( ) , / $ % .

(+), , , . , , .
Excel , ?
, , , . , ,
, . , 15, 7 7., .
, , .
. , .
?
, ,
Excel ,
. , , , ,
, .
Excel , , ?
, . Microsoft Excel
, . , , ,
( ), .
, ,
, F2, Enter, .
Excel?
,
15 . 15 , 15- ().

7 .
- , Excel , , ?
, . , , , , , .
, HKEY_CURRENT_USER\
Software\Microsoft\Of f iceMO. 0\Excel\Options ( 10.0
9.0 8.0 )
UndoHi s t o r y DWORD. , . . ,
.
?

,
.
, , ?
Excel . .
, .
.

.
,
( ),
, ?
,
.
Private, : P r i v a t e Sub ().
, Private .
, ?

Run Application. :
Run "Primer.xlsIMyMacro"

, Primer.xls.

7 .
VBA ?
. .
VBA
(). ?
, ,
,
: , .
Microsoft?
,
Microsoft Office. , - . , . Microsoft.

.
. ?
P e r s o n a l . x l s . , , , .
, .
Excel . ,
. ?
, . ,
. , . , .
.

, ,
. , , , #!.
, X Y ?
.

7.
Excel , ?
(, ) Excel 2000, .
1. Excel.
2. F5.
3. X2OOO:L2OOO, Enter.
4. Tab .
5. Ctrl Shift,
, . , .

Excel 2000. Excel 2002 .
- ,
Excel -?
, , , , .
, .
?
. ,

. .
Excel, , ?
. ,
, Excel, :
Excel ( )
. / ( , !). 0
Excel , .
,
Excel. .

7.
Excel 2002 ,
( , )?
, .
.
, .
, , ?

. , 255.
? Enter .
, , . Enter . Alt+Enter
, .
?
. , ,
, ( , ). Excel XLStart (
:\Program Files\Microsoft Office\Office 10\XLStart), Excel.
- , .
Excel ?
, .
,
(
). . , , .

7.
?
.
Alt,
.

, ?

, , 0,00.
. ,
,
.
.
, . . , .
Excel 2000 , VBA .
Excel 2002 . ?
, Excel 2002
Visual Basic Project. .
, .
,
, . ( ) , . ,
, , ?
. .
. .
Excel ?
Excel . . ,

7 .

. , Ctrl Shift. .
, (, 100, . .). ,
?
,
. .

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

( ) .
, . - ?
Ctrl * (
). .
, ?
Ctrl+Alt+F9.
, -
, . ,

7.
, .
?
. , ( ,
Ctrl), ,
, . . , ,
.
- ?
. - ,
VBA. , 1 ,
1:2:
Worksheets ("1") .ScrollArea

= "1:20"


:
Worksheets("1").ScrollArea

=""

, ScrollArea , .
Workbook_Open.
, , . , ?
, .

1 . 1 . .
, ... % .
, ?
Excel . .
, (
) , . . , -

7.
;
( ,
);
.
- ?
,
Excel 2002. .
.
. Excel
.
,
( , , . .) VBA?
VBA Tools Options ( )
Editor Format ( ). .

, , .

?
, ,
Excel, .
, , ,

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

7.
( ,
).
VBA Option Explicit. ?
Option E x p l i c i t , , ,
. , VBA Tools Options ( ), Editor ()
Require Variable Declaration ( ).
.
?
, VBA, .
s t a t u s B a r Application. :
Application.StatusBar = " " & FileNum

.
:
Application.StatusBar False
,
. Excel
. ?
(
), .
, .

. Excel
Microsoft Excel:

Application;

Q Chart;
Range;

Workbook;

Q Worksheet.
, , , .

Application
Application Microsoft Excel. Excel.
Application (Cell,
Range .) (ActiveCell, ActiveChart .).
, Application
, Cell A p p l i c a t i o n . Cell,
Application .
. .1 Application.
.1. Application

ActiveCell


Range

. Range,
,
.
, Nothing

ActiveChart

Chart

. Chart,

. ,
Nothing

ActiveSheet

Worksheet

. Worksheet,

. ,
Nothing

. Excel
.1. Application ()

ActiveWindow

Window

. Window,

. ,
Nothing

ActiveWorkbook

Workbook

. Workbook,
,
.
,
Nothing

Caller

Range

Range ,

String


Auto_Open, Auto_Close, Auto_Activate
Auto_Deactivate.

,
OnDoubleClick
OnEntry

Error

Error ,

Caption

String

,

Excel.
,
Empty

Cells

Range

. Range
.
,
( Nothing)

Charts

Sheets

. (
Sheets),
( Chart).
Nothing,

Columns

Range

. Range,

. Nothing,

CommandBars

CommandBars

.
CommandBars,
CommandBar ( , ,
.)

Dialogs

Dialogs

Application

EnableCancelKey

XlEnableCancelKey

, Excel
Ctrl+Pause Break, Esc,

FileSearch

FileSearch

FileSearch,

Range

Range

. Range,

Rows

Range

. Range,

. Nothing,

ScreenUpdating

Boolean


Excel

Selection

Object

.
.
, Nothing.

( Range)

Sheets

Sheets

Sheets,
(
ActiveWorkbook. Sheets). He ,

StatusBar

String

,
Excel.

False

ThisWorkbook

Workbook

. Workbook
,

Windows

Windows

.
Windows,

Workbooks

Workbooks

.
Workbooks,

WorksheetFunction WorksheetFunction

.
WorksheetFunction,

Worksheets

.
Worksheets,
(
ActiveWorkbook.Worksheets). He
,

Worksheets

. Excel
. .2 Application.
.2. Application

InputBox

Prompt (String)
;
Title (Variant) ;
Default (Variant) ,
;
Left (Variant) Z-
;
Top (Variant) F-
;
HelpFile (Variant)
;
HelpContextld (Variant)

;
Type (Variant)

Variant



.
.
HelFile
HelpContextld,

.
, ,
(Range)
,

Intersect

Range

Range

Range,

OnTime

EarliestTime (Variant) ,
;
Procedure (Variant)
;
LatestTime (Variant)

;
Schedule (Variant)


,
Procedure,

EarliestTime . Excel


LatestTime ,
.
Schedule, True,

Run

Macro (Variant) ,
Range,
DLL;
Argl-Arg30 (Variant)

,

DLL
XLL.

Union

Range

Range

Range,

Chart

Wait

Time (Variant)

Boolean


,
Time.
True,

Chart
chart
, ChartObject. Chart : ,
.
. . Chart.
.. Chart

ChartArea

ChartArea

. ChartArea,
, (
, , .)

ChartTitle

ChartTitle

. ChartTitle,

ChartType

XlChartType

HasTitle

Boolean

, .

PlotArea

PlotArea

. PlotArea,

. .4 Chart.
.4. Chart

Activate

()

. Excel
.4. Chart ()

ApplyDataLabels

Type (XlDataLabelsType)
;
LegendKey (Variant)
;
AutoText (Variant)

;
HasLeaderLines (Variant)
;
ShowSeriesName (Variant)

;
ShowCategoryName (Variant)

;
Show Value (Variant)
;
ShowPercentage (Variant)


;
ShowBubbleSize (Variant)

(
);
Separator (Variant)

Axes

Type (XIAxisType) ;
AxisGroup (XIAxisGroup)

Object

Export

FileName (String)
;
FilterName (Variant)
;
Interactive (Variant)

Boolean



,

.
Interactive True,


,


.
True,


.
,

.

,



( LegentKey
ShowBubbleSize).

True
( )
False (
).
Separator

,

Range

Location

Where (XlChartLocation)
;
Name (Variant)
,
Where

SeriesCollection

Index (Variant)

SetSourceData

Source (Range)
;
PlotBy (XIRowCol)



(


)
Object


,

(Series),

(SeriesCollection)


.

,

(
)

Range
Range , , ,
. Range ,
Excel.
. .5 Range.
.5. Range

Address


String

. ,
Range.
Range ,
,
.
Range ,

,

Areas

Areas

. ,
,
Range

. Excel
.5. Range ()

Borders

Cells

Range

. Range
,

Column

Long

.
,
Range

Columns

Range

. Range,
,
Range

Comment

Comment

. Comment,

Count

Long

. ,
,
Range

End

Range

. Range,


EntireColumn

Range

. Range
, ,

EntireRow

Range

. Range
, ,

Font

Font

Font,
( ,
.)

Formula

Variant

FormulaLocal

Variant

FormulaRlCl

Variant


.
R1C1. R ,
(, 10
R1C10)

Height

Variant

HorizontalAlignment

Variant

Borders

.
Border,
[ )

Range

Interior


Interior
. Interior,

Left

Variant

Name

Names

(
).
Name

Next

Range

. Range

NumberFormat

Variant


.
, NULL

Offset

Range

. Range
,

Orientation

Variant


(
). -90 90

Parent

Object

.
,
()

Range

Range

. Range

Row

Long

. ,

Range

Rows

Range

. Range,
,
Range

Text

String

. ,
Range

Top

Variant

.
Range

Value

Variant

VerticalAlignment

Variant

Width

Variant

Worksheet

Worksheet

. Worksheet,
,

. Excel
. .6 Range.

.6. Range

()
.
,

Activate

AddComment

Text (Variant)


.
Text

AutoFilter

Field (Variant)
,
;
Criteria I (Variant)
;
Operator
(XIAutoFilterOperator)

;
Criteria2 (Variant)
;
VisibleDropDown (Variant)



.

Criteria 1
Criteria2.
,
Operator.

VisibleDropDown
True,

Clear

(,
.),
,


ClearComments

ClearContents

Copy

Destination (Variant)
,



Windows
.
-
Destination.
,

Range

Find

FindNext

What (Variant)
;
After (Variant)
;
Lookln (Variant)
;
LookAt (XlLookAt)
;
SearchOrder (XlSearchOrder)
;
SearchDirection
(XlSearchDirection)
;
MatchCase (Variant)
;
MatchByte (Variant)
;
SearchFormat (Variant)

After (Variant) ,

What
.
After (
)
.

,
( ,
.),
Lookln.

LookAt
.
SearchDirection

.


Range

,
Find

Select
Sort

Range

Keyl (Variant) ;
Orderl (XlSortOrder)
;
2 (Variant) ;
Order2 (XlSortOrder)
;
(Variant) ;
Order3 (XlSortOrder)
;
Header (XlYesNoGuess)
;
OrderCustom (Variant)


;
MatchCase (Variant)
;
Orientation (XlSortOrientation)
;
SortMethod (XlSortMethod)



( 1 3). ,
,
Keyl-.

(
)
Order 1-Order3.
Orientation ,
.

Header True,
( )
.
MatchCase
True,
.
SortMethod
.
DataOptionlDataOption3 ,

. Excel
.6. Range ()

Sort

DataOptionl
(XlSortDataOption)

;
DataOption2
(XlSortDataOption)
;

Range


,
:
,
(,
),

Value
(, )

DataOption3
(XlSortDataOption)

SpecialCells

Type (XlCellType)
;
Value (XlSpecialCellsValue)

Workbook
Workbook , Excel. , , , . Workbook
.
. .7 Workbook.
.7. Workbook

Charts

Sheets

. Sheets,

Name

String

Names

Names

. Names,

( ,
, )

Path

String

. ,
. ,

Workbook


ProtectStructure Boolean
. True,
. False
Sheets

Sheets

. Sheets,
(
, )

Windows

Windows

. Windows,
Window

Worksheets

Sheets

. Sheets,

. .8 Workbook.

.8. Workbook

Protect
Password (Variant)
;
Structure (Variant)
;
Windows (Variant)

SaveAs

.
Password,

.
Structure True,
,
Windows True,

,
FileName
FileFormat .
Password,
.
WriteResPassword,

.
ReadOnlyRecommended (Variant)

(

Password).
;
CreateBackup
CreateBackup (Variant)
True
;

AccessMode (Variant)
.
;
AccessMode
ConflictResolution (Variant)
ConflictResolution

.
(
Local,
);
True,
AddToMra (Variant) (
;
, .).
Local (Variant)
, False,
VBA

FileName (Variant)
;
FileFormat (Variant) ;
Password (Variant)
;
WriteResPassword (Variant)
;

. Excel
.8. Workbook ()


Unprotect

Password (Variant)

.
Password
,

. .9 Workbook.
.9. Workbook

BeforeClose

Cancel (Boolean)

Excel

.
Cancel True,
Excel ,

BeforePrint

Cancel (Boolean)

Excel


. Cancel
True, Excel ,

Open

Worksheet
Worksheet .
,
.
( worksheet) , Excel
.
. .10 worksheet.
. 10. Worksheet

Cells

Range

. Range,

Columns

Range

. Range,

Comments

Comments

. Comments,

Hyperlinks

Hyperlinks

. Hyperlinks,
Hyperlink
.

Worksheet

Index

Long

.
Sheets ,

Name

String

Names

Names

. Names,

Parent

Object

.

(Worksheet),

ProtectContents

Boolean

. True,

Range

Range

. Range,
,

Rows

Range

. Range,

Shapes

Shapes

. Shapes,
,

UsedRange

Range

. Range,
,
-

. . 11 Worksheet
. 11. Worksheet

Activate


(
)

ChartObjects Index
ChartObject,
ChartObjects
(Variant)

ChartObject (
),
Index.
,
ChartObjects,
ChartObject

Select


Activate

. Excel
. .12 Worksheet.
. 12. Worksheet

BeforeRightClick

Target (Range) ,

;
Cancel (Boolean)

Excel



.
Target Range
,
.
Cancel
True, Excel

Change

Target (Range)


. Target
Range

SelectionChange

Target (Range)


. Target
Range

97
222
211

219

246

200

291
290
298
291
291
303
293
300
296
103, 105
178
118
120
110, 112
180
116
165
212

3
96

203, 269
177

226
227
81
99
98
256

169
83, 136
32,131
100

276
252
277

279
102, 118, 121

136

262
267

188
189
82
189, 274
251
249

260
211
311
228
228
282
286
285
282
283
111
111
114
113
119, 182
182
184
81
85, 90, 91


101
153
86
81
95
100
100
217
274

277
109

245
245
260
268
11
154
267
92, 101, 111,124,148

175

174
170
109

101
HTML- 205
- 208
HTML- 207

271
225
242
203

194
197
256
131, 133
132
134
136
143
144

286


297
203
115

103, 106
119
104
169
107, 160
119
151
108
132
162
286
127

V
VBA
API- 74
24
62
63
63
23
28
71
36
23
29
32
49
20
20
20
20
27
67
29
61
68
41
51
26
19
38
77
18
20
54
43
63
19