"Built-in Constants in Visual Basic for Applications" (WC0993)Last reviewed: August 28, 1997Article ID: Q112671 |
The information in this article applies to:
The following file is available for download from the Microsoft Software Library:
~ Wc0993.exe (size: 288903 bytes)For more information about downloading files from the Microsoft Software Library, please see the following article in the Microsoft Knowledge Base:
ARTICLE-ID: Q119591 TITLE : How to Obtain Microsoft Support Files from Online ServicesThe Application Note "Built-in Constants in Microsoft Visual Basic for Applications," (WC0993) provides a complete list of the constants that are included in Microsoft Office 97 programs and Microsoft Excel for Windows, versions 5.0 and 7.0, for use in Visual Basic for Applications. This Application Note contains the Microsoft Excel 97, Microsoft Access 97, Microsoft Office Binder 97, Microsoft Office 97, Microsoft Outlook 97, Microsoft PowerPoint 97, Visual Basic for Applications, Microsoft Word 97, and Microsoft Excel for Windows, versions 5.0 and 7.0, constants files. You can use these files in Visual Basic 3.0 or later projects. These files provide the definitions of these constants so that you can use the name of the constants in your Visual Basic modules. This Application Note also includes a Microsoft Excel 5.0 workbook file, Constants.xls, which includes lists of the constants that you can sort alphabetically or numerically. You can obtain this Application Note from the following sources:
THE TEXT OF WC0993
Microsoft(R) Technical Support Application Note (Text File) WC0993: BUILT-IN CONSTANTS IN MICROSOFT VISUAL BASIC(R) FOR APPLICATIONS Revision Date: 3/97The following information applies to Microsoft Office 97, Microsoft Excel for Windows(R), versions 5.0 and 7.0.
| INFORMATION PROVIDED IN THIS DOCUMENT AND ANY SOFTWARE THAT MAY | | ACCOMPANY THIS DOCUMENT (collectively referred to as an Application | | Note) IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER | | EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED | | WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR | | PURPOSE. The user assumes the entire risk as to the accuracy and | | the use of this Application Note. This Application Note may be | | copied and distributed subject to the following conditions: 1) All | | text must be copied without modification and all pages must be | | included; 2) If software is included, all files on the disk(s) must | | be copied without modification (the MS-DOS(R) utility diskcopy is | | appropriate for this purpose); 3) All components of this | | Application Note must be distributed together; and 4) This | | Application Note may not be distributed for profit. | | | | Copyright (C) 1994-1997 Microsoft Corporation. All Rights Reserved. | | Microsoft, MS-DOS, and Visual Basic are registered trademarks and | | Windows is a trademark of Microsoft Corporation. | |---------------------------------------------------------------------| OVERVIEWThis Application Note provides a complete list of the constants that are included in Microsoft Office 97 programs and Microsoft Excel for Windows, versions 5.0 and 7.0, for use in Visual Basic for Applications. The following files are included.
Filename Function ---------------------------------------------------------------------- Constant.xls Microsoft Excel for Windows, version 5.0, workbook that contains a complete list of all the built-in constants discussed in this document Ac97cons.bas Constants file for Microsoft Access 97 Bd97cons.bas Constants file for Microsoft Office Binder 97 for Windows Of97cons.bas Constants file for common Microsoft Office 97 for Windows features Ol97cons.bas Constants file for Microsoft Outlook 97 Pp97cons.bas Constants file for Microsoft PowerPoint 97 for Windows Vbacons.bas Constants file for common Visual Basic for Applications features Wd97cons.bas Constants file for Microsoft Word 97 for Windows Xl57cons.bas Constants file for Microsoft Excel for Windows, versions 5.0 and 7.0 Xl97cons.bas Constants file for Microsoft Excel 97 for WindowsYou can use the BAS files with Microsoft Visual Basic, versions 3.0 and later, or with any other program that supports Visual Basic or Visual Basic for Applications. Each BAS file contains a complete set of constants for a specific program. If you include the BAS file in a Visual Basic project, you can use constant names (instead of typing the values) in Visual Basic modules. Constant.xls is a Microsoft Excel 5.0 workbook that contains a complete, easy-to-use listing of all the constants in the BAS files.
WHAT ARE BUILT-IN CONSTANTS?When you create a procedure using Visual Basic for Applications, you can use constants to represent values that you use frequently. Using constants makes your code easier to read and maintain. For example, if you use the value 5.67 frequently, you can define a constant called MyValue as 5.67, and then use MyValue in your procedure everywhere you would use the value 5.67. Programs that can use Visual Basic for Applications include built-in constants that you can use in Visual Basic functions, methods, objects, and properties. The built-in constants for a specific program begin with the same two-letter prefix. The prefixes for the Office programs are listed in the following table.
Prefix Program -------------------------------------- xl Microsoft Excel wd Microsoft Word ac Microsoft Access pp Microsoft PowerPoint bind Microsoft Office Binder ol Microsoft Outlook mso Microsoft Office vb Visual BasicBuilt-in constants make it easier for you to create procedures in Office programs with Visual Basic and Visual Basic for Applications. For example, to change the orientation of an active Microsoft Excel worksheet to landscape or to check whether a cell is center-aligned, you could use the following Visual Basic code:
ActiveWorksheet.PageSetup.Orientation = xlLandscape If Range("A1").HorizontalAlignment = xlCenter Then MsgBox "Cell A1 is centered!" End IfThe built-in constants in this example (xlLandscape and xlCenter) are easier to remember than the numeric values they represent. Also, when you use built-in constants, it is easier to read the code and understand the function the code performs. For example, without built-in constants, you use the following code to change the orientation of an active Microsoft Excel worksheet to landscape or to check whether a cell is center-aligned:
ActiveWorksheet.PageSetup.Orientation = 2 If Range("A1").HorizontalAlignment = -4108 ThenNote that it is difficult to understand what these lines do without first knowing what the values 2 and -4108 represent.
Using Built-in Constants in Microsoft Office 97 ProgramsWhen you write a Visual Basic for Applications macro in a program, built- in constants that belong to that program are automatically available. For example, if you write a Visual Basic for Applications macro in Microsoft Excel, all of the Microsoft Excel constants are automatically available to the macro. However, when you use one program (for example, Microsoft Access) to control another program (for example, Microsoft Excel), and you use the constants for the program you want to control in the macro, you must add the constants to the controlling program. To make the constants available to a program, do either of the following:
Applications Project in a Microsoft Office 97 ProgramTo load the BAS file, use the following steps:
NOTE: Do not add both the Xl57cons.bas and the Xl97cons.bas files to your project. These files are similar but provide constants for different versions of Microsoft Excel.
Creating a Reference to the Program That You Want to ControlTo create a reference to the program, use the following steps:
USING BUILT-IN CONSTANTS IN MICROSOFT VISUAL BASICIf you write a Microsoft Visual Basic program that uses Automation to control an Office program, you may want to use the constants that belong to that program. Depending on the version of Microsoft Visual Basic you are using, use one of the following methods to make the constants available:
Loading a BAS File into a Code ModuleVisual Basic 5.0: To load the BAS file, use the following steps:
To load the BAS file, use the following steps:
To load the BAS file, use the following steps:
Creating a Reference to the Program That You Want to ControlVisual Basic 5.0: To create a reference to the program, use the following steps:
To create a reference to the program, use the following steps:
WHERE ARE BUILT-IN CONSTANTS LISTED IN MICROSOFT OFFICE PROGRAMS?The built-in constants that are available for a program are listed in Help or in the Object Browser. If you want to determine which built-in constants are available for a particular function, look them up in Help or use the Object Browser.
Looking Up a Built-in Constant in HelpMicrosoft Office 97 Programs:
Microsoft Excel 5.0
Looking Up Constants with the Object BrowserMicrosoft Office 97 Programs:
USING THE LISTS IN CONSTANT.XLSThe Constant.xls workbook contains a complete list of the built-in constants. These lists are designed so that you can easily sort them in alphabetical or numerical order. When you open the workbook in Microsoft Excel, the Contents worksheet is displayed. This worksheet contains basic information about the workbook, including instructions for moving between worksheets and information about library files.
|
Additional query words: xlconstants wdconstants acconstants ppconstants
© 1998 Microsoft Corporation. All rights reserved. Terms of Use. |