string parameters are too long?

C

clara

Hi all,

I define some place holders ( like <<<place holder>>> in a doc file and to
replace the place holders with some texts from an excel file. when text
length become long then I am told "string parameters are too long", how long
is too long and how can I circumvent it ?

Clara
 
D

Doug Robbins - Word MVP

Probably 255 characters.

You may need to do something like:

' FILIT Macro
' Macro created 05/09/98 by Doug Robbins to insert long string into
FormField
'
Dim FillText as String, FirstBit as String
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
 
C

clara

Hi Doug Robbins,

254 is the max len allowed. Could you elaborate your code a little further ,
especially the line marked with *

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


Clara

thank you so much for your help
 
D

Doug Robbins - Word MVP

The macro that I posted was a workaround for the similar issue of their
being a limitation on the length of the information that can be inserted by
the use of vba into a formfield in a document that is protected for forms.

If you need assistance, you should show us the code that you are trying to
use to insert information into what you refer to as "place holders".

--
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
 
C

clara

Good Morning Doug,

The following is my code snippet. The general meaning: get the text from
range(details), then replace the <<<Detail>>> in my word doc with the text.
During the replacement, the length of the text is limited below 254, I hope
replacement include all the characters when the text length is over 254.

Detail =Range(Details).Value

With appWrd.Selection.Find
.text = "<<<Detail>>>"
With .Replacement
.text = ActionDetail
End With
.Execute Format:=True, Replace:=wdReplaceAll
End With

thank you so much for your help


Clara
 
D

Doug Robbins - Word MVP

Use the following construction:

Dim Detail as Range
Set Detail = 'Range that contains the text that you want to insert
Selection.HomeKey wdStory
Selection.Find.ClearFormatting
With Selection.Find
Do While .Execute(Findtext:="<<<Detail>>>", Forward:=True,
MatchWildcards:=False, Wrap:=wdFindStop) = True
Selection.Range.FormattedText = Detail.FormattedText
Loop
End With


--
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top