Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

MicroBeaut Visual Basic for Applications (VBA) Snippets

License

NotificationsYou must be signed in to change notification settings

MicroBeaut/MicroBeaut-VBA-Snippets

Repository files navigation

microbeaut logo

MicroBeaut Visual Basic for Applications (VBA) Snippets

Install MicroBeaut VBA Snippets from the Marketplace

Provides VBA Snippets for:

VBA Constants

Statements

Functions

Conversion functions

Math functions

The followingconstants can be used anywhere in your code in place of the actual values.

Calendar constants

Prefix

VbCalendar

TheVbCalendar argument has the following values.

ConstantValueDescription
vbCalGreg0Indicates that the Gregorian calendar is used.
vbCalHijri1Indicates that the Hijri calendar is used.

Color constants

Prefix

ColorConstants

TheColorConstants argument has the following values.

ConstantValueDescription
vbBlack0x0Black
vbRed0xFFRed
vbGreen0xFF00Green
vbYellow0xFFFFYellow
vbBlue0xFF0000Blue
vbMagenta0xFF00FFMagenta
vbCyan0xFFFF00Cyan
vbWhite0xFFFFFFWhite

Comparison constants

Prefix

VbCompareMethod

TheVbCompareMethod argument has the following values.

ConstantValueDescription
vbUseCompareOption-1Performs a comparison by using the setting of theOption Compare statement.
vbBinaryCompare0Performs a binary comparison.
vbTextCompare1Performs a textual comparison.
vbDatabaseCompare2For Microsoft Access (Windows only), performs a comparison based on information contained in your database.

Date constants

The followingconstants can be used anywhere in your code in place of the actual values.

Day of Week

Prefix

VbDayOfWeek

TheVbDayOfWeek argument has the following values.

ConstantValueDescription
VbUseSystemDayOfWeek0Use the day of the week specified in your system settings for the first day of the week.
vbSunday1Sunday (default)
vbMonday2Monday
vbTuesday3Tuesday
vbWednesday4Wednesday
vbThursday5Thursday
vbFriday6Friday
vbSaturday7Saturday

First Week Of Year

Prefix

VbFirstWeekOfYear

TheVbFirstWeekOfYear argument has the following values.

ConstantValueDescription
vbUseSystem0Use NLS API setting.
VbFirstJan11Start with week in which January 1 occurs (default).
vbFirstFourDays2Start with the first week that has at least four days in the new year.
vbFirstFullWeek3Start with the first full week of the year.

Dir, GetAttr, and SetAttr constants

Prefix

VbFileAttribute

TheVbFileAttribute argument has the following values.

ConstantValueDescription
vbNormal0Normal (default forDir andSetAttr)
vbReadOnly1Read-only
vbHidden2Hidden
vbSystem4System file
vbVolume8Volume label
vbDirectory16Directory or folder
vbArchive32File has changed since last backup
vbAlias64On the Macintosh, identifier is an alias

OnlyVbNormal,vbReadOnly,vbHidden, andvbAlias are available on the Macintosh.

AppActivate

Activates an application window.

Prefix

AppActivate

Syntax

AppActivatetitle, [wait ]

Beep

Sounds a tone through the computer's speaker.

Prefix

Beep

Syntax

Beep

Call

Transfers control to a Sub procedure, Function procedure, or dynamic-link library (DLL) procedure.

Prefix

Call

Syntax

[Call ]name [argumentlist ]

ChDir

Changes the current directory or folder.

Prefix

ChDir

Syntax

ChDirpath

ChDrive

Changes the current drive.

Prefix

ChDrive

Syntax

ChDrivedrive

Close

Concludes input/output (I/O) to a file opened by using the Open statement.

Prefix

Close

Syntax

Close [filenumberlist ]

Const

Declaresconstants for use in place of literal values.

Prefix

Const

Syntax

[Public |Private ]Constconstname [Astype ]=expression

Date

Sets the current system date#mmmm d, yyyy#.

Prefix

Date

Syntax

Date=date

DeleteSetting

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.

Prefix

DeleteSetting

Syntax

DeleteSettingappname,section,key

Dim

Declaresvariables and allocates storage space.

Prefix

DimDimWithEvents

Syntax

Dim [WithEvents ]varname [( [subscripts ]) ] [As [New ]type ]

Do...Loop

Repeats a block ofstatements while a condition isTrue or until a condition becomesTrue.

Prefix

DoUntilLoopDoWhileLoop

Syntax

