User FAQs

If you have a question, please send it to us.


1) Is there any Microsoft documentation for VBA Programming ?

link - learn.microsoft.com/en-gb/office/vba/api/overview/language-reference 
link - learn.microsoft.com/en-us/office/vba/library-reference/concepts/getting-started-with-vba-in-office

2) Is VBA an Interpreted or Compiled programming language ?
VBA is Interpreted.
Although there is a pre-compilation step, which is a little confusing.
The code is converted into an intermediate language to be executed by the interpreter.
This allows you to pause code, edit a line mid-execution, and resume running it immediately.


3) Is VBA a Strongly or Weakly Typed programming language ?
VBA is Weakly Typed.
It allows implicit type conversion when data types are not compatible.

Dim x As Integer 
x = "123" 'The string is automatically converted to a number

4) Is VBA a Dynamically or Statically Typed programming language ?
VBA is Statically Typed.
This has nothing to do with whether you use the Variant data type or not.
The Variant data type is a fixed size and it is just the value inside that is dynamic.

Dim myNumber As Long 
Dim myText As String
Dim myFlag As Boolean

5) Is VBA an Object Oriented or Functional programming language ?
VBA is classified as a Procedural programming language which has some object oriented capabilities.
You can create Class Modules where you can define your own objects, properties and methods.
You can use Class Modules to achieve Encapsulation and Polymorphism.
There is only Interface Inheritance (using Implements), there is no Implementation (or Class) Inheritance.
This means you cannot create a parent class and then create a child class that automatically inherits all its code and properties.


6) Should I indent my code with spaces or tabs ?
Always use tabs to indent your code to bring structure, never use spaces.

link - youtube.com/watch?v=SsoOG6ZeyUI 

7) Do I really need to add comments ?
And only add "value added" comments which explain why. Do not add trivial comments.
Put your comments on the line above the code it is describing.
Make the indentation match the indentation of the code it refers to.

Public Sub MyRoutine() 
'comment associated with the If statement
   If (bValue = True) Then

8) Do I need to add a Comment Block ?
When you are working with other developers it can be useful to add comment blocks.
Add them Comment Block above every procedure and function.


9) What is Option Explicit and what does it do ?

Option Explicit 

Including this at the top of a module means that all variables must be explicitly declared using the Dim statement.
This statement only affects the module it is declared in.


10) What problems do you have if you don't use Option Explicit ?
Variables do not have to be declared before they are used.
Mistyping a variable name will create a new variable and will probably create a run-time error.


11) What is the difference between a Literal Constant and a Symbolic Constant ?
A literal constant is a specific value such as a number, date or text.

Dim myDate As Date 
myDate = #12/31/2020#

A symbolic constant is a literal constant that is represented by a name.

Public Const sVALUE As String = "text" 

12) What is the difference between a Do-While loop and a Do-Until loop ?
In a Do-While loop the condition must be True.

Do 
   statements
Loop While boolean-expression = True

In a Do-Until loop the condition must be False.

Do Until boolean-expression = False 
    statements
Loop

13) Write a Do-While loop that is executed at least once ?

Do 
   statements
Loop While boolean-expression = True

14) Write a Do-Until loop that has the condition at the top ?

Do Until boolean-expression = False 
    statements
Loop

15) Do I need to make any changes to my code for it to run in 64-bit Office ?
Most of the code will work just fine, although there are a few things to look out for.

link - learn.microsoft.com/en-us/office/vba/language/concepts/getting-started/64-bit-visual-basic-for-applications-overview 

16) What is the Call Statement and when would it be used ?
The Call statement can be used when passing execution to a subroutine.
When it is used you must enclose any arguments in parentheses.
You should always use the Call keyword because it makes your code easier to read.

Sub MySubroutine() 
   MySub1
   MySub2 50
   Call MySub1
   Call MySub2(50)
End Sub

Sub MySub1()
End Sub
Sub MySub2(ByVal iNumber As Integer)
End Sub

17) What is the difference between a Sub and a Function ?
A Sub (subroutine or procedure) is a method that does not return a value.
A Function is a method that ALWAYS returns a value.
If a Function has no 'As' keyword then the default is 'As Variant'
The following two functions are identical.

Function MyFunction() 
   MyFunction = 100
End Function
Function MyFunction() As Variant
   MyFunction = 100
End Function

