Inserting text into protected field/textbox

M

Mike

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
 
D

Doug Robbins - Word MVP

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
 
M

Mike

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
 
D

Doug Robbins - Word MVP

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
 
M

Mike

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
 
D

Doug Robbins - Word MVP

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 said:
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
 
M

Mike

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
 
D

Doug Robbins - Word MVP

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
 
M

Mike

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













- Tekst uit oorspronkelijk bericht weergeven -

Thanks for the solution!

Mike
 

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