ID: Q112671
The information in this article applies to:
The 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.
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 Services
Microsoft(R) Technical Support Application Note (Text File)
WC0993: BUILT-IN CONSTANTS IN MICROSOFT VISUAL BASIC(R)
FOR APPLICATIONS
Revision Date: 3/97
The 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. |
|---------------------------------------------------------------------|
This 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 Windows
You 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.
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 Basic
Built-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 If
The 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 Then
Note that it is difficult to understand what these lines do without first
knowing what the values 2 and -4108 represent.
When 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:
To load the BAS file, use the following steps:
1. In the Visual Basic Editor (press ALT+F11), click Module on the Insert
menu to create a new module.
2. On the Insert menu, click File. In the Insert File dialog box, open the
folder that contains the BAS file you want to add. In the Files of Type
list, click Basic Files (*.bas).
3. Click the BAS file you want, and then click Open.
It may take a few seconds for the Visual Basic Editor to load the BAS file. After you load the file, the module contains many Global Const statements. Each statement declares a single constant.
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.
To create a reference to the program, use the following steps:
1. In the Visual Basic Editor (press ALT+F11), click References on the
Tools menu.
2. In the Available References list, click to select the check box to the
left of the object library that contains the constants that you want to
use. For example, if you want to use constants that belong to Microsoft
Word 97, click to select the check box to the left of Microsoft Word
8.0 Object Library.
Note In this dialog box, "8.0" and "97" are synonymous. Therefore, the
Microsoft Excel 8.0 Object Library provides the constants for Microsoft
Excel 97.
3. After you finish selecting the libraries you want to use, click OK.
You can now use the constants that belong to the referenced programs in the Visual Basic for Applications macro.
If 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:
NOTE: This method works for any version of Microsoft Visual Basic.
Visual Basic 5.0:
To load the BAS file, use the following steps:
1. In the development environment, click Add Module on the Project menu.
On the New tab, click Module, and then click Open.
This step adds an empty code module to the project.
2. Verify that the module is the active window. On the Edit menu, click
Insert File.
3. In the List Files of Type box, click Basic Files (*.bas).
4. Click the BAS file and click Open.
Visual Basic 4.0:
To load the BAS file, use the following steps:
1. In the development environment, click Module on the Insert menu.
This adds an empty code module to your project.
2. Verify that the module is the active window. On the Insert menu, click
File.
3. In the List Files of Type box, click Basic Files (*.bas).
4. Select the BAS file and click Open.
Visual Basic 3.0:
To load the BAS file, use the following steps:
1. In the development environment, click New Module on the File menu.
This step adds an empty code module to the project.
2. Verify that the module is the active window. On the File menu click
Load Text.
3. In the List Files of Type box, click Basic Files (*.bas).
4. Click the BAS file, and click Replace. If you want to add the BAS file
to a module that contains other code or declarations, click Merge.
Visual Basic 5.0:
To create a reference to the program, use the following steps:
1. On the View menu, click Project Explorer.
2. On the Project menu, click References. If the References command
appears dimmed, the project is running. To make the command available,
end program execution.
3. In the Available References list, select the check box to the left of
the object library that contains the constants you want to access. For
example, if you want to access constants that belong to Microsoft Word
97, select the check box to the left of Microsoft Word 8.0 Object
Library.
Note In this dialog box, "8.0" and "97" are synonymous. Therefore, the
Microsoft Excel 8.0 Object Library provides the constants for Microsoft
Excel 97.
4. After you finish selecting the libraries you want to use, click OK.
Visual Basic 4.0:
To create a reference to the program, use the following steps:
1. On the View menu, click Project.
2. On the Tools menu, click References. If the References command appears
dimmed, the project is running. To make the command available, end
program execution.
3. In the Available References list, click to select the check box to the
left of the object library that contains the constants you want to
access. For example, if you want to access constants that belong to
Microsoft Word 97, click to select the check box to the left of
Microsoft Word 8.0 Object Library.
Note In this dialog box, "8.0" and "97" are synonymous. Therefore, the
Microsoft Excel 8.0 Object Library provides the constants for Microsoft
Excel 97.
4. After you finish selecting the libraries you want to use, click OK.
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.
Microsoft Office 97 Programs:
1. Start the Visual Basic Editor (press ALT+F11).
2. On the Standard toolbar, click Office Assistant.
3. Type the name of the function you want to view in the box and click
Search.
4. In the list of topics, click the button for the function you want to
view.
Microsoft Excel 7.0:
1. In a Visual Basic module, click Microsoft Excel Help Topics on the Help
menu.
2. Click the Index tab.
3. Type the name of the function you want to view in the box and click
Display.
Any built-in constants that are available to the function appear in
bold in the Help topic text for that function. For example, the
ConvertFormula method uses the following six built-in constants. These
constants are listed in bold, for example: xlA1, xlR1C1, xlAbsolute,
xlAbsRowRelColumn, xlRelRowAbsColumn, and xlRelative.
Microsoft Excel 5.0
1. On the Help menu, click Contents.
2. In the Microsoft Excel Help Contents window, click Programming with
Visual Basic.
3. In the Visual Basic Reference window, click Search and click the Index
tab.
4. Type the name of the function you want to view in the box and click
Display.
Any built-in constants that are available to the function appear in
bold in the Help topic text for that function. For example, the
ConvertFormula method uses the following six built-in constants. These
constants are listed in bold, for example: xlA1, xlR1C1, xlAbsolute,
xlAbsRowRelColumn, xlRelRowAbsColumn, and xlRelative.
Microsoft Office 97 Programs:
1. Start the Visual Basic Editor (press ALT+F11).
2. On the View menu, click Object Browser.
3. In the Project/Library box, click the library that contains the
constants you want to view (for example, click Excel).
Note Click <All Libraries> to browse through a list of all libraries.
4. In the Classes list, click Constants.
The constants are listed in the Members of 'Constants' box.
Microsoft Excel 5.0 and 7.0:
1. In a Visual Basic module, click Object Browser on the View menu.
2. In the Libraries/Workbooks list box, click Excel.
3. In the Objects/Modules list, click Constants.
A list of the built-in constants appears in the Methods/Properties
list.
For a complete list of the built-in constants, see the Constant.xls file
that is included with this Application Note.
The 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 msoconstants bindconstants olconstants vbconstants
Keywords : kbfile kbprg
Version : WINDOWS:7.0,97
Platform : WINDOWS
Issue type : kbinfo
Last Reviewed: August 28, 1998