Re: String too long error by Doug
Doug
Wed Jun 28 13:08:32 CDT 2006
' Macro created 05/09/98 by Doug Robbins to insert long string into
FormField
'
FillText = "Your long string"
LenFillText = Len(FillText)
FirstBit = Left(FillText, 255)
If LenFillText > 255 Then
SecondBit = Mid(FillText, 256, LenFillText - 255)
ActiveDocument.FormFields("Text1").Result = FirstBit
Selection.GoTo What:=wdGoToBookmark, Name:="Text1"
ActiveDocument.Unprotect
Selection.InsertAfter SecondBit
ActiveDocument.Protect Type:=wdAllowOnlyFormFields, NoReset:=True
Else
ActiveDocument.FormFields("Text1").Result = FillText
End If
--
Hope this helps.
Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.
Doug Robbins - Word MVP
"KateP" <KateP@discussions.microsoft.com> wrote in message
news:7B226915-C185-4FB7-B9E6-441D46EBD775@microsoft.com...
> Hi Helmut
>
> Many thanks for your post. You say "putting that amount of characters in
> a
> formfield doesn't make much sense", please could you advise what would be
> a
> better way of doing this, I've been really struggling..
>
> Thank you in advance.
>
> Kate
>
> "Helmut Weber" wrote:
>
>> Hi Kate,
>>
>> the result is limited to 256 characters,
>> as far as I see,
>> and even putting that amount of characters
>> in a formfield doesn't make much sense to me.
>>
>> Have a look at this sample:
>>
>> Sub Test09978()
>> Dim s As String
>> s = "We the People of the United States, in Order to form " & _
>> "a more perfect Union, establish Justice, insure domestic " & _
>> "Tranquility, provide for the common defence, promote the " & _
>> "general Welfare, and secure the Blessings of Liberty to " & _
>> "ourselves and our Posterity, do ordain and establish this " & _
>> "Constitution for the United States of America."
>>
>> s = Left(s, 251) & "[...]"
>> ActiveDocument.FormFields(1).Result = s
>> End Sub
>>
>> You may use:
>>
>> RaisedBy = Left(RaisedBy, 251) & "[...]"
>> worddoc.FormFields(1).result = RaisedBy
>>
>>
>> --
>> Greetings from Bavaria, Germany
>>
>> Helmut Weber, MVP WordVBA
>>
>> Win XP, Office 2003
>> "red.sys" & Chr$(64) & "t-online.de"
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>