SoFunction
Updated on 2025-04-12

Constants to be used in VBA


Drive type constant

Only if your project's corresponding pairs containing these constant definitionsType libraryThese constants can only be used when there is an explicit reference.

constant value describe
Unknown 0 The drive type cannot be determined.
Removable 1 The drive has deletion media. Includes all floppy drives and many other types of storage devices.
Fixed 2 The drive has fixed media (not deleteable). All hard drives including deletion hard drives.
Remote 3 Network drive. Includes drives that can be shared anywhere on the network.
CDROM 4 The drive is a CD-ROM. Includes read-only CD-ROM and read-write CD-ROM.
RAMDisk 5

A drive is a piece of random access memory (RAM) on the local computer that works like a disk drive.

 

 

File attribute constant

Only if your project's corresponding pairs containing these constant definitionsType libraryThese constants can only be used when there is an explicit reference.

constant value describe
Normal 0 Normal file. No properties are set.
ReadOnly 1 Read-only file. The attribute is readable/write.
Hidden 2 Hide files. The attribute is readable/write.
System 4 System files. The attribute is readable/write.
Volume 8 Disk drive volume label. The attribute is read-only.
Directory 16 Folder or directory. The attribute is read-only.
Archive 32 Files that have been changed since the last backup. The attribute is readable/write.
Alias 64 Link or shortcut. The attribute is read-only.
Compressed 128 Compress files. The attribute is read-only.

 

File input/output constant

Only if your project's corresponding pairs containing these constant definitionsType libraryThese constants can only be used when there is an explicit reference.

constant value describe
ForReading 1 Open the file for read-only operation. Files cannot be written.
ForWriting 2 Open a file for write operations. If there is a file with the same file name, the original content of the file will be overwritten.
ForAppending 8 Open the file and write to the end of the file.

IMEStatus constant

The following can be used anywhere in the codeconstantInstead of actual value.

JapaneseareaThe constants are as follows:

constant value describe
vbIMEModeNoControl 0 IME not installed (default)
vbIMEModeOn 1 Open IME
vbIMEModeOff 2 Close IME
vbIMEModeDisable 3 Invalid IME
vbIMEModeHiragana 4 Full width Hiragana mode
vbIMEModeKatakana 5 Full width Katakana mode
vbIMEModeKatakanaHalf 6 Half Width Katakana Mode
vbIMEModeAlphaFull 7 Full width Alphanumeric mode

vbIMEModeAlpha 8 Half-width Alphanumeric mode

The constants in the South Korean region are as follows:

constant value describe
vbIMEModeAlphaFull 7 Full width Alphanumeric mode
vbIMEModeAlpha 8 Half-width Alphanumeric mode
vbIMEModeHangulFull 9 Full width Hangul mode
vbIMEModeHangul 10 Half-width Hangul mode

The constant values ​​of Chinese regions are as follows:

constant value describe
vbIMEModeNoControl 0 IME not installed (default)
vbIMEModeOn 1 IME Open
vbIMEModeOff 2 IME off

 

Keycode constant

The following can be used anywhere in the codeconstantInstead of actual values:

constant value describe
vbKeyLButton 0x1 Left mouse button
vbKeyRButton 0x2 Right mouse button
vbKeyCancel 0x3 CANCEL key
vbKeyMButton 0x4 Middle mouse button
vbKeyBack 0x8 BACKSPACE key
vbKeyTab 0x9 TAB key
vbKeyClear 0xC CLEAR key
vbKeyReturn 0xD ENTER key
vbKeyShift 0x10 SHIFT key
vbKeyControl 0x11 CTRL key
vbKeyMenu 0x12 MENU key
vbKeyPause 0x13 PAUSE key
vbKeyCapital 0x14 CAPS LOCK key
vbKeyEscape 0x1B ESC
vbKeySpace 0x20 SPACEBAR key
vbKeyPageUp 0x21 PAGE UP key
vbKeyPageDown 0x22 PAGE DOWN key
vbKeyEnd 0x23 END key
vbKeyHome 0x24 HOME key
vbKeyLeft 0x25 LEFT ARROW key
vbKeyUp 0x26 UP ARROW key
vbKeyRight 0x27 RIGHT ARROW key
vbKeyDown 0x28 DOWN ARROW key
vbKeySelect 0x29 SELECT key
vbKeyPrint 0x2A PRINT SCREEN key
vbKeyExecute 0x2B EXECUTE key
vbKeySnapshot 0x2C SNAPSHOT key
vbKeyInsert 0x2D INSERT key
vbKeyDelete 0x2E DELETE key
vbKeyHelp 0x2F HELP key
vbKeyNumlock 0x90 NUM LOCK key

