View Single Post
  #8   Report Post  
Posted to microsoft.public.excel.programming
Chip Pearson Chip Pearson is offline
external usenet poster
 
Posts: 7,247
Default Determining Office Version

Jim,

You can use Conditional Compilation combined with CallByName to
do what you want. For example,

#If VBA6 Then
If CInt(Application.Version) 9 Then
' Excel 2002 or 2003
CallByName Application.CommandBars, "DisableCustomize",
VbLet, True
Else
' Excel 2000
End If
#Else
' Excel 97
#End If

--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com



"Jim Gross" wrote in
message ...
Thanks for your response, Dave.

I know about Application.Version. Problem is that
CommandBars.DisableCustomize doesn't exist in Excel 2000
VBA, but I need it when the workbook is hosted in Office
XP. I can force the 2000 compiler to ignore that code if
I use conditional compilation with compiler directives:
#If...#Then...#Else...#End If (new in Excel 2000.)
Otherwise, 2000 VBA throws an error just at the sight of
CommandBars.DisableCustomize, before any code in the
module even executes.

Unfortunately, application.version doesn't work with the
compiler directives. The directives work only with hard
constants, and there aren't any built-in constants for
Excel/Office version that I can find.

The solution I have found is somewhat convoluted,
involving the use of Add-In methods to load (and later on
unload) part of the VBA code from a file or a worksheet
into a code module after editing it to set a conditional
compilation constant based on application.version. It's
not pretty, but it does meet the objective of a single
code base and so far it seems to work.

Jim Gross