Article ID: 213841 - View products that this article applies to.
This article was previously published under Q213841
For a Microsoft Excel 97 and earlier and Microsoft Excel 98 and earlier version of this article, see 105416
If you use a Microsoft Visual Basic for Applications procedure to pass a string that is greater than 255 characters in length to an object, such as a text box, Microsoft Excel may truncate the string to 255 characters or may fail to enter the string in the text box.
This behavior also commonly occurs when you attempt to pass more than 255 characters to the Connection or SourceData argument of the PivotTableWizard. When you attempt to do this, you receive the following error message:
NOTE: This behavior affects other Excel objects.
Run-time error '1004':
PivotTableWizard method of worksheet class failed
In Microsoft Excel 7.0 or earlier, this behavior occurs because the character limit per cell is 255 characters. As a result, strings greater than 255 characters in length that are passed from a Visual Basic procedure to any Microsoft Excel function or object are truncated to 255 characters.
In Excel, you can use more than 255 characters in a cell; however, when you pass strings that are greater than 255 characters in length from a Visual Basic procedure, Excel uses the same design that earlier versions use.
This limit applies to all strings that you pass from a Visual Basic procedure to an Excel sheet; it is not exclusive to information you pass to cells. For example, if you pass a text string that is longer than 255 characters to a text box on a worksheet or a dialog sheet, Excel truncates the text even though a text box can hold up to 10,240 characters.
Microsoft provides programming examples for illustration only, without warranty either expressed or implied. This includes, but is not limited to, the implied warranties of merchantability or fitness for a particular purpose. This article assumes that you are familiar with the programming language that is being demonstrated and with the tools that are used to create and to debug procedures. Microsoft support engineers 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 requirements. To insert more than 255 characters in a text box, use the Characters property to insert multiple string variables. Examples 1 and 2 contain macros that use the Characters property to do this.
To pass more than 255 characters to the Connection or SourceData arguments, convert the long string to an array. To see a sample macro that uses a user-defined function, see Example 3.
Example 1In the following example, the character length of each variable is 100. Each Insert method inserts another string at the position at the end of the previous string.
Example 2This example utilizes a looping structure to insert a long string into a text box.
Example 3: Converting Text to an Array for PivotTableWizardThis example creates a PivotTable from a Microsoft Access database. It converts the value for the Connection argument to an array using the StringToArray function because the string is greater than 255 characters in length.
For more information about getting help with Visual Basic for Applications, click the following article number to view the article in the Microsoft Knowledge Base:
(http://support.microsoft.com/kb/226118/ )List of resources that are available to help you learn Visual Basic for Applications programming
Article ID: 213841 - Last Review: January 24, 2007 - Revision: 4.5
Contact us for more help