Article ID: 158472 - Last Review: November 23, 2006 - Revision: 2.4 XL97: No Automatic Type Coercion Between Variable TypesThis article was previously published under Q158472 On This PageSYMPTOMS
When you run a Visual Basic for Applications macro in Microsoft Excel 97,
you may receive the following error message:
Compile error: ByRef argument type mismatch CAUSE
This problem may occur if all of the following conditions are true:
WORKAROUNDMicrosoft 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 Microsoft Advisory Services. For more information, visit these Microsoft Web sites: Microsoft Certified Partners - https://partner.microsoft.com/global/30000104 (https://partner.microsoft.com/global/30000104) Microsoft Advisory Services - http://support.microsoft.com/gp/advisoryservice (http://support.microsoft.com/gp/advisoryservice) 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 (http://support.microsoft.com/default.aspx?scid=fh;en-us;cntactms) The following workarounds assume that you have a Visual Basic module that contains two macros: Method 1To prevent the problem from occurring, change how the second macro (Macro2) accepts values. In this case, change the second macro toMethod 2A second way to prevent the problem from occurring is to convert the value to an Integer as you pass it to the second macro using the CInt function.Method 3Another way to prevent the problem from occurring is to dimension a second variable in the first macro. This second variable should be of the same type as the value accepted by the second macro. The value from the array is copied into the second variable, which is then sent to the second macro. For example:STATUS
This behavior is by design of Microsoft Excel 97. The behavior demonstrated
by earlier versions of Microsoft Excel is actually incorrect.
MORE INFORMATION
In earlier versions of Microsoft Excel, a value can be passed from an
element in an array of type Variant in one function, to a variable of
another type in another function. This is called "automatic type coercion",
since the value passed between functions is being forced (coerced) to
switch from one type (Variant) to another type (Integer, for example).
In Microsoft Excel 97, automatic type coercion is not supported. Because of this, you may need to ensure that your macros consistently use the same types of variables when passing values from macro to macro. | Article Translations
|

Back to the top
