Microsoft Office Tutorials and References
In Depth Information
Writing Your Own VBA Procedures
Table 2-1
VBA Data Types
Data Type
Acceptable Values
Storage Size
Declaration
Character
Boolean
True (–1) or False (0)
2 bytes
Byte
0 to 255
1 byte
Currency
–922,337,203,685,477.5808 to
922,337,203,685,477.5807
8 bytes
@
Date
January 1, 100, to
December 31, 9999
8 bytes
Double
–1.79769313486231E308
to –4.94065645841247E-
324 for negative values;
4.94065645841247E-324 to
1.79769313486232E308 for
positive values
8 bytes
#
Integer
–32,768 to 32,767
2 bytes
%
Long
–2,147,483,648 to
2,147,483,647
4 bytes
&
Object
Name of any object
4 bytes
Single
–3.402823E38 to –1.401298E-
45 for negative values;
1.401298E-45 to 3.402823E38
for positive values
4 bytes
!
String (fixed
length)
Any text from 1 to 65,400
characters in length
10 + string
length
$
You define the names and data types of arguments within the parentheses
that follow the name of the procedure. Separate the name from the data
type by using the word As. The following example Sub statement defines a
sub procedure named SampleSub(). That sub procedure accepts two
arguments: a single-precision number named Amount and a string named Payee.
Sub SampleSub(Amount As Single, Payee As String)
... code ...
End Sub
Unlike a sub procedure, a function procedure can return a value. You
define the data type of the returned value after the parentheses and the
word As. The returned data doesn’t need a name — just a data type. The
following example Function statement defines a function procedure
named IsOpen(). That function accepts one argument: a string. The name
 
Search JabSto ::




Custom Search