Conditional compilation

W

WK

Hi,

I wrote an Excel programm under Excel 2000. Some parts are not running in
Excel 97 because of some new used features Excel 2000 offers. To run the
Excel programm in both versions -in Excel 97 with some reduced functions
:( - I used the conditional compilation.

So, in the project property I set the following statement "EXCEL2000 = 0"
for the program that shall run with Excel 97. In the VBA code I used the
conditional statements in the necessary code sections as follows

#IF EXCEL2000=0 then
....
#ELSE
....
# END IF

Everything works fine when I devoled all under Excel 2000. But when I use
the programm in Excel 97 I get a runtime-error during the start of the Excel
programm. When I translate the error message into English it is as follows :
"You have to finish an #IF statement with #END IF". This I do !!!! The
program shows the blue bar in the beginning of the second function of a
module that I completey will only offer for Excel 2000 users (using the
conditional IF-function mentioned above).

What is rediclious to me, when I again compile the Excel VBA after the
runtime-error appeared everything seems fine and I get no compile error.

This is not very satisfying.

Does anyone has an idea why Excel 97 behaves so and how I can prevent this
error message.

Thanks in advance,
Winfried (800)
 
O

Orlando Magalhães Filho

Hi WK,

Use the structure below. You can compile it only on Excel 97, but you can
run it in all Excel versions (97 to 2002).

Sub Main()
'Here you can put all statements compatible with all Excel Version
If Val(Application.Version) > 8 Then
#If VBA6 Then
'Here you can put all statements not compatible with Excel 97
If Val(Application.Version) > 9 Then VBAExcel10
#End If
End If
End Sub

Sub VBAExcel10()
'Here you can put all statements not compatible with Excel 97 and
Excel 2000
End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top