Do [{While |Until}condition ]  [statements ]  [ExitDo ]  [statements ]Loop

Or,

Prefix

DoLoopUntilDoLoopWhile

Syntax

Do  [statements ]  [ExitDo ]  [statements ]Loop [{While |Until}condition ]

End

Ends a procedure or block.

Prefix

EndEndFunctionEndIfEndPropertyEndSelectEndSubEndTypeEndWith

Syntax

EndEndFunctionEndIfEndPropertyEndSelectEndSubEndTypeEndWith

Enum

Declares a type for an enumeration.

Prefix

Enum

Syntax

[Public |Private ]Enumnamemembername [=constantexpression ]membername [=constantexpression ]...EndEnum

Erase

Reinitializes the elements of fixed-sizearrays and releases dynamic-array storage space.

Prefix

Erase

Syntax

Erasearraylist

Error

Simulates the occurrence of an error.

Prefix

Error

Syntax

Errorerrornumber

Event

Declares a user-defined event.

Prefix

Event

Syntax

[Public ]Eventprocedurename [(arglist) ]

Exit

Exits a block of Do…Loop, For…Next, Function, Sub, or Property code.

Prefix

ExitDoExitFoExitFuExitPrExitSu

Syntax

ExitDoExitForExitFunctionExitPropertyExitSub

FileCopy

Copies a file.

Prefix

FileCopy

Syntax

FileCopysource,destination

For Each...Next

Repeats a group ofstatements for each element in anarrays or collection.

Prefix

ForEach

Syntax

ForEachelementIngroup  [statements ]  [ExitFor ]  [statements ]Next [element ]

For...Next

Repeats a group ofstatements a specified number of times.

Prefix

ForNext

Syntax

Forcounter=startToend [Stepstep ]  [statements ]  [ExitFor ]  [statements ]Next [counter ]

Function

Declares the name, arguments, and code that form the body of aFunctionprocedure.

Prefix

FunctionFunctionStatic

Syntax

[Public |Private |Friend] [Static ]Functionname [(arglist) ] [Astype ]  [statements ]  [name=expression ]  [ExitFunction ]  [statements ]  [name=expression ]EndFunction

Get

Reads data from an open disk file into a variable.

Prefix

Get

Syntax

