-
Notifications
You must be signed in to change notification settings - Fork 225
/
VBA.bas
515 lines (479 loc) · 10.7 KB
/
VBA.bas
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
' Office VBA Reference
' https://learn.microsoft.com/en-us/office/vba/api/overview/language-reference
' [MS-VBAL]: VBA Language Specification
' https://learn.microsoft.com/en-us/openspecs/microsoft_general_purpose_programming_languages/ms-vbal/
' https://msopenspecs.azureedge.net/files/MS-VBAL/[MS-VBAL].pdf
' Visual Basic 6.0 Documentation
' https://learn.microsoft.com/en-us/previous-versions/visualstudio/visual-basic-6/visual-basic-6.0-documentation
' FreeBASIC Manual
' https://www.freebasic.net/wiki/DocToc
'! VBA keywords =======================================================
' https://learn.microsoft.com/en-us/office/vba/language/reference/statements
AppActivate
Beep
Call
ChDir
ChDrive
Close
Const As
Date
Declare PtrSafe Sub Lib Alias
Declare PtrSafe Function Lib Alias As
DefBool DefByte DefInt DefLng DefLngLng DefLngPtr
DefCur DefSng DefDbl DefDec DefDate DefStr DefObj DefVar
DeleteSetting
Dim WithEvents As New
Do
End
Exit Do
Do While
Loop
Do Until
Loop
Do
Loop While
Do
Loop Until
Loop
Enum
End Enum
Erase
Error
Public Event
FileCopy
For Each In
Exit For
Next
For To Step
Next
Public Private Friend Static Function As
Optional ByVal ByRef ParamArray As
Exit Function
End Function
Get
GoSub Return
GoTo
If Then
ElseIf Then
Else
End If
If Then Else
Implements
Input
Kill
Let
Line Input
Load
Lock To
Unlock To
LSet
Mid()
MkDir
Name As
On Error GoTo
On Error Resume Next
On GoSub
On GoTo
Open For Access As Len
Option Base
Option Compare Binary Text Database
Option Explicit
Option Private Module
Print Spc() Tab()
Private WithEvents As New
Property Get As
Exit Property
End Property
Property Let
End Property
Property Set
End Property
Public WithEvents As New
Put
RaiseEvent
Randomize
ReDim Preserve As
Rem
Reset
Resume Next
RmDir
RSet
SavePicture ' VB6
SaveSetting
Seek
Select Case
Case Else
Case To
End Select
SendKeys
Set New Nothing
SetAttr
Static As New
Stop
Sub
Exit Sub
End Sub
Time
Private Public Type
End Type
Unload
While
Wend
Width
With
End With
Write
' https://learn.microsoft.com/en-us/office/vba/language/reference/keywords-visual-basic-for-applications
Me
Empty Null
False True
' https://learn.microsoft.com/en-us/office/vba/language/reference/user-interface-help/operator-summary
AddressOf And Eqv Imp Is Like Mod Not Or Xor
' VB6
Class Attribute Version
Begin
BeginProperty
EndProperty
End
If
EndIf
'! types =======================================================
' https://learn.microsoft.com/en-us/office/vba/language/reference/user-interface-help/data-type-summary
Boolean Byte
Currency
Date Decimal Double
Integer
Long LongLong LongPtr
Object
Single String
Variant
Any
'! directives =======================================================
' https://learn.microsoft.com/en-us/office/vba/language/reference/directives
#Const
#If Then
#ElseIf Then
#Else
#End If
#If
#EndIf
'! objects =======================================================
' https://learn.microsoft.com/en-us/office/vba/language/reference/objects-visual-basic-for-applications
Collection {
Add()
Item(index)
Remove(index)
Count
}
Debug {
Assert()
Print()
}
Dictionary {
Add()
Exists(key)
Items()
Keys()
Remove(key)
RemoveAll()
CompareMode
Count
Item(key)
Key(key)
}
{ ' Drive
AvailableSpace
DriveLetter
DriveType
FileSystem
FreeSpace
IsReady
RootFolder
SerialNumber
ShareName
TotalSize
VolumeName
}
Err {
Clear()
Raise()
Description
HelpContext
HelpFile
Number
Source
}
{ ' File
Copy()
Delete()
Move()
OpenAsTextStream([iomode, [format]])
Attributes
DateCreated
DateLastAccessed
DateLastModified
Drive
Name
ParentFolder
Path
ShortName
ShortPath
Size
' Type
}
FileSystemObject {
BuildPath(path, name)
CopyFile()
CopyFolder()
CreateFolder(foldername)
CreateTextFile(filename, [overwrite, [unicode]])
DeleteFile()
DeleteFolder()
DriveExists(drivespec)
FileExists(filespec)
FolderExists(folderspec)
GetAbsolutePathName(pathspec)
GetBaseName(path)
GetDrive(drivespec)
GetDriveName(path)
GetExtensionName(path)
GetFile(filespec)
GetFileName(pathspec)
GetFolder(folderspec)
GetParentFolderName(path)
GetSpecialFolder(folderspec)
GetTempName()
MoveFile()
MoveFolder(source, destination)
OpenTextFile(filename, [iomode, [create, [format]]])
Drives
}
{ ' Folder
Add()
Files
IsRootFolder
SubFolders
}
{ ' TextStream
Close()
Read(characters)
ReadAll()
ReadLine()
Skip(characters)
SkipLine()
Write(string)
WriteBlankLines(lines)
WriteLine([string])
AtEndOfLine
AtEndOfStream
Column
Line
}
{ ' UserForm
Hide()
PrintForm()
Show()
Calendar
RightToLeft
ShowModal
StartUpPosition
}
'! functions =======================================================
' https://learn.microsoft.com/en-us/office/vba/language/reference/functions-visual-basic-for-applications
' https://learn.microsoft.com/en-us/office/vba/language/concepts/getting-started/returning-strings-from-functions
' Conversion functions
Asc(string)
AscB(string)
AscW(string)
Chr(charcode)
ChrB(charcode)
ChrW(charcode)
CVErr(errornumber)
Format(Expression, [Format], [FirstDayOfWeek], [FirstWeekOfYear])
Hex(number)
Oct(number)
Str(number)
Val(string)
' Type conversion functions
CBool(expression)
CByte(expression)
CCur(expression)
CDate(expression)
CVDate(expression)
CDbl(expression)
CDec(expression)
CInt(expression)
CLng(expression)
CLngLng(expression)
CLngPtr(expression)
CSng(expression)
CStr(expression)
CVar(expression)
' Math functions
Abs(number)
Atn(number)
Cos(number)
Exp(number)
Int(number)
Fix(number)
Log(number)
Rnd(Number)
Sgn(number)
Sin(number)
Sqr(number)
Tan(number)
' Other functions
Array(arglist)
CallByName(object, procname, calltype, [args])
Choose(index, choice)
Command()
CreateObject(name, [servername])
CurDir(drive)
Date
DateAdd(interval, number, date)
DateDiff(interval, date1, date2, [firstdayofweek, [firstweekofyear]])
DatePart(interval, date, [firstdayofweek, [firstweekofyear]])
DateSerial(year, month, day)
DateValue(date)
Day(date)
DDB(cost, salvage, life, period, [factor])
Dir(pathname, [attributes])
DoEvents()
Environ({ envstring | number })
EOF(filenumber)
Error(errornumber)
FileAttr(filenumber, returntype)
FileDateTime(pathname)
FileLen(pathname)
Filter(sourcearray, match, [include, [compare]])
FormatCurrency(Expression, [NumDigitsAfterDecimal, [IncludeLeadingDigit, [UseParensForNegativeNumbers, [GroupDigits]]]])
FormatDateTime(Date, [NamedFormat])
FormatNumber(Expression, [NumDigitsAfterDecimal, [IncludeLeadingDigit, [UseParensForNegativeNumbers, [GroupDigits]]]])
FormatPercent(Expression, [NumDigitsAfterDecimal, [IncludeLeadingDigit, [UseParensForNegativeNumbers, [GroupDigits]]]])
FreeFile(rangenumber)
FV(rate, nper, pmt, [pv, [type]])
GetAllSettings(appname, section)
GetAttr(pathname)
GetObject([pathname], [class])
GetSetting(appname, section, key, [default])
Hour(time)
IIf(expr, truepart, falsepart)
Input(number, filenumber)
InputB(number, filenumber)
InputBox(prompt, [title], [default], [xpos], [ypos], [helpfile, context])
InStr([start], string1, string2, [compare])
InStrB([start], string1, string2, [compare])
InStrRev(stringcheck, stringmatch, [start, [compare]])
IPmt(rate, per, nper, pv, [fv, [type]])
IRR(values(), [guess])
IsArray(varname)
IsDate(expression)
IsEmpty(expression)
IsError(expression)
IsMissing(argname)
IsNull(expression)
IsNumeric(expression)
IsObject(identifier)
Join(sourcearray, [delimiter])
LBound(arrayname, [dimension])
LCase(string)
Left(string, length)
LeftB(string, length)
Len(string | varname)
LenB(string | varname)
Loc(filenumber)
LOF(filenumber)
LTrim(string)
RTrim(string)
Trim(string)
Mid(string, start, [length])
MidB(string, start, [length])
Minute(time)
MIRR(values( ), finance_rate, reinvest_rate)
Month(date)
MonthName(month, [abbreviate])
MsgBox(prompt, [buttons,] [title,] [helpfile, context])
Now
NPer(rate, pmt, pv, [fv, [type]])
NPV(rate, values( ))
Partition(number, start, stop, interval)
Pmt(rate, nper, pv, [fv, [type]])
PPmt(rate, per, nper, pv, [fv, [type]])
PV(rate, nper, pmt, [fv, [type]])
QBColor(color)
Rate(nper, pmt, pv, [fv, [type, [guess]]])
Replace(expression, find, replace, [start, [count, [compare]]])
RGB(red, green, blue)
Right(string, length)
RightB(string, length)
Round(expression, [numdecimalplaces])
Second(time)
Seek(filenumber)
Shell(pathname, [windowstyle])
SLN(cost, salvage, life)
Space(number)
Spc(n)
Split(expression, [delimiter, [limit, [compare]]])
StrComp(string1, string2, [compare])
StrConv(string, conversion, [LCID])
String(number, character)
StrReverse(expression)
Switch(expr-1, value-1, [expr-2, value-2…, [expr-n, value-n]])
SYD(cost, salvage, life, period)
Tab(n)
Time
Timer
TimeSerial(hour, minute, second)
TimeValue(time)
TypeName(varname)
UBound(arrayname, [dimension])
UCase(string)
VarType(varname)
Weekday(date, [firstdayofweek])
WeekdayName(weekday, abbreviate, firstdayofweek)
Year(date)
'! constants =======================================================
' https://learn.microsoft.com/en-us/office/vba/language/reference/constants-visual-basic-for-applications
' Calendar constants
vbCalGreg vbCalHijri
' CallType constants
vbMethod vbGet vbLet vbSet
' Color constants
vbBlack vbRed vbGreen vbYellow vbBlue vbMagenta vbCyan vbWhite
' Comparison constants
vbUseCompareOption vbBinaryCompare vbTextCompare vbDatabaseCompare
' Date constants
vbUseSystem vbSunday vbMonday vbTuesday vbWednesday vbThursday vbFriday vbSaturday
vbUseSystemDayOfWeek vbFirstJan1 vbFirstFourDays vbFirstFullWeek
' Date Format constants
vbGeneralDate vbLongDate vbShortDate vbLongTime vbShortTime
' Dir, GetAttr, and SetAttr constants
vbNormal vbReadOnly vbHidden vbSystem vbVolume vbDirectory vbArchive vbAlias
' DriveType constants
' File Attribute constants
' File Input/Output constants
' Form constants
vbModeless vbModal
' Keycode constants
' Miscellaneous constants
vbCrLf vbCr vbLf vbNewLine vbNullChar vbNullString vbObjectError vbTab vbBack vbFormFeed vbVerticalTab
' MsgBox constants
vbOKOnly vbOKCancel vbAbortRetryIgnore vbYesNoCancel vbYesNo vbRetryCancel
vbCritical vbQuestion vbExclamation vbInformation
vbDefaultButton1 vbDefaultButton2 vbDefaultButton3 vbDefaultButton4
vbApplicationModal vbSystemModal
vbMsgBoxHelpButton vbMsgBoxSetForeground vbMsgBoxRight vbMsgBoxRtlReading
vbOK vbCancel vbAbort vbRetry vbIgnore vbYes vbNo
' QueryClose constants
vbFormControlMenu vbFormCode vbAppWindows vbAppTaskManager
' Shell constants
vbHide vbNormalFocus vbMinimizedFocus vbMaximizedFocus vbNormalNoFocus vbMinimizedNoFocus
' SpecialFolder constants
' StrConv constants
vbUpperCase vbLowerCase vbProperCase vbWide vbNarrow vbKatakana vbHiragana vbUnicode vbFromUnicode
' System Color constants
' Tristate constants
vbTrue vbFalse vbUseDefault
' VarType constants
vbEmpty vbNull vbInteger vbLong vbSingle vbDouble vbCurrency vbDate vbString vbObject vbError
vbBoolean vbVariant vbDataObject vbDecimal vbByte vbLongLong vbUserDefinedType vbArray