18) Can you use the Call statement when passing execution to a Function ?
Yes. You can use the Call keyword when you want to ignore the returned value.
In the first two function calls the value returned from these functions is assigned to the variable 'myResult'.
In the last four function calls the value returned from these functions is ignored.

Sub MySubroutine() 
   Dim myResult as Integer

   myResult = MyFun1
   myResult = MyFun2(50)
   MyFun1
   MyFun2 50
   Call MyFun1
   Call MyFun2(50)
End Sub

Function MyFun1() As Integer
   MyFun1 = 100
End Function
Function MyFun2(ByVal iNumber As Integer) As Integer
   MyFun2 = 100 + iNumber
End Function

19) Can you explain why the last subroutine call does not increment the amount variable ?
There are only two ways to call a subroutine.
The first is to not use the Call method in which case the arguments do not appear in parentheses.
The second is to use the Call method in which case the arguments have to appear in parentheses.
In the last subroutine call the argument (or expression) is being evaluated before being passed to the mySub2 subroutine.
You can enclose expressions inside there own set of parentheses to force them to be evaluated first.

Sub MySubroutine() 
   Dim iAmount As Integer
   iAmount = 50
   Debug.Print iAmount '50

   MySub2 iAmount
   Debug.Print iAmount '100

   Call MySub2(iAmount)
   Debug.Print iAmount '150

   MySub2 (iAmount)
   Debug.Print iAmount '150
End Sub

Sub MySub2(ByRef iArgAmount As Integer)
   iArgAmount = iArgAmount + 50
End Sub

20) Is it possible to return more than one value from a Function or Subroutine ?
Yes. There are several ways this can be achieved:
*) By returning an array from a function.
*) By returning a collection from a function.
*) By returning a class from a function.

Public Function MyFunction() As String() 
Public Function MyFunction() As VBA.Collection
Public Function MyFunction() As MyClass

*) Passing in several arguments to a subroutine using ByRef.

Public Sub MySubroutine(ByRef sArgument1 As String, _ 
                        ByRef sArgument2 As String)

*) Passing in an array, which can only be passed by reference.
*) Passing in a collection, which is always passed by reference.
*) Passing in a class, which is always passed by reference.

Public Sub MySubroutine(ByRef vaArray() As String) 
Public Sub MySubroutine(ByRef myCollection As VBA.Collection)
Public Sub MySubroutine(ByRef myClassVariable As MyClass)

21) What is the difference between ByVal and ByRef and which is the default ?
ByRef - (default) - passes a pointer to the variable in memory.
ByVal - passes a copy of the variable.
Passing ByRef is the default when the passing mechanism is not specified.
The following two subroutines are identical.

Sub MySubroutine(iNumber As Integer) 
End Sub
Sub MySubroutine(ByRef iNumber As Integer)
End Sub

22) What is displayed in the Immediate Window ?

Sub MySubroutine() 
    Debug.Print VBA.TypeName(MyFunction1) 'displays Empty
    Debug.Print VBA.TypeName(MyFunction2) 'displays Empty
    Debug.Print VBA.TypeName(MyFunction3) 'displays Empty
End Sub

Function MyFunction1()
End Function

Function MyFunction2() As Variant
End Function

Function MyFunction3() As Variant
Dim myVariant As Variant
   MyFunction3 = myVariant 'defaults to Empty
End Function

A Function always has a value returned from it.
If the data type is not explicitly provided then a Variant data type will be used.


23) What is displayed in the Immediate Window ?

Sub MySubroutine() 
   Debug.Print MyFunction1 'displays 100
   Debug.Print MyFunction2 'displays 0

   Dim myObject As Object
   Set myObject = MyFunction3
   Debug.Print (myObject Is Nothing) 'displays True
End Sub

Function MyFunction1() As Long
   MyFunction1 = 100
End Function

Function MyFunction2() As Long
   Exit Function
   MyFunction2 = 100
End Function

Function MyFunction3() As Object
End Function

The first function returns 100 because this is the value that is assigned to the function name.
The second function returns 0 because if a value has not been assigned to the function name (before an Exit Function or End Function) the default value for the return data type is passed back.
The third function returns Nothing because when a value is not assigned to the function name the default value for the return data type is passed back. In this case it is Object whose default value is Nothing.
When a function returns a reference data type it must be assigned to a variable using the Set statement.


© 2026 Better Solutions Limited. All Rights Reserved. © 2026 Better Solutions Limited TopPrevNext