Microsoft KB Archive/213809

= XL2000: Cannot Use xlConstant Names in Variables in Visual Basic Code =

Article ID: 213809

Article Last Modified on 11/23/2006

-

APPLIES TO


 * Microsoft Excel 2000 Standard Edition

-



This article was previously published under Q213809





SYMPTOMS
When you attempt to use Microsoft Excel 2000 constant names to set properties in Visual Basic code, you may receive the following error message:

Type mismatch

For example, if you want to show the Open dialog box, and you use the following sample code (where the Excel constant is represented by a variable) Sub Open_Box Dim var As String var = "xlDialogOpen" Application.Dialogs(var).show End Sub you receive the "type mismatch" error message.



CAUSE
This behavior occurs because Excel constant names are not actually handled as strings, but rather as the values that they represent.



WORKAROUND
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

To set the Excel constant values to variables in Visual Basic, an integer variable must be set to the value that the constant name represents, as in the following sample code: Sub Open_Box Dim var As Integer var = xlDialogOpen ' Note the absence of quotation marks. Application.Dialogs(var).Show End Sub When this type of code is run, the Open dialog box appears as expected.

Keywords: kbdtacode kberrmsg kbprb kbprogramming KB213809

-

[mailto:TECHNET@MICROSOFT.COM Send feedback to Microsoft]

© Microsoft Corporation. All rights reserved.