Get [# ]filenumber, [recnumber ],varname

GoSub...Return

Branches to and returns from a subroutine within a procedure.

Prefix

GoSub

Syntax

GoSubline...lineline...Return

GoTo

Branches unconditionally to a specified line within a procedure.

Prefix

GoToline

Syntax

GoToline

If...Then...Else

Conditionally executes a group ofstatements, depending on the value of an expression.

Prefix

If

Syntax

IfconditionThen [statements ] [Elseelsestatements ]Or,IfconditionThen  [statements ][ElseIfcondition-nThen  [elseifstatements ]][Else  [elsestatements ]]EndIf

Load

Loads an object but doesn't show it.

Prefix

Load

Syntax

Loadobject

Input

Reads data from an open sequential file and assigns the data to variables.

Prefix

Input

Syntax

Input#filenumber,varlist

Kill

Deletes files from a disk.

Prefix

Kill

Syntax

Killpathname

Let

Assigns the value of an expression to a variable or property.

Prefix

Let

Syntax

[Let ]varname=expression

Line Input

Reads a single line from an open sequential file and assigns it to a String variable.

Prefix

LineInput

Syntax

LineInput#

Lock, Unlock

Controls access by other processes to all or part of a file opened by using the Open statement.

Prefix

LockUnlock

Syntax

Lock [# ]filenumber, [recordrange ]Unlock [# ]filenumber, [recordrange ]

LSet

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.

Prefix

LSet

Syntax

LSetstringvar=stringLSetvarname1=varname2

Mid

Replaces a specified number of characters in aVariant (String) variable with characters from another string.

Prefix

Mid

Syntax

Mid(stringvar,start, [length ])=string

MkDir

Creates a new directory or folder.

Prefix

MkDir

Syntax

MkDirpath

Name

Renames a disk file, directory, or folder.

Prefix

Name

Syntax

NameoldpathnameAsnewpathname

On Error

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.

Prefix

OnErrorGoOnErrorRe

Syntax

OnErrorGoTo0OnErrorGoTolineOnErrorResumeNext

On...GoSub, On...GoTo

Branch to one of several specified lines, depending on the value of an expression.

Prefix

OnGoSubOnGoTo

Syntax

OnexpressionGoSubdestinationlistOnexpressionGoTodestinationlist

Open

Enables input/output (I/O) to a file.

Prefix

Open

Syntax

OpenpathnameFormode [Accessaccess ] [lock ]As [# ]filenumber [Len=reclength ]

Option Base

Used at the module level to declare the default lower bound for array subscripts.

Prefix

OptionBa

Syntax

OptionBase{0 |1}

Option Compare

Used at the module level to declare the default comparison method to use when string data is compared.

Prefix

OptionCo

Syntax

OptionCompare{Binary |Text |Database}

Option Explicit

Used at the module level to force explicit declaration of all variables in that module.

Prefix

OptionEx

Syntax

Option Explicit

Option Private

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.

Prefix

OptionPr

Syntax

OptionPrivateModule

Print

Writes display-formatted data to a sequential file.

Prefix

Print#

Syntax

Print#filenumber, [outputlist ]

Private

Used at the module level to declare private variables and allocate storage space.

Prefix

PrivatePrivateWith

Syntax

Private [WithEvents ]varname [( [subscripts ]) ] [As [New ]type ]

Property Get

Declares the name, arguments, and code that form the body of aProperty procedure, which gets the value of a property.

Prefix

PropertyGetPropertyGetStatic

Syntax

[Public |Private |Friend ] [Static ]PropertyGetname [(arglist) ] [Astype ]  [statements ]  [name=expression ][ExitProperty ]  [statements ]  [name=expression ]EndProperty

Property Let

Declares the name, arguments, and code that form the body of aProperty procedure, which assigns a value to a property.

Prefix

PropertyLetPropertyLetStatic

Syntax

[Public |Private |Friend ] [Static ]PropertyLetname( [arglist ],value)  [statements ]  [ExitProperty ]  [statements ]EndProperty

Property Set

Declares the name, arguments, and code that form the body of aProperty procedure, which sets a reference to an object.

Prefix

PropertySetPropertySetStatic

Syntax

[Public |Private |Friend ] [Static ]PropertySetname( [arglist ],reference)  [statements ]  [ExitProperty ]  [statements ]EndProperty

Public

Used at the module level to declare public variables and allocate storage space.

Prefix

PublicPublicWith

Syntax

Public [WithEvents ]varname [( [subscripts ]) ] [As [New ]type ]

Put

Writes data from a variable to a disk file.

Prefix

Put

Syntax

Put [# ]filenumber, [recnumber ],varname

RaiseEvent

Fires an event declared at the module level within a class, form, or document.

Prefix

RaiseEvent

Syntax

RaiseEventeventname [(argumentlist) ]

Randomize

Initializes the random-number generator.

Prefix

Randomize

Syntax

Randomize [number ]

ReDim

Used at the procedure level to reallocate storage space for dynamic array variables.

Prefix

ReDim

Syntax

ReDim [Preserve ]varname(subscripts)

Rem

Used to include explanatory remarks in a program.

Prefix

Rem

Syntax

Remcomment

Reset

Closes all disk files opened by using the Open statement.

Prefix

Reset

Syntax

Reset

Resume

Removes an existing directory or folder.

Prefix

ResumeResumeNeResumeLi

Syntax

Resume [0 ]ResumeNextResumeline

RmDir

Removes an existing directory or folder.

Prefix

RmDir

Syntax

RmDirpath

RSet

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.

Prefix

RSet

Syntax

RSetstringvar=stringRSetvarname1=varname2

SaveSetting

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.

Prefix

SaveSetting

Syntax

SaveSettingappname,section,key,setting

Remarks

The root of these registry settings is:Computer\HKEY_CURRENT_USER\Software\VB and VBA Program Settings.

Seek

Sets the position for the next read/write operation within a file opened by using the Open statement.

Prefix

Seek

Syntax

Seek [# ]filenumber,position

Select Case

Executes one of several groups of statements, depending on the value of an expression.

Prefix

SelectCase

Syntax

SelectCasetestexpression[Caseexpressionlist-n  [statements-n ]][CaseElse   [elsestatements ]]EndSelect

SendKeys

Sends one or more keystrokes to the active window as if typed at the keyboard.

Prefix

SendKeys

Syntax

SendKeys [# ]filenumber,position

Set

Assigns an object reference to a variable or property.

Prefix

Set

Syntax

Setobjectvar={[New ]objectexpression |Nothing}

SetAttr

Sets attribute information for a file.

Prefix

SetAttr

Syntax

SetAttrpathname,attributes

Static

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.

Prefix

Static

Syntax

Staticvarname [( [subscripts ]) ] [As [New ]type ]

Stop

Suspends execution.

Prefix

Stop

Syntax

Stop

Sub

Declares the name, arguments, and code that form the body of aSub procedure.

Prefix

SubSubStatic

Syntax

[Private |Public |Friend ] [Static ]Subname [(arglist) ]  [statements ]  [ExitSub ]  [statements ]EndSub

Time

Sets the system time.#hh:mm:ss AM/PM#

Prefix

Time

Syntax

Time=time

Type

Used at the module level to define a user-defined data type containing one or more elements.

Prefix

Type

Syntax

[Private |Public ]Typevarnameelementname [( [subscripts ]) ]Astype  [elementname [( [subscripts ]) ]Astype ]...EndType

Unload

Removes an object from memory.

Prefix

Unload

Syntax

Unloadobject

While...Wend

Removes an object from memory.

Prefix

WhileWend

Syntax

Whilecondition  [statements ]Wend

Width

Assigns an output line width to a file opened by using the Open statement.

Prefix

Width

Syntax

Width#filenumber,width

With

Executes a series of statements on a single object or a user-defined type.

Prefix

With

Syntax

Withobject  [statements ]EndWith

Write

Writes data to a sequential file.

Prefix

Write

Syntax

Write#filenumber, [outputlist ]

Asc

Returns an Integer representing the character code corresponding to the first letter in a string.

Prefix

Asc

Syntax

Asc(string)

Chr

Returns a String containing the character associated with the specified character code.

Prefix

Chr

Syntax

Chr(charcode)

Format

Returns a Variant (String) containing an expression formatted according to instructions contained in a format expression.

Prefix

Format

Syntax

Format(Expression, [Format ], [FirstDayOfWeek ], [FirstWeekOfYear ])

Hex

Returns a Variant (String) containing an expression formatted according to instructions contained in a format expression.

Prefix

Hex

Syntax

Hex(number)

Oct

Returns a Variant (String) representing the octal value of a number.

Prefix

Oct

Syntax

Oct(number)

Str

Returns a Variant (String) representation of a number.

Prefix

Str

Syntax

Str(number)

Val

Returns the numbers contained in a string as a numeric value of appropriate type.

Prefix

Val

Syntax

Val(string)

Abs

Returns a value of the same type that is passed to it specifying the absolute value of a number.

Prefix

Abs

Syntax

Abs(number)

Atn

Returns a Double specifying the arctangent of a number.

Prefix

Atn

Syntax

Atn(number)

Cos

Returns a Double specifying the cosine of an angle.

Prefix

Cos

Syntax

Cos(number)

Exp

Returns a Double specifying e (the base of natural logarithms) raised to a power.

Prefix

Exp

Syntax

Exp(number)

Int, Fix

Returns a Double specifying e (the base of natural logarithms) raised to a power.

Prefix

IntFix

Syntax

Int(number)Fix(number)

Log

Returns a Double specifying the natural logarithm of a number.

Prefix

Log

Syntax

Log(number)

Rnd

Returns a Single containing a pseudo-random number.

Prefix

Rnd

Syntax

Rnd [(Number) ]

Sgn

Returns a Variant (Integer) indicating the sign of a number.

Prefix

Sgn

Syntax

Sgn(number)

Sin

Returns a Double specifying the cosine of an angle.

Prefix

Sin

Syntax

Sin(number)

Sqr

Returns a Double specifying the sine of an angle.

Prefix

Sqr

Syntax

Sqr(number)

Tan

Returns a Double specifying the tangent of an angle.

Prefix

Tan

Syntax

Tan(number)

Reference


Release Notes

[0.0.1]

  • Initial release of MicroBeaut VBA Snippets

[0.0.2]

  • Changed package description
  • Revised statements
  • Added new statements

[0.0.3]

  • Changed the prefix for,
    • Dim WithEvent
    • On Error *
    • Private WithEvent
    • Public WithEvent

[0.0.4]

  • Removed statementsIf...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

[0.0.5]

  • Fixed package not updated

[0.0.6]

  • Added VBA Constants

License

MIT License

Copyright © 2023 MicroBeaut

About

MicroBeaut Visual Basic for Applications (VBA) Snippets

Resources

License

Stars

Watchers

Forks

Packages

No packages published

[8]ページ先頭

©2009-2025 Movatter.jp