The information in this article applies to:
SYMPTOMSWhen you run a Visual Basic for Applications macro in Microsoft Excel 97, you may receive the following error message:
CAUSE
This behavior will occur if the following conditions are all true:
NOTE: This behavior is a change from earlier versions of Microsoft Excel. 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 the Microsoft fee-based consulting line at (800) 936-5200. For more information about the support options available from Microsoft, please see the following page on the World Wide Web: http://www.microsoft.com/support/supportnet/overview/overview.aspThe following workarounds assume that you created a Visual Basic module with the following code:
The array MyArray is initialized at the module level; so, it is available
to all macros within the module. The first macro redimensions the array,
and then passes an element of the array to the second macro. The second
macro refers to the element in the array by reference, not by value.
NOTE: If you run Macro1, you receive the error message. To prevent the problem from occurring, use either of the following methods. Method 1In the second macro, use the keyword ByVal to force the macro to refer to the element in the array by value, not by reference. For example, change the second macro to the following:
Method 2Use an intermediate variable to pass the value from one macro to the other. For example, change the first macro to the following:
By using an intermediate variable to send the value to the second macro,
you prevent the second macro from referring to locations within the array's
memory. You can then redimension the array without receiving an error
message.
MORE INFORMATION
When you pass a variable from one macro to another macro in Microsoft
Excel, the actual value of the variable is not passed between macros.
Instead, a reference to the value's location in memory is passed; this is
called passing a value by reference. You can also pass a value by value by
using the keyword ByVal.
Additional query words: XL97
Keywords : kberrmsg kbprg kbdta kbdtacode KbVBA xlvbmigrate |
Last Reviewed: November 9, 1999 © 2000 Microsoft Corporation. All rights reserved. Terms of Use. |