Hi,

I have a letter with fields, which is protected. For the content of
the letter, I want to use variable text.

I made a userform which can select several textlines, which then are
to be inserted in the letter.

The textlines are in separate word-files.

What I want to do is insert a or multiple word-file(s) into a field.

If I unprotect the letter, then the field is overwritten. Is it
possible to insert the text, which is in another file into a protected
field?

Or insert the text and put a field on top of the text?

Thanks, Mike

Re: Inserting text into protected field/textbox by Doug

Doug
Sun Feb 11 22:28:42 CST 2007

If you use the .Result of the formfield, you can have insert text into it
without unprotecting the document.

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

"Mike" <Mike_Gator14@yahoo.com> wrote in message
news:1171231735.000960.313480@a34g2000cwb.googlegroups.com...
> Hi,
>
> I have a letter with fields, which is protected. For the content of
> the letter, I want to use variable text.
>
> I made a userform which can select several textlines, which then are
> to be inserted in the letter.
>
> The textlines are in separate word-files.
>
> What I want to do is insert a or multiple word-file(s) into a field.
>
> If I unprotect the letter, then the field is overwritten. Is it
> possible to insert the text, which is in another file into a protected
> field?
>
> Or insert the text and put a field on top of the text?
>
> Thanks, Mike
>



Re: Inserting text into protected field/textbox by Mike

Mike
Mon Feb 12 02:43:40 CST 2007

On 12 feb, 05:28, "Doug Robbins - Word MVP" <d...@REMOVECAPSmvps.org>
wrote:
> If you use the .Result of the formfield, you can have insert text into it
> without unprotecting the document.
>

Can you help me a little bit more? I now use:

myName = formuliernaam.lsttekstblokselectie.List(x) & ".doc"
ActiveDocument.Bookmarks("BInhoud").Select
Selection.InsertFile FileName:=myName, Range:="", _
ConfirmConversions:=False, Link:=False, Attachment:=False

where x is the name of a wordfile, which has to be chosen in a
userform listbox.

If I use:

myName = formuliernaam.lsttekstblokselectie.List(x) & ".doc"
Set MyRange = ActiveDocument.Fields(15).Result
MyRange.InsertFile FileName:=myName, Range:="", _
ConfirmConversions:=False, Link:=False, Attachment:=False

I get an error.

Or is it not possible to use the InsertFile method with Fields.result?

Thanks, Mike



Re: Inserting text into protected field/textbox by Doug

Doug
Mon Feb 12 03:30:59 CST 2007

I am not sure what you have in document x, but what you will need to do is
use code to open that document, then set a range object (say myrange) to the
range of that document then use :

ActiveDocument.FormFields("[bookmarknameofformfield]").Result = myrange



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

"Mike" <Mike_Gator14@yahoo.com> wrote in message
news:1171269820.660532.308200@h3g2000cwc.googlegroups.com...
> On 12 feb, 05:28, "Doug Robbins - Word MVP" <d...@REMOVECAPSmvps.org>
> wrote:
>> If you use the .Result of the formfield, you can have insert text into it
>> without unprotecting the document.
>>
>
> Can you help me a little bit more? I now use:
>
> myName = formuliernaam.lsttekstblokselectie.List(x) & ".doc"
> ActiveDocument.Bookmarks("BInhoud").Select
> Selection.InsertFile FileName:=myName, Range:="", _
> ConfirmConversions:=False, Link:=False, Attachment:=False
>
> where x is the name of a wordfile, which has to be chosen in a
> userform listbox.
>
> If I use:
>
> myName = formuliernaam.lsttekstblokselectie.List(x) & ".doc"
> Set MyRange = ActiveDocument.Fields(15).Result
> MyRange.InsertFile FileName:=myName, Range:="", _
> ConfirmConversions:=False, Link:=False, Attachment:=False
>
> I get an error.
>
> Or is it not possible to use the InsertFile method with Fields.result?
>
> Thanks, Mike
>
>



Re: Inserting text into protected field/textbox by Mike

Mike
Mon Feb 12 04:49:17 CST 2007

On 12 feb, 10:30, "Doug Robbins - Word MVP" <d...@REMOVECAPSmvps.org>
wrote:
> I am not sure what you have in document x, but what you will need to do is
> use code to open that document, then set a range object (say myrange) to the
> range of that document then use :
>
> ActiveDocument.FormFields("[bookmarknameofformfield]").Result = myrange
>

