XL98: Conditional Compilation Code Lost With 5.0/95 Format (186174)



The information in this article applies to:

  • Microsoft Excel 98 Macintosh Edition

This article was previously published under Q186174

SYMPTOMS

If you use the Save As command on the File menu to save a document in Microsoft Excel 5.0/95 Workbook format, you lose any Conditional Compilation directives in your Visual Basic for Applications code.

NOTE: When saving your document in Microsoft Excel 5.0/95 format, you are not warned that your code will be lost.

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 document in the Microsoft Excel 5.0/95 Workbook format, you must open the file in Microsoft Excel 98 and retype the Conditional Compilation directives.

If you have not saved your file in the Microsoft Excel 5.0/95 Workbook format and you want to preserve your Conditional Compilation directives, comment out the Conditional Compilation directives and save the file in the Microsoft Excel 5.0/95 Workbook format.

MORE INFORMATION

You can use Conditional Compilation directives (for example, #IF...THEN...#ELSE) to run selective blocks of code. Typically, this is 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. This includes, but is not limited to, the implied warranties of merchantability or fitness for a particular purpose. This article assumes that you are familiar with the programming language that is being demonstrated and with the tools that are used to create and to debug procedures. Microsoft support engineers 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 requirements. The following macro provides an example of using conditional compilation:

  1. Save and close any open workbooks, and then open a new workbook.
  2. Start the Visual Basic Editor by pressing OPTION+F11.
  3. On the Insert menu, click Module.
  4. In the module, type the following code:
          #Const test = 1
    
          Sub Cond_Comp()
    
              #If test Then
                  MsgBox "test evaluates to True"
    
              #Else
                  MsgBox "test evaluates to False"
    
              #End If
    
          End Sub
    						
  5. Run the Cond_Comp macro.

    Because the conditional compilation constant "test" has a value of one, a message box will display the message "test evaluates to True".
  6. Change the first line of code in the module to:
          #Const test = 0
  7. Run the Cond_Comp macro.

    Because the conditional compilation constant "test" has a value of zero, a message box will display the message "test evaluates to False."
Conditional compilation constants can also be specified in the Project Properties dialog box instead of in a module. To use this technique in the previous example, follow these steps:

  1. Comment out the first line in the module so that it looks like the following:
          '#Const test = 0
  2. On the Tools menu, click VBAProject Properties, and click the General tab.
  3. In the Conditional Compilation Arguments box, type the following:
          test = 1
  4. Click OK.
  5. Run the Cond_Comp macro.

    Because the conditional compilation constant "test" has a value of 1, a message box displays 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
				

REFERENCES

For more information about Conditional Compilation, from the Visual Basic Editor, click the Office Assistant, type conditional compilation click Search, and then click to view "Understanding Conditional Compilation."

NOTE: If the Assistant is hidden, click the Office Assistant button on the Standard toolbar. If Microsoft Help is not installed on your computer, please see the following article in the Microsoft Knowledge Base:

179216 OFF98: How to Use the Microsoft Office Installer Program


Modification Type:MajorLast Reviewed:6/17/2005
Keywords:kbprb kbProgramming KB186174