VBA versions

Versions


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