- Calendar constants
- Color constants
- Comparison constants
- Date constants
- Dir, GetAttr, and SetAttr constants
- AppActivate
- Beep
- Call
- ChDir
- ChDrive
- Close
- Const
- Date
- DeleteSetting
- Dim
- Do...Loop
- End
- Enum
- Erase
- Error
- Event
- Exit
- FileCopy
- For Each...Next
- For...Next
- Function
- Get
- GoSub...Return
- GoTo
- If...Then...Else
- Input #
- Kill
- Let
- Line Input #
- Load
- Lock, Unlock
- LSet
- Mid
- MkDir
- Name
- On Error
- On...GoSub, On...GoTo
- Open
- Option Base
- Option Compare
- Option Explicit
- Option Private
- Print #
- Private
- Property Get
- Property Let
- Property Set
- Public
- Put
- RaiseEvent
- Randomize
- ReDim
- Rem
- Reset
- Resume
- RmDir
- RSet
- SaveSetting
- Seek
- Select Case
- SendKeys
- Set
- SetAttr
- Static
- Stop
- Sub
- Time
- Type
- Unload
- While...Wend
- Width #
- With
- Write #
The following constants
can be used anywhere in your code in place of the actual values.
VbCalendar
The VbCalendar
argument has the following values.
Constant | Value | Description |
---|---|---|
vbCalGreg | 0 | Indicates that the Gregorian calendar is used. |
vbCalHijri | 1 | Indicates that the Hijri calendar is used. |
ColorConstants
The ColorConstants
argument has the following values.
Constant | Value | Description |
---|---|---|
vbBlack | 0x0 | Black |
vbRed | 0xFF | Red |
vbGreen | 0xFF00 | Green |
vbYellow | 0xFFFF | Yellow |
vbBlue | 0xFF0000 | Blue |
vbMagenta | 0xFF00FF | Magenta |
vbCyan | 0xFFFF00 | Cyan |
vbWhite | 0xFFFFFF | White |
VbCompareMethod
The VbCompareMethod
argument has the following values.
Constant | Value | Description |
---|---|---|
vbUseCompareOption | -1 | Performs a comparison by using the setting of the Option Compare statement. |
vbBinaryCompare | 0 | Performs a binary comparison. |
vbTextCompare | 1 | Performs a textual comparison. |
vbDatabaseCompare | 2 | For Microsoft Access (Windows only), performs a comparison based on information contained in your database. |
The following constants
can be used anywhere in your code in place of the actual values.
VbDayOfWeek
The VbDayOfWeek
argument has the following values.
Constant | Value | Description |
---|---|---|
VbUseSystemDayOfWeek | 0 | Use the day of the week specified in your system settings for the first day of the week. |
vbSunday | 1 | Sunday (default) |
vbMonday | 2 | Monday |
vbTuesday | 3 | Tuesday |
vbWednesday | 4 | Wednesday |
vbThursday | 5 | Thursday |
vbFriday | 6 | Friday |
vbSaturday | 7 | Saturday |
VbFirstWeekOfYear
The VbFirstWeekOfYear
argument has the following values.
Constant | Value | Description |
---|---|---|
vbUseSystem | 0 | Use NLS API setting. |
VbFirstJan1 | 1 | Start with week in which January 1 occurs (default). |
vbFirstFourDays | 2 | Start with the first week that has at least four days in the new year. |
vbFirstFullWeek | 3 | Start with the first full week of the year. |
VbFileAttribute
The VbFileAttribute
argument has the following values.
Constant | Value | Description |
---|---|---|
vbNormal | 0 | Normal (default for Dir and SetAttr) |
vbReadOnly | 1 | Read-only |
vbHidden | 2 | Hidden |
vbSystem | 4 | System file |
vbVolume | 8 | Volume label |
vbDirectory | 16 | Directory or folder |
vbArchive | 32 | File has changed since last backup |
vbAlias | 64 | On the Macintosh, identifier is an alias |
Only VbNormal, vbReadOnly, vbHidden, and vbAlias are available on the Macintosh.
Activates an application window.
AppActivate
AppActivate title, [ wait ]
Sounds a tone through the computer's speaker.
Beep
Beep
Transfers control to a Sub procedure, Function procedure, or dynamic-link library (DLL) procedure.
Call
[ Call ] name [ argumentlist ]
Changes the current directory or folder.
ChDir
ChDir path
Changes the current drive.
ChDrive
ChDrive drive
Concludes input/output (I/O) to a file opened by using the Open statement.
Close
Close [ filenumberlist ]
Declares constants
for use in place of literal values.
Const
[ Public | Private ] Const constname [ As type ] = expression
Sets the current system date #mmmm d, yyyy#
.
Date
Date = date
Deletes a section or key setting from an application's entry in the Windows registry
or (on the Macintosh) information in the application's initialization file.
DeleteSetting
DeleteSetting appname, section, key
Declares variables
and allocates storage space.
Dim
Dim WithEvents
Dim [ WithEvents ] varname [ ( [ subscripts ] ) ] [ As [ New ] type ]
Repeats a block of statements
while a condition is True or until a condition becomes True.
Do Until Loop
Do While Loop
Do [{ While | Until } condition ]
[ statements ]
[ Exit Do ]
[ statements ]
Loop
Or,
Do Loop Until
Do Loop While
Do
[ statements ]
[ Exit Do ]
[ statements ]
Loop [{ While | Until } condition ]
Ends a procedure or block.
End
End Function
End If
End Property
End Select
End Sub
End Type
End With
End
End Function
End If
End Property
End Select
End Sub
End Type
End With
Declares a type for an enumeration.
Enum
[ Public | Private ] Enum name
membername [= constantexpression ]
membername [= constantexpression ] . . .
End Enum
Reinitializes the elements of fixed-size arrays
and releases dynamic-array storage space.
Erase
Erase arraylist
Simulates the occurrence of an error.
Error
Error errornumber
Declares a user-defined event.
Event
[ Public ] Event procedurename [ (arglist) ]
Exits a block of Do…Loop, For…Next, Function, Sub, or Property code.
Exit Do
Exit Fo
Exit Fu
Exit Pr
Exit Su
Exit Do
Exit For
Exit Function
Exit Property
Exit Sub
Copies a file.
FileCopy
FileCopy source, destination
Repeats a group of statements
for each element in an arrays
or collection.
For Each
For Each element In group
[ statements ]
[ Exit For ]
[ statements ]
Next [ element ]
Repeats a group of statements
a specified number of times.
For Next
For counter = start To end [ Step step ]
[ statements ]
[ Exit For ]
[ statements ]
Next [ counter ]
Declares the name, arguments, and code that form the body of a Function procedure
.
Function
Function Static
[Public | Private | Friend] [ Static ] Function name [ ( arglist ) ] [ As type ]
[ statements ]
[ name = expression ]
[ Exit Function ]
[ statements ]
[ name = expression ]
End Function
Reads data from an open disk file into a variable.
Get
Get [ # ] filenumber, [ recnumber ], varname
Branches to and returns from a subroutine within a procedure.
GoSub
GoSub line
... line
line ...
Return
Branches unconditionally to a specified line within a procedure.
GoTo line
GoTo line
Conditionally executes a group of statements
, depending on the value of an expression.
If
If condition Then [ statements ] [ Else elsestatements ]
Or,
If condition Then
[ statements ]
[ ElseIf condition-n Then
[ elseifstatements ]]
[ Else
[ elsestatements ]]
End If
Loads an object but doesn't show it.
Load
Load object
Reads data from an open sequential file and assigns the data to variables.
Input
Input #filenumber, varlist
Deletes files from a disk.
Kill
Kill pathname
Assigns the value of an expression to a variable or property.
Let
[ Let ] varname = expression
Reads a single line from an open sequential file and assigns it to a String variable.
Line Input
Line Input #
Controls access by other processes to all or part of a file opened by using the Open statement.
Lock
Unlock
Lock [ # ] filenumber, [ recordrange ]
Unlock [ # ] filenumber, [ recordrange ]
Left aligns a string within a string variable, or copies a variable of one user-defined type
to another variable of a different user-defined type.
LSet
LSet stringvar = string
LSet varname1 = varname2
Replaces a specified number of characters in a Variant (String) variable with characters from another string.
Mid
Mid(stringvar, start, [ length ] ) = string
Creates a new directory or folder.
MkDir
MkDir path
Renames a disk file, directory, or folder.
Name
Name oldpathname As newpathname
Enables an error-handling routine and specifies the location of the routine within a procedure; can also be used to disable an error-handling routine.
On Error Go
On Error Re
On Error GoTo 0
On Error GoTo line
On Error Resume Next
Branch to one of several specified lines, depending on the value of an expression.
On GoSub
On GoTo
On expression GoSub destinationlist
On expression GoTo destinationlist
Enables input/output (I/O) to a file.
Open
Open pathname For mode [ Access access ] [ lock ] As [ # ] filenumber [ Len = reclength ]
Used at the module level to declare the default lower bound for array subscripts.
Option Ba
Option Base { 0 | 1 }
Used at the module level to declare the default comparison method to use when string data is compared.
Option Co
Option Compare { Binary | Text | Database }
Used at the module level to force explicit declaration of all variables in that module.
Option Ex
Option Explicit
When used in host applications that allow references across multiple projects, Option Private Module prevents a module's contents from being referenced outside its project. In host applications that don't permit such references, for example, standalone versions of Visual Basic, Option Private has no effect.
Option Pr
Option Private Module
Writes display-formatted data to a sequential file.
Print #
Print #filenumber, [ outputlist ]
Used at the module level to declare private variables and allocate storage space.
Private
Private With
Private [ WithEvents ] varname [ ( [ subscripts ] ) ] [ As [ New ] type ]
Declares the name, arguments, and code that form the body of a Property procedure, which gets the value of a property.
Property Get
Property Get Static
[ Public | Private | Friend ] [ Static ] Property Get name [ (arglist) ] [ As type ]
[ statements ]
[ name = expression ]
[ Exit Property ]
[ statements ]
[ name = expression ]
End Property
Declares the name, arguments, and code that form the body of a Property procedure, which assigns a value to a property.
Property Let
Property Let Static
[ Public | Private | Friend ] [ Static ] Property Let name ( [ arglist ], value )
[ statements ]
[ Exit Property ]
[ statements ]
End Property
Declares the name, arguments, and code that form the body of a Property procedure, which sets a reference to an object.
Property Set
Property Set Static
[ Public | Private | Friend ] [ Static ] Property Set name ( [ arglist ], reference )
[ statements ]
[ Exit Property ]
[ statements ]
End Property
Used at the module level to declare public variables and allocate storage space.
Public
Public With
Public [ WithEvents ] varname [ ( [ subscripts ] ) ] [ As [ New ] type ]
Writes data from a variable to a disk file.
Put
Put [ # ] filenumber, [ recnumber ], varname
Fires an event declared at the module level within a class, form, or document.
RaiseEvent
RaiseEvent eventname [ ( argumentlist ) ]
Initializes the random-number generator.
Randomize
Randomize [ number ]
Used at the procedure level to reallocate storage space for dynamic array variables.
ReDim
ReDim [ Preserve ] varname ( subscripts )
Used to include explanatory remarks in a program.
Rem
Rem comment
Closes all disk files opened by using the Open statement.
Reset
Reset
Removes an existing directory or folder.
Resume
Resume Ne
Resume Li
Resume [ 0 ]
Resume Next
Resume line
Removes an existing directory or folder.
RmDir
RmDir path
Right aligns a string within a string variable, or copies a variable of one user-defined type to another variable of a different user-defined type.
RSet
RSet stringvar = string
RSet varname1 = varname2
Saves or creates an application entry in the application's entry in the Windows registry or (on the Macintosh) information in the application's initialization file.
SaveSetting
SaveSetting appname, section, key, setting
The root of these registry settings is: Computer\HKEY_CURRENT_USER\Software\VB and VBA Program Settings
.
Sets the position for the next read/write operation within a file opened by using the Open statement.
Seek
Seek [ # ] filenumber, position
Executes one of several groups of statements, depending on the value of an expression.
Select Case
Select Case testexpression
[ Case expressionlist-n
[ statements-n ]]
[ Case Else
[ elsestatements ]]
End Select
Sends one or more keystrokes to the active window as if typed at the keyboard.
SendKeys
SendKeys [ # ] filenumber, position
Assigns an object reference to a variable or property.
Set
Set objectvar = {[ New ] objectexpression | Nothing }
Sets attribute information for a file.
SetAttr
SetAttr pathname, attributes
Used at the procedure level to declare variables and allocate storage space. Variables declared with the Static statement retain their values as long as the code is running.
Static
Static varname [ ( [ subscripts ] ) ] [ As [ New ] type ]
Suspends execution.
Stop
Stop
Declares the name, arguments, and code that form the body of a Sub procedure.
Sub
Sub Static
[ Private | Public | Friend ] [ Static ] Sub name [ ( arglist ) ]
[ statements ]
[ Exit Sub ]
[ statements ]
End Sub
Sets the system time. #hh:mm:ss AM/PM#
Time
Time = time
Used at the module level to define a user-defined data type containing one or more elements.
Type
[ Private | Public ] Type varname
elementname [ ( [ subscripts ] ) ] As type
[ elementname [ ( [ subscripts ] ) ] As type ] . . .
End Type
Removes an object from memory.
Unload
Unload object
Removes an object from memory.
While Wend
While condition
[ statements ]
Wend
Assigns an output line width to a file opened by using the Open statement.
Width
Width #filenumber, width
Executes a series of statements on a single object or a user-defined type.
With
With object
[ statements ]
End With
Writes data to a sequential file.
Write
Write #filenumber, [ outputlist ]
Returns an Integer representing the character code corresponding to the first letter in a string.
Asc
Asc(string)
Returns a String containing the character associated with the specified character code.
Chr
Chr(charcode)
Returns a Variant (String) containing an expression formatted according to instructions contained in a format expression.
Format
Format(Expression, [ Format ], [ FirstDayOfWeek ], [ FirstWeekOfYear ])
Returns a Variant (String) containing an expression formatted according to instructions contained in a format expression.
Hex
Hex(number)
Returns a Variant (String) representing the octal value of a number.
Oct
Oct(number)
Returns a Variant (String) representation of a number.
Str
Str(number)
Returns the numbers contained in a string as a numeric value of appropriate type.
Val
Val(string)
Returns a value of the same type that is passed to it specifying the absolute value of a number.
Abs
Abs(number)
Returns a Double specifying the arctangent of a number.
Atn
Atn(number)
Returns a Double specifying the cosine of an angle.
Cos
Cos(number)
Returns a Double specifying e (the base of natural logarithms) raised to a power.
Exp
Exp(number)
Returns a Double specifying e (the base of natural logarithms) raised to a power.
Int
Fix
Int(number)
Fix(number)
Returns a Double specifying the natural logarithm of a number.
Log
Log(number)
Returns a Single containing a pseudo-random number.
Rnd
Rnd [ (Number) ]
Returns a Variant (Integer) indicating the sign of a number.
Sgn
Sgn(number)
Returns a Double specifying the cosine of an angle.
Sin
Sin(number)
Returns a Double specifying the sine of an angle.
Sqr
Sqr(number)
Returns a Double specifying the tangent of an angle.
Tan
Tan (number)
- Initial release of MicroBeaut VBA Snippets
- Changed package description
- Revised statements
- Added new statements
- Changed the prefix for,
Dim WithEvent
On Error *
Private WithEvent
Public WithEvent
- Removed statements
If...Then..Exit
inside,Do...Loop
For Each...Next
For...Next
Function
If...Then...Else
- Updated descriptions
- Added new statements
- Added Conversion functions
- Added Math functions
- Fixed package not updated
- Added VBA Constants
MIT License
Copyright © 2023 MicroBeaut