- Notifications
You must be signed in to change notification settings - Fork0
MicroBeaut Visual Basic for Applications (VBA) Snippets
License
MicroBeaut/MicroBeaut-VBA-Snippets
Folders and files
| Name | Name | Last commit message | Last commit date | |
|---|---|---|---|---|
Repository files navigation
- 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 followingconstants can be used anywhere in your code in place of the actual values.
VbCalendarTheVbCalendar 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. |
ColorConstantsTheColorConstants 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 |
VbCompareMethodTheVbCompareMethod argument has the following values.
| Constant | Value | Description |
|---|---|---|
| vbUseCompareOption | -1 | Performs a comparison by using the setting of theOption 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 followingconstants can be used anywhere in your code in place of the actual values.
VbDayOfWeekTheVbDayOfWeek 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 |
VbFirstWeekOfYearTheVbFirstWeekOfYear 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. |
VbFileAttributeTheVbFileAttribute argument has the following values.
| Constant | Value | Description |
|---|---|---|
| vbNormal | 0 | Normal (default forDir andSetAttr) |
| 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 |
OnlyVbNormal,vbReadOnly,vbHidden, andvbAlias are available on the Macintosh.
Activates an application window.
AppActivateAppActivatetitle, [wait ]
Sounds a tone through the computer's speaker.
BeepBeepTransfers control to a Sub procedure, Function procedure, or dynamic-link library (DLL) procedure.
Call[Call ]name [argumentlist ]
Changes the current directory or folder.
ChDirChDirpath
Changes the current drive.
ChDriveChDrivedrive
Concludes input/output (I/O) to a file opened by using the Open statement.
CloseClose [filenumberlist ]
Declaresconstants for use in place of literal values.
Const[Public |Private ]Constconstname [Astype ]=expression
Sets the current system date#mmmm d, yyyy#.
DateDate=date
Deletes a section or key setting from an application's entry in the Windowsregistry or (on the Macintosh) information in the application's initialization file.
DeleteSettingDeleteSettingappname,section,key
Declaresvariables and allocates storage space.
DimDimWithEvents
Dim [WithEvents ]varname [( [subscripts ]) ] [As [New ]type ]
Repeats a block ofstatements while a condition isTrue or until a condition becomesTrue.
DoUntilLoopDoWhileLoop
Do [{While |Until}condition ] [statements ] [ExitDo ] [statements ]Loop
Or,
DoLoopUntilDoLoopWhile
Do [statements ] [ExitDo ] [statements ]Loop [{While |Until}condition ]
Ends a procedure or block.
EndEndFunctionEndIfEndPropertyEndSelectEndSubEndTypeEndWith
EndEndFunctionEndIfEndPropertyEndSelectEndSubEndTypeEndWith
Declares a type for an enumeration.
Enum[Public |Private ]Enumnamemembername [=constantexpression ]membername [=constantexpression ]...EndEnum
Reinitializes the elements of fixed-sizearrays and releases dynamic-array storage space.
EraseErasearraylist
Simulates the occurrence of an error.
ErrorErrorerrornumber
Declares a user-defined event.
Event[Public ]Eventprocedurename [(arglist) ]
Exits a block of Do…Loop, For…Next, Function, Sub, or Property code.
ExitDoExitFoExitFuExitPrExitSu
ExitDoExitForExitFunctionExitPropertyExitSub
Copies a file.
FileCopyFileCopysource,destination
Repeats a group ofstatements for each element in anarrays or collection.
ForEach
ForEachelementIngroup [statements ] [ExitFor ] [statements ]Next [element ]
Repeats a group ofstatements a specified number of times.
ForNext
Forcounter=startToend [Stepstep ] [statements ] [ExitFor ] [statements ]Next [counter ]
Declares the name, arguments, and code that form the body of aFunctionprocedure.
FunctionFunctionStatic
[Public |Private |Friend] [Static ]Functionname [(arglist) ] [Astype ] [statements ] [name=expression ] [ExitFunction ] [statements ] [name=expression ]EndFunction
Reads data from an open disk file into a variable.
GetGet [# ]filenumber, [recnumber ],varname
Branches to and returns from a subroutine within a procedure.
GoSubGoSubline...lineline...Return
Branches unconditionally to a specified line within a procedure.
GoToline
GoToline
Conditionally executes a group ofstatements, depending on the value of an expression.
IfIfconditionThen [statements ] [Elseelsestatements ]Or,IfconditionThen [statements ][ElseIfcondition-nThen [elseifstatements ]][Else [elsestatements ]]EndIf
Loads an object but doesn't show it.
LoadLoadobject
Reads data from an open sequential file and assigns the data to variables.
InputInput#filenumber,varlist
Deletes files from a disk.
KillKillpathname
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.
LineInput
LineInput#
Controls access by other processes to all or part of a file opened by using the Open statement.
LockUnlock
Lock [# ]filenumber, [recordrange ]Unlock [# ]filenumber, [recordrange ]
Left aligns a string within a string variable, or copies a variable of oneuser-defined type to another variable of a different user-defined type.
LSetLSetstringvar=stringLSetvarname1=varname2
Replaces a specified number of characters in aVariant (String) variable with characters from another string.
MidMid(stringvar,start, [length ])=string
Creates a new directory or folder.
MkDirMkDirpath
Renames a disk file, directory, or folder.
NameNameoldpathnameAsnewpathname
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.
OnErrorGoOnErrorRe
OnErrorGoTo0OnErrorGoTolineOnErrorResumeNext
Branch to one of several specified lines, depending on the value of an expression.
OnGoSubOnGoTo
OnexpressionGoSubdestinationlistOnexpressionGoTodestinationlist
Enables input/output (I/O) to a file.
OpenOpenpathnameFormode [Accessaccess ] [lock ]As [# ]filenumber [Len=reclength ]
Used at the module level to declare the default lower bound for array subscripts.
OptionBa
OptionBase{0 |1}
Used at the module level to declare the default comparison method to use when string data is compared.
OptionCo
OptionCompare{Binary |Text |Database}
Used at the module level to force explicit declaration of all variables in that module.
OptionEx
Option ExplicitWhen 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.
OptionPr
OptionPrivateModule
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.
PrivatePrivateWith
Private [WithEvents ]varname [( [subscripts ]) ] [As [New ]type ]
Declares the name, arguments, and code that form the body of aProperty procedure, which gets the value of a property.
PropertyGetPropertyGetStatic
[Public |Private |Friend ] [Static ]PropertyGetname [(arglist) ] [Astype ] [statements ] [name=expression ][ExitProperty ] [statements ] [name=expression ]EndProperty
Declares the name, arguments, and code that form the body of aProperty procedure, which assigns a value to a property.
PropertyLetPropertyLetStatic
[Public |Private |Friend ] [Static ]PropertyLetname( [arglist ],value) [statements ] [ExitProperty ] [statements ]EndProperty
Declares the name, arguments, and code that form the body of aProperty procedure, which sets a reference to an object.
PropertySetPropertySetStatic
[Public |Private |Friend ] [Static ]PropertySetname( [arglist ],reference) [statements ] [ExitProperty ] [statements ]EndProperty
Used at the module level to declare public variables and allocate storage space.
PublicPublicWith
Public [WithEvents ]varname [( [subscripts ]) ] [As [New ]type ]
Writes data from a variable to a disk file.
PutPut [# ]filenumber, [recnumber ],varname
Fires an event declared at the module level within a class, form, or document.
RaiseEventRaiseEventeventname [(argumentlist) ]
Initializes the random-number generator.
RandomizeRandomize [number ]
Used at the procedure level to reallocate storage space for dynamic array variables.
ReDimReDim [Preserve ]varname(subscripts)
Used to include explanatory remarks in a program.
RemRemcomment
Closes all disk files opened by using the Open statement.
ResetResetRemoves an existing directory or folder.
ResumeResumeNeResumeLi
Resume [0 ]ResumeNextResumeline
Removes an existing directory or folder.
RmDirRmDirpath
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.
RSetRSetstringvar=stringRSetvarname1=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.
SaveSettingSaveSettingappname,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.
SeekSeek [# ]filenumber,position
Executes one of several groups of statements, depending on the value of an expression.
SelectCase
SelectCasetestexpression[Caseexpressionlist-n [statements-n ]][CaseElse [elsestatements ]]EndSelect
Sends one or more keystrokes to the active window as if typed at the keyboard.
SendKeysSendKeys [# ]filenumber,position
Assigns an object reference to a variable or property.
SetSetobjectvar={[New ]objectexpression |Nothing}
Sets attribute information for a file.
SetAttrSetAttrpathname,attributes
Used at the procedure level to declare variables and allocate storage space. Variables declared with theStatic statement retain their values as long as the code is running.
StaticStaticvarname [( [subscripts ]) ] [As [New ]type ]
Suspends execution.
StopStopDeclares the name, arguments, and code that form the body of aSub procedure.
SubSubStatic
[Private |Public |Friend ] [Static ]Subname [(arglist) ] [statements ] [ExitSub ] [statements ]EndSub
Sets the system time.#hh:mm:ss AM/PM#
TimeTime=time
Used at the module level to define a user-defined data type containing one or more elements.
Type[Private |Public ]Typevarnameelementname [( [subscripts ]) ]Astype [elementname [( [subscripts ]) ]Astype ]...EndType
Removes an object from memory.
UnloadUnloadobject
Removes an object from memory.
WhileWend
Whilecondition [statements ]Wend
Assigns an output line width to a file opened by using the Open statement.
WidthWidth#filenumber,width
Executes a series of statements on a single object or a user-defined type.
WithWithobject [statements ]EndWith
Writes data to a sequential file.
WriteWrite#filenumber, [outputlist ]
Returns an Integer representing the character code corresponding to the first letter in a string.
AscAsc(string)
Returns a String containing the character associated with the specified character code.
ChrChr(charcode)Returns a Variant (String) containing an expression formatted according to instructions contained in a format expression.
FormatFormat(Expression, [Format ], [FirstDayOfWeek ], [FirstWeekOfYear ])
Returns a Variant (String) containing an expression formatted according to instructions contained in a format expression.
HexHex(number)Returns a Variant (String) representing the octal value of a number.
OctOct(number)Returns a Variant (String) representation of a number.
StrStr(number)Returns the numbers contained in a string as a numeric value of appropriate type.
ValVal(string)
Returns a value of the same type that is passed to it specifying the absolute value of a number.
AbsAbs(number)Returns a Double specifying the arctangent of a number.
AtnAtn(number)Returns a Double specifying the cosine of an angle.
CosCos(number)Returns a Double specifying e (the base of natural logarithms) raised to a power.
ExpExp(number)Returns a Double specifying e (the base of natural logarithms) raised to a power.
IntFix
Int(number)Fix(number)
Returns a Double specifying the natural logarithm of a number.
LogLog(number)Returns a Single containing a pseudo-random number.
RndRnd [(Number) ]
Returns a Variant (Integer) indicating the sign of a number.
SgnSgn(number)Returns a Double specifying the cosine of an angle.
SinSin(number)Returns a Double specifying the sine of an angle.
SqrSqr(number)Returns a Double specifying the tangent of an angle.
TanTan(number)
- Initial release of MicroBeaut VBA Snippets
- Changed package description
- Revised statements
- Added new statements
- Changed the prefix for,
Dim WithEventOn Error *Private WithEventPublic WithEvent
- Removed statements
If...Then..Exitinside,Do...LoopFor Each...NextFor...NextFunctionIf...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
About
MicroBeaut Visual Basic for Applications (VBA) Snippets
Resources
License
Uh oh!
There was an error while loading.Please reload this page.
Stars
Watchers
Forks
Packages0
Uh oh!
There was an error while loading.Please reload this page.

