PDA

View Full Version : Updating AutoTextEntries - get run-time error '5854' String parameter too long.



brett_x
07-01-2016, 11:55 AM
I'm working on a project (in Word 2011, Mac, but hopefully that isn't the issue) where I need to manipulate AutoText entries. I need to save what is in a Userform text field as an updated version of an existing Autotext entry.

When the Userform TextBox is around 256 characters, I get a run-time error '5854' 'String parameter too long'. The line it calls out is:


NormalTemplate.AutoTextEntries("autoTextEntry1").Value = TextBox1.Value

Since Autotext entries are not limited to 256 characters, it doesn't seem to be an autotext limitation. So is there a way around this? I've seen many posts about splitting up long strings for other purposes, and I'd really like to avoid that if possible (and practical, of course).

Thanks in advance.
- Brett

gmaxey
07-01-2016, 07:21 PM
The autotext value property has a limit of 255 period. You can fudge and create a new one:


Sub ScratchMacro()
'A basic Word macro coded by Greg Maxey
Dim oAT As AutoTextEntry
Dim strText As String
Dim oDoc As Document, oDocTemp As Document
Set oAT = ThisDocument.AttachedTemplate.AutoTextEntries("Test")
strText = String(5000, "x") 'Your userform value
On Error Resume Next
oAT.Value = strText
If Err.Number <> 0 Then
Set oDoc = ActiveDocument
Set oDocTemp = Documents.Add(, , , False)
oDoc.Activate
oDocTemp.Range.Text = strText
ThisDocument.AttachedTemplate.AutoTextEntries.Add oAT.Name, oDocTemp.Range
oDocTemp.Close wdDoNotSaveChanges
End If
lbl_Exit:
Exit Sub
End Sub

brett_x
07-05-2016, 06:30 AM
The autotext value property has a limit of 255 period.

That is interesting. I didn't think that was a limitation because you can save autotext that is much longer than that. But of course, you are right that I can't access beyond 255 characters of it though VBA. I'm guessing this is a VBA limitation(?).

I'm going to be working the solution you provided when I get a chance. I'll follow up with further questions and/or my findings.

Thank you for your help.