, :
1. ( , , ).
2. .
, .
3. .
, - .
4. . - .
. , ( ).
. .
(runtime error) , .. , .
5. . , .
( ) , , , .
, .
VBA : . VBA, , , .
! , , .
: Sub Function.
Sub : ( ), (, , : - ..) Property ( , - ).
|
|
1. , :
; VBA;
; > (Insrert > Module) 2- ).
2. .
Sub _([])
End Sub
, Sub End Sub , , .
_ . , . .
[] . . .
( [ ] , , ).
,
Sub _()
Msgbox
End Sub
.
VBA
1. () 255 ;
2. ;
3. :
! @ $ #? / () {} [] = ^ / * - + ~ <> ^?;
4. VBA (Sub, If, Do ..);
5. .
, - , . - .
:
Function _ ([]) [As ]
_=
End Function
, Function End Function , ;
_ , ;
, ;
As ;
_= , .
:
Function (x As Integer, y As Integer) As Long
= x + y
End Function
. Long. . , , ,
Sub _z()
Dim a As Integer, b As Integer
Dim c As Integer, d As Integer, z As Double
a = Range("A1").Value
b = Range("A2").Value
c = Range("A3").Value
d = Range("A4").Value
z = (a, b) * (a, c) / (b, d)
Msgbox " " & z
End Sub
z . 1, 2, 3 4. z .
|
|
VBA (). , VBA . VBA ( , ).
! .
VBA :
; ;
; ;
; ;
; .
, VBA (, , ..)
! .
, .
VBA :
a) , .. , , ,
2 3.14 562
,
#12/31/2002#
True False
b) . , .
:
Const _ [ As ] =
,
Const Pi As double =3.14159
Const =500
Const Str =Hello
! .
c) VBA ( ). , , Msgbox, InputBox.
, , Ok, Yes, Cancel,No . . .
VBA vb, .. Excel Word. , vbOkOnly 0 Ok.
VbYesNoCancel 3 Yes, No, Cancel.
. : ,
_ =
, , , , , .
! , , , .
X=4 X 4
A=4+Sin(X)
C=S>4 S>4
Z=Cells(1,2).Value Z , 1- 2-
Cells(1,2).Value= Z , 1- 2- Z
= . = , . VBA , .
, VBA.
, . , , ( ).
:
Option Base . VBA 0.
Option Base 1 1.
|
|
Option Explicit , VBA . VBA: > > (Require Variable Declaration).
, .. . , , , 5mod2 5 mod 2 aORb a OR b, VBA 5mod2 aORb .
:
;
;
;
VBA.
, VBA- .
, 2- , . ,
Msgbox & St & _
, . ,
Dim A As Byte, B As Byte, C As Integer
A=20: B=12: C=48
VBA- . ,
Dim A As Byte, B As Byte
VBA
(-,+ ..) (Or, And ..), () .
VBA- 4 : , , .
+ | , | +4 |
* / | , | A*b/c |
^ | B^4 | |
\ | . | 5\2 >2 |
mod | 5 mod 2 > 1 | |
Not | . | A = True B = Not A B > False |
And | Ȼ. , , . | A=True: B = False C = A And B C > False |
Or | . , . | A =3: B =5 C = (A>6) Or (B<10) C >True |
XOR | . , , . , . | A=True: B =True: C= False D =A XOR B D>False D = B XOR C D> True |
= | ||
<> | ||
< | ||
> | ||
<= | ||
>= | ||
Like | . : *,? . | A=Hello! C= A Like ! C >False C= A Like He* C > True |
Is | ||
& | . | MsgBox : & |
, :
() | ||
s(x) | ||
^ | ||
- sin(x) | ( ) | |
*, / | , | |
\ | ||
mod | ||
+, | , | |
& | ||
>, <= | ||
And, Or, Not |
.
|
|