WD97: ErrMsg If AutoText String Exceeds 255 CharactersLast reviewed: August 27, 1997Article ID: Q171129 |
The information in this article applies to:
SYMPTOMSYou may receive the following Visual Basic for Applications error when you use the AutoTextEntries property to create AutoText entries:
Run-time error '5854': String parameter too long. CAUSEThis error message occurs when the text string is longer than 255 characters.
WORKAROUNDMicrosoft provides examples of Visual Basic for Applications procedures 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. The Visual Basic procedures in this article are provided 'as is' and Microsoft does not guarantee that they can be used in all situations. While Microsoft support engineers can help explain the functionality of a particular macro, they will not modify these examples to provide added functionality, nor will they help you construct macros to meet your specific needs. If you have limited programming experience, you may want to consult one of the Microsoft Solution Providers. Solution Providers offer a wide range of fee-based services, including creating custom macros. For more information about Microsoft Solution Providers, call Microsoft Customer Information Service at (800) 426-9400. To work around this problem, modify the macro to insert the text string into the document, select it, add the selection as an AutoText entry, and then remove the text string. The following sample Visual Basic for Application macro demonstrates this procedure:
Sub setautotextentry() Dim autoName As String Dim autoEntry As String Dim sNewEntry As Object ' Sample AutoText Entry Name. autoName = "ExampleAutoTextEntryName" ' Sample AutoText Entry Text of 1000 characters. autoEntry = String(1000, "A") On Error GoTo errHandler If Len(autoEntry) < 255 Then ' If the length of the text is 255 characters or fewer, ' add it as a new AutoText Entry. ActiveDocument.Selection.Range.Collapse Set sNewEntry = NormalTemplate.AutoTextEntries.Add _ (Name:=autoName, Range:=Selection.Range) sNewEntry.Value = autoEntry Else ' If the length of the text is greater than 255 characters, ' insert it into the active document and add it ' as a new AutoText Entry. ActiveDocument.Selection.Range.Collapse ActiveDocument.Selection.Text = autoEntry NormalTemplate.AutoTextEntries.Add _ Name:=autoName, Range:=Selection.Range ActiveDocument.Selection.Range.Delete End If errHandler: ' This line must be left aligned! End Sub |
Additional query words: 8.0 8.0 vba vbe vb
© 1998 Microsoft Corporation. All rights reserved. Terms of Use. |