Microsoft KB Archive/213734

= XL2000: Conditional Compilation Code Is Lost When You Save File as an Excel 5.0 File =

Article ID: 213734

Article Last Modified on 11/23/2006

-

APPLIES TO


 * Microsoft Excel 2000 Standard Edition

-



This article was previously published under Q213734





SYMPTOMS
If you save a Microsoft Excel 2000 workbook in the Microsoft Excel 5.0 Workbook file format, you lose any conditional compilation directives in your code.

NOTE: You are not warned about the loss of your code when you save your file in the 5.0 file format.



CAUSE
Conditional compilation directives are not used in earlier versions of Visual Basic for Applications and Microsoft Excel.



RESOLUTION
If you have already saved your file in the 5.0 file format, you must reenter your conditional compilation directives when you open your file in Microsoft Excel 2000.

If you have not yet saved your file in the 5.0 file format and you want to preserve your conditional compilation directives, either save your module as a .bas file (you can import it into other projects) or comment the conditional compilation directives, and then save your file in the 5.0 file format.



MORE INFORMATION
You can use conditional compilation, using the #If ... Then ... #Else directives, to run blocks of code selectively. This is typically used in cross-platform Sub procedures. The #If ... Then ... #Else directives evaluate expressions containing conditional compiler constants to determine what code to execute in the macro.

Microsoft provides programming examples for illustration only, without warranty either expressed or implied, including, but not limited to, the implied warranties of merchantability and/or fitness for a particular purpose. This article assumes that you are familiar with the programming language being demonstrated and the tools used to create and debug procedures. Microsoft support professionals can help explain the functionality of a particular procedure, but they will not modify these examples to provide added functionality or construct procedures to meet your specific needs. If you have limited programming experience, you may want to contact a Microsoft Certified Partner or the Microsoft fee-based consulting line at (800) 936-5200. For more information about Microsoft Certified Partners, please visit the following Microsoft Web site:

https://partner.microsoft.com/global/30000104

For more information about the support options that are available and about how to contact Microsoft, visit the following Microsoft Web site:

http://support.microsoft.com/default.aspx?scid=fh;EN-US;CNTACTMS

The following macro (outlined in "Method 1" and "Method 2") provides an example of how to use the conditional compilation constants.

Method 1
To use the conditional compilation constants in a module, follow these steps:  Save and close any open workbooks, and then open a new workbook. Start the Visual Basic Editor (press ALT+F11). On the Insert menu, click Module.  Type the following code in the module: Sub Cond_Comp #If test Then MsgBox "test evaluates to True" #Else MsgBox "test evaluates to False" #End If End Sub  Run the Cond_Comp macro.
 * 1) Const test = 1

Because the conditional compilation constant "test" has a value of 1, a message box will display the message "test evaluates to True."</li>  Change the first line of code in the module to and then run the Cond_Comp macro. A message box will display the message "test evaluates to False." </li></ol>
 * 1) Const test = 0

Method 2
Conditional compilation constants can also be specified in the Project Properties dialog box instead of in a module. To use the conditional compilation constants in the Project Properties box, follow these steps: <ol>  Comment the first line in the module so that it looks like the following: '#Const test = 0 </li> On the Tools menu, click VBAProject Properties, and then click the General tab.</li>  Type the following code in the Conditional Compilation Arguments box: test = 1 </li> Click OK, and then run the Cond_Comp macro.</li></ol>

Because the conditional compilation constant "test" has a value of 1, a message box will display the message "test evaluates to True."

NOTE: If you want to specify more than one conditional compilation constant in the Conditional Compilation Arguments box, use a colon as a separator. For example, you would type the following into the Conditional Compilation Arguments box:

first = 1 : second = 0

<div class="references_section">