PC Review


Reply
Thread Tools Rate Thread

Avoiding Compile Error for Unsupported Methods

 
 
Kevin
Guest
Posts: n/a
 
      22nd Dec 2008
I have written some VBA code in an Excel 2003 workbook that also needs to be
accessible in Excel 2007, so the file format is 2003 (xls). Whenever I open
it in Compatibility Mode in 2007 and then try to save it the Compatibility
Checker pops up with warnings that I know will not cause problems for me. So,
I added the following line of code to suppress the Compatibility Checker:

ThisWorkbook.CheckCompatibility = False

This works great in Excel 2007, but I get a compile error when I open it in
2003 because the CheckCompatibility method is not supported in 2003.

My question is: Is there a way to somehow insulate this line of code so that
it is only compiled when the file is opened in 2007? Some sort of compiler
directive that conditionally compiles it based on the version? Or any other
ideas? :-)

Thanks in advance for your help!

Kevin
 
Reply With Quote
 
 
 
 
Kevin
Guest
Posts: n/a
 
      22nd Dec 2008
I figured it out and used the #Const directive a compiler constant that I
then used in a #If - Then -#Else loop to run the line of code only if it was
running in Excel 2007. For anyone else who may benefit from this, here's the
code:

If Application.Version = "12.0" Then
boolExcelVersion12 = True
Else
boolExcelVersion12 = False
End If

#Const constboolExcelVersion12 = boolExcelVersion12

#If constboolExcelVersion12 Then
ThisWorkbook.CheckCompatibility = False
#End If

Kevin

====================

"Kevin" wrote:

> I have written some VBA code in an Excel 2003 workbook that also needs to be
> accessible in Excel 2007, so the file format is 2003 (xls). Whenever I open
> it in Compatibility Mode in 2007 and then try to save it the Compatibility
> Checker pops up with warnings that I know will not cause problems for me. So,
> I added the following line of code to suppress the Compatibility Checker:
>
> ThisWorkbook.CheckCompatibility = False
>
> This works great in Excel 2007, but I get a compile error when I open it in
> 2003 because the CheckCompatibility method is not supported in 2003.
>
> My question is: Is there a way to somehow insulate this line of code so that
> it is only compiled when the file is opened in 2007? Some sort of compiler
> directive that conditionally compiles it based on the version? Or any other
> ideas? :-)
>
> Thanks in advance for your help!
>
> Kevin

 
Reply With Quote
 
Jim Rech
Guest
Posts: n/a
 
      22nd Dec 2008
Put that line in its own sub and call it only if Val(Application.Version)>=
12.

--
Jim
"Kevin" <(E-Mail Removed)> wrote in message
news:9FBB239B-AAF8-484C-9151-(E-Mail Removed)...
|I have written some VBA code in an Excel 2003 workbook that also needs to
be
| accessible in Excel 2007, so the file format is 2003 (xls). Whenever I
open
| it in Compatibility Mode in 2007 and then try to save it the Compatibility
| Checker pops up with warnings that I know will not cause problems for me.
So,
| I added the following line of code to suppress the Compatibility Checker:
|
| ThisWorkbook.CheckCompatibility = False
|
| This works great in Excel 2007, but I get a compile error when I open it
in
| 2003 because the CheckCompatibility method is not supported in 2003.
|
| My question is: Is there a way to somehow insulate this line of code so
that
| it is only compiled when the file is opened in 2007? Some sort of compiler
| directive that conditionally compiles it based on the version? Or any
other
| ideas? :-)
|
| Thanks in advance for your help!
|
| Kevin

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
compile dll with calls to methods that dont exit yet Peted Microsoft C# .NET 2 18th Feb 2007 12:10 PM
Avoiding compile errors caused by using different Access versions =?Utf-8?B?YmVhY2h5?= Microsoft Access 0 9th Mar 2006 10:44 PM
VBAProject name compile error, not defined at compile time Matthew Dodds Microsoft Excel Programming 1 13th Dec 2005 07:17 PM
Unsupported methods for running the PowerPoint Viewer 97 from a CD-ROM or DVD-ROM Timothy L Microsoft Powerpoint 2 17th Aug 2005 01:24 AM
Unsupported methods for XL macro in IE Jean-Yves Microsoft Excel Programming 0 20th Aug 2004 03:34 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 10:07 PM.