The A to Z keys are the same as the ASCII codes of the letter A – Z:

constant value describe
vbKeyA 65 A key
vbKeyB 66 B key
vbKeyC 67 C key
vbKeyD 68 D key
vbKeyE 69 E key
vbKeyF 70 F key
vbKeyG 71 G key
vbKeyH 72 H key
vbKeyI 73 I key
vbKeyJ 74 J key
vbKeyK 75 K key
vbKeyL 76 L key
vbKeyM 77 M key
vbKeyN 78 N key
vbKeyO 79 O key
vbKeyP 80 P key
vbKeyQ 81 Q key
vbKeyR 82 R key
vbKeyS 83 S key
vbKeyT 84 T key
vbKeyU 85 U key
vbKeyV 86 V key
vbKeyW 87 W key
vbKeyX 88 X key
vbKeyY 89 Y key
vbKeyZ 90 Z key

Keys 0 to 9 are the same as the ASCII codes for numbers 0 – 9:

constant value describe
vbKey0 48 0 key
vbKey1 49 1 key
vbKey2 50 2 keys
vbKey3 51 3 keys
vbKey4 52 4 keys
vbKey5 53 5 keys
vbKey6 54 6 keys
vbKey7 55 7 keys
vbKey8 56 8 keys
vbKey9 57 9 keys

The following constants represent keys on the numeric keypad:

constant value describe
vbKeyNumpad0 0x60 0 key
vbKeyNumpad1 0x61 1 key
vbKeyNumpad2 0x62 2 keys
vbKeyNumpad3 0x63 3 keys
vbKeyNumpad4 0x64 4 keys
vbKeyNumpad5 0x65 5 keys
vbKeyNumpad6 0x66 6 keys
vbKeyNumpad7 0x67 7 keys
vbKeyNumpad8 0x68 8 keys
vbKeyNumpad9 0x69 9 keys
vbKeyMultiply 0x6A MULTIPLICATION SIGN (*) key
vbKeyAdd 0x6B PLUS SIGN (+) key
vbKeySeparator 0x6C ENTER key
vbKeySubtract 0x6D MINUS SIGN () key
vbKeyDecimal 0x6E DECIMAL POINT (.) key
vbKeyDivide 0x6F DIVISION SIGN (/) key

The following constants represent function keys:

constant value describe
vbKeyF1 0x70 F1 key
vbKeyF2 0x71 F2 key
vbKeyF3 0x72 F3 key
vbKeyF4 0x73 F4 key
vbKeyF5 0x74 F5 key
vbKeyF6 0x75 F6 key
vbKeyF7 0x76 F7 key
vbKeyF8 0x77 F8 key
vbKeyF9 0x78 F9 key
vbKeyF10 0x79 F10 key
vbKeyF11 0x7A F11 key
vbKeyF12 0x7B F12 key
vbKeyF13 0x7C F13 key
vbKeyF14 0x7D F14 key
vbKeyF15 0x7E F15 key
vbKeyF16 0x7F F16 key

Miscellaneous constant

the followingconstantBy Visual Basic for ApplicationsType libraryDefinition, which can be used to replace the actual value anywhere in the code:

constant equal describe
vbCrLf Chr(13) + Chr(10) Combining carriage return and line break
vbCr Chr(13) Carriage return symbol
vbLf Chr(10) Line breaks
vbNewLine Chr(13) + Chr(10) or, on the Macintosh, Chr(13) New line characters specified by the platform; applicable to the current platform
vbNullChar Chr(0) Characters with a value of 0
vbNullString A string with a value of 0 Used to call external procedures; unlike strings with zero length ("")
vbObjectError -2147221504 The user-defined error number should be greater than this value, for example:
Number = vbObjectError + 1000
vbTab Chr(9) Tab word.
vbBack Chr(8) Backspace characters
vbFormFeed Chr(12) No function in Microsoft Windows or on the Macintosh
vbVerticalTab Chr(11) No function in Microsoft or on the Macintosh Windows