This is intended to be a short and stuffed series on VBA programming

Quick setup tutorial :
==========
open word
click on the miscrosoft icon left top
choose word options
according to your office version, choose show developper tab
on the developper tab record and stop a macro
choose visual basic logo
on the file explorer choose module
choose new macros
the editor should appear
click on view
click on immidiate window
you are set

Note
==========
I am no VBA fan

Variable Creation
==========
VBA creates a new variable
1 if you declare it
2 if it encounters a non declared variable creates it at the moment
this behaviour might have unintended resuls as a mistyped variable name might end up as a new variable

Variable Naming
==========
Variable names cannot :
– Have spaces
– Start with a number
– Contain special chartacters (see simple declaration)
Valid names
– A char is valid e.g. a
– _ is allowed e.g. a_variable_name
Good practices
— specify a short notification about type in the variable name
strMyName = “a”

Simple Variable Types
==========
Types and description
+ Boolean => True or False
+ Byte => integer from 0 to 255
+ Currency => +- <15 digits> . <4 digits>
+ Date
+ Decimal
+ Double
+ Integer
+ Long
+ Object
+ Single
+ String
|_ + fixed length
|_ + variable length
+ Variant => normally holds any type of data

Simple Declarations
==========
Adding some symbols at the end of a variable automatically declares it’s type
-> % for Integer
Number_of_pupils% = 5
-> & for long
-> @ for Currency
Pounds_i_own@
-> ! for Single
-> # for Double
-> $ for String

Force document to require prior declaration
==========
Add at the beginning of the document
Option Explicit

Specifying variables
==========
Write
Sub testing()
Dim a
a = 5
Debug.Print a
End Sub
Then run,
5 will appear in the immediate window (see top how to enable it)

Right data type
==========
Dim a only can cause errors etc
Better specify what you want
Dim a as Integer

Constants
==========
Const a as String
Will prevent reassignments to a

Multiple Declarations
==========
Dim a as String, b as Integer
Dim a,b,c as String

Public and Private
==========
Public means available to all modules of a project
Public authorName as String
Private means available to current module only
Private someRestrictedInfo as String

Static
==========
Static variables are available to only the procedures that defined them
Sub mySub()
Static x as Integer
End Sub
It is also persistent

Best Online Bookmark manager : https://www.bookmarkninja.com