VBA versions
Versions
- Excel 2016: Microsoft Visual Basic for Applications 7.1
- Excel 2013: Microsoft Visual Basic for Applications 7.1
- Excel 2010: Microsoft Visual Basic for Applications 7.0 (introduced the 64-bit version)
- Excel 2007: Microsoft Visual Basic 6.5
- Excel 2003: Microsoft Visual Basic 6.5
Compiler directives
Code written in VBA 7 may not be backward compatible. To conditionally compile selected blocks of Visual Basic code, use the #If...Then...#Else compiler directive. Syntax - code 1, and example code 2.
Code 1: SYNTAX:
#If...Then...#Else Directive conditionally compile
'' #If Vba7 Then '' statements '' #Else '' [elsestatements] '' #EndIf
Conditionally compile the UDF ArgumentDescriptions parameter which was introduced in VBA 7. Code 2 - line 26. The compiler directive is distinguished from a normal If...Then...Else statement bur the use of the # symbol line 16, line 21, and line 27. Link to GetCF function
Code 2: Sub
GetCFDescribeFunction compiler directive
'' Code location - [ThisWorkbook (code)] module
Private Sub GetCFDescribeFunction()
Dim FuncName As String
Dim FuncDesc As String
Dim FuncCategory As String
Dim FuncArgDesc(1 To 2) As String
FuncName = "GetCF"
FuncDesc = "Returns information about the reference cell"
FuncCategory = 9 '' Information category
FuncArgDesc(1) = "is the cell that you want information about."
FuncArgDesc(2) = "Optional. If 0 or omitted - returns Address and Format; If 1 - returns Address, Format, and Value; If 2 - returns 1, with comments; " & _
"If 3 returns Address, Format, Text, and Value, with comments "
#If VBA6 Then
Application.MacroOptions _
Macro:=FuncName, _
Description:=FuncDesc, _
Category:=FuncCategory
#ElseIf VBA7 Then
Application.MacroOptions _
Macro:=FuncName, _
Description:=FuncDesc, _
Category:=FuncCategory, _
ArgumentDescriptions:=FuncArgDesc
#End If
End Sub
- This example was developed in Excel 2013 with VBA 7.1
- Published: 9th October 2016
- Revised: Saturday 25th of February 2023 - 09:37 AM, [Australian Eastern Standard Time (EST)]