Thanks again for your reply!

Document x is just a word-doc with a line or several lines of text.
With the word-docs I want to 'build' the letter.

So f.i. I have:

01.doc
02.doc
03.doc

and I want only the lines within 02.doc and 03.doc inserted in my
letter.

Now I use a loop to insertfile both files, but if I understand
correctly I have to follow these steps:

1. open 02.doc
2. set a range to the line in the 02.doc
3. go to the letter
4. insert the range in the field
5. repeat the same for 03.doc

Is this correct?

And how do I open and set the range in 02.doc?

Set objDoc = objWord.Documents.Open("02.doc")
Set MyRange = ....

Thanks, Mike


Re: Inserting text into protected field/textbox by Doug

Doug
Mon Feb 12 06:14:11 CST 2007

If it's the whole of the document, it would be

Set MyRange = objDoc.Range

If it is not the whole document, you would need to bookmark the part of it
that you want and then use

Set MyRange = objDoc.Bookmarks("bookmarkname").Range

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

"Mike" <Mike_Gator14@yahoo.com> wrote in message
news:1171277357.209555.46580@v45g2000cwv.googlegroups.com...
> On 12 feb, 10:30, "Doug Robbins - Word MVP" <d...@REMOVECAPSmvps.org>
> wrote:
>> I am not sure what you have in document x, but what you will need to do
>> is
>> use code to open that document, then set a range object (say myrange) to
>> the
>> range of that document then use :
>>
>> ActiveDocument.FormFields("[bookmarknameofformfield]").Result = myrange
>>
>
> Thanks again for your reply!
>
> Document x is just a word-doc with a line or several lines of text.
> With the word-docs I want to 'build' the letter.
>
> So f.i. I have:
>
> 01.doc
> 02.doc
> 03.doc
>
> and I want only the lines within 02.doc and 03.doc inserted in my
> letter.
>
> Now I use a loop to insertfile both files, but if I understand
> correctly I have to follow these steps:
>
> 1. open 02.doc
> 2. set a range to the line in the 02.doc
> 3. go to the letter
> 4. insert the range in the field
> 5. repeat the same for 03.doc
>
> Is this correct?
>
> And how do I open and set the range in 02.doc?
>
> Set objDoc = objWord.Documents.Open("02.doc")
> Set MyRange = ....
>
> Thanks, Mike
>



Re: Inserting text into protected field/textbox by Mike

Mike
Mon Feb 12 06:53:19 CST 2007

On 12 feb, 13:14, "Doug Robbins - Word MVP" <d...@REMOVECAPSmvps.org>
wrote:
> If it's the whole of the document, it would be
>
> Set MyRange = objDoc.Range
>
> If it is not the whole document, you would need to bookmark the part of it
> that you want and then use
>
> Set MyRange = objDoc.Bookmarks("bookmarkname").Range
>

Getting close I think.... :-)

I tried to do it like this:

For x = formuliernaam.lsttekstblokselectie.ListCount - 1 To 0 Step -1
formuliernaam.lsttekstblokselectie.ListIndex = x
myName = formuliernaam.lsttekstblokselectie.List(x) & ".doc"
Documents.Open (formuliernaam.lsttekstblokselectie.List(x) &
".doc")
Set MyRange = ActiveDocument.Paragraphs(1).Range
If x = formuliernaam.lsttekstblokselectie.ListCount - 1 Then
Str = MyRange
Else
Str = Str & Chr$(13) & MyRange
End If
Documents(2).Select
Documents(formuliernaam.lsttekstblokselectie.List(x) &
".doc").Close Savechanges:=wdDoNotSaveChanges
Next x
ActiveDocument.FormFields(15).Result = Str

I get "String too long" error if I use more than 3 lines of text...
The field is set to unlimited text.

Is it possible to:

1. open the word.doc (f.i. 02.doc)
2. Set the range and put it in the field
3. open the second Word-doc (f.i. 03.doc)
4. put this in the field AFTER the previous inserted text?

Thanks, Mike


Re: Inserting text into protected field/textbox by Doug

Doug
Mon Feb 12 14:41:09 CST 2007

There is a 255 character limit on the amount of text that can be inserted
into the .Result of a formfield.

Here is a workaround (that may be going around in circles if I recall where
you started)

' 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

