PDA

View Full Version : Solved: Compiler Directives (#Const, #If, etc.)



Paul_Hossler
08-31-2009, 07:50 AM
Recently I had to make a WB 2003 and 2007 compatible.

To make my life easy and only have one version to maintain, I bracketed the 2007 code (Ribbon, etc.) and the 2003 code (Commandbars, etc.) with #If / #Else / #EndIf directives


Option Explicit

#Const Ver = "2007"

Sub DoStuff()
#If Ver = "2007" Then
Call Do2007

#Else
Call Do2003

#End If

End Sub


1. The #Const is private to each module. Is there any way to avoid that?

2. I find it hard to believe that there aren't any built in directives, such as OS, Platform, Version, etc. Are there some and I'm missing them?

Thanks

Paul

mdmackillop
08-31-2009, 09:18 AM
MsgBox Application.Version

Paul_Hossler
08-31-2009, 10:28 AM
Thanks, not too sure how that will help.

Some 2003 VBA statements will not 'compile' at all in 2007, and vice versa.

So I need to use conditional compiler directives to allow some 2003 VBA to be 'bypassed' if the WB is used in Excel2007, and the same going the other way

Paul

Bob Phillips
08-31-2009, 10:50 AM
In the project properties in the VBIDE for your project, in the 2007 version enter

Ver2007=-1

in the Conditional Compilation Arguments and use, nothing for the 2003 verison



Sub DoStuff()
#If Ver2007 Then
Call Do2007

#Else
Call Do2003

#End If

End Sub

Paul_Hossler
08-31-2009, 08:02 PM
Works great

Still seems a little funny that MS doesn't have a least a few standard Directives pre-defined

Thanks

Paul

Bob Phillips
09-06-2009, 02:57 PM
They do have a few, But not that one. Don't forget, VBA has been aboandoned as regards enhancements.