"Mike" <Mike_Gator14@yahoo.com> wrote in message
news:1171284799.559212.281240@l53g2000cwa.googlegroups.com...
> On 12 feb, 13:14, "Doug Robbins - Word MVP" <d...@REMOVECAPSmvps.org>
> wrote:
>> If it's the whole of the document, it would be
>>
>> Set MyRange = objDoc.Range
>>
>> If it is not the whole document, you would need to bookmark the part of
>> it
>> that you want and then use
>>
>> Set MyRange = objDoc.Bookmarks("bookmarkname").Range
>>
>
> Getting close I think.... :-)
>
> I tried to do it like this:
>
> For x = formuliernaam.lsttekstblokselectie.ListCount - 1 To 0 Step -1
> formuliernaam.lsttekstblokselectie.ListIndex = x
> myName = formuliernaam.lsttekstblokselectie.List(x) & ".doc"
> Documents.Open (formuliernaam.lsttekstblokselectie.List(x) &
> ".doc")
> Set MyRange = ActiveDocument.Paragraphs(1).Range
> If x = formuliernaam.lsttekstblokselectie.ListCount - 1 Then
> Str = MyRange
> Else
> Str = Str & Chr$(13) & MyRange
> End If
> Documents(2).Select
> Documents(formuliernaam.lsttekstblokselectie.List(x) &
> ".doc").Close Savechanges:=wdDoNotSaveChanges
> Next x
> ActiveDocument.FormFields(15).Result = Str
>
> I get "String too long" error if I use more than 3 lines of text...
> The field is set to unlimited text.
>
> Is it possible to:
>
> 1. open the word.doc (f.i. 02.doc)
> 2. Set the range and put it in the field
> 3. open the second Word-doc (f.i. 03.doc)
> 4. put this in the field AFTER the previous inserted text?
>
> Thanks, Mike
>



Re: Inserting text into protected field/textbox by Mike

Mike
Tue Feb 13 09:06:39 CST 2007

On 12 feb, 21:41, "Doug Robbins - Word MVP" <d...@REMOVECAPSmvps.org>
wrote:
> There is a 255 character limit on the amount of text that can be inserted
> into the .Result of a formfield.
>
> Here is a workaround (that may be going around in circles if I recall where
> you started)
>
> ' 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
>
> "Mike" <Mike_Gato...@yahoo.com> wrote in message
>
> news:1171284799.559212.281240@l53g2000cwa.googlegroups.com...
>
>
>
> > On 12 feb, 13:14, "Doug Robbins - Word MVP" <d...@REMOVECAPSmvps.org>
> > wrote:
> >> If it's the whole of the document, it would be
>
> >> Set MyRange = objDoc.Range
>
> >> If it is not the whole document, you would need to bookmark the part of
> >> it
> >> that you want and then use
>
> >> Set MyRange = objDoc.Bookmarks("bookmarkname").Range
>
> > Getting close I think.... :-)
>
> > I tried to do it like this:
>
> > For x = formuliernaam.lsttekstblokselectie.ListCount - 1 To 0 Step -1
> > formuliernaam.lsttekstblokselectie.ListIndex = x
> > myName = formuliernaam.lsttekstblokselectie.List(x) & ".doc"
> > Documents.Open (formuliernaam.lsttekstblokselectie.List(x) &
> > ".doc")
> > Set MyRange = ActiveDocument.Paragraphs(1).Range
> > If x = formuliernaam.lsttekstblokselectie.ListCount - 1 Then
> > Str = MyRange
> > Else
> > Str = Str & Chr$(13) & MyRange
> > End If
> > Documents(2).Select
> > Documents(formuliernaam.lsttekstblokselectie.List(x) &
> > ".doc").Close Savechanges:=wdDoNotSaveChanges
> > Next x
> > ActiveDocument.FormFields(15).Result = Str
>
> > I get "String too long" error if I use more than 3 lines of text...
> > The field is set to unlimited text.
>
> > Is it possible to:
>
> > 1. open the word.doc (f.i. 02.doc)
> > 2. Set the range and put it in the field
> > 3. open the second Word-doc (f.i. 03.doc)
> > 4. put this in the field AFTER the previous inserted text?
>
> > Thanks, Mike- Tekst uit oorspronkelijk bericht niet weergeven -
>
> - Tekst uit oorspronkelijk bericht weergeven -

Thanks for the solution!

Mike