Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Word / Programming / February 2007

Tip: Looking for answers? Try searching our database.

Inserting text into protected field/textbox

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Mike - 11 Feb 2007 22:08 GMT
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
Doug Robbins - Word MVP - 12 Feb 2007 04:28 GMT
If you use the .Result of the formfield, you can have insert text into it
without unprotecting  the document.

Signature

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

> Hi,
>
[quoted text clipped - 15 lines]
>
> Thanks, Mike
Mike - 12 Feb 2007 08:43 GMT
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
Doug Robbins - Word MVP - 12 Feb 2007 09:30 GMT
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

Signature

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

> On 12 feb, 05:28, "Doug Robbins - Word MVP" <d...@REMOVECAPSmvps.org>
> wrote:
[quoted text clipped - 23 lines]
>
> Thanks, Mike
Mike - 12 Feb 2007 10:49 GMT
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
Doug Robbins - Word MVP - 12 Feb 2007 12:14 GMT
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

Signature

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

> On 12 feb, 10:30, "Doug Robbins - Word MVP" <d...@REMOVECAPSmvps.org>
> wrote:
[quoted text clipped - 37 lines]
>
> Thanks, Mike
Mike - 12 Feb 2007 12:53 GMT
On 12 feb, 13:14, "Doug Robbins - Word MVP" <d...@REMOVECAPSmvps.org>
wrote:
> If it's the whole of the document, it would be
>
[quoted text clipped - 4 lines]
>
> 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
Doug Robbins - Word MVP - 12 Feb 2007 20:41 GMT
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

Signature

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

> On 12 feb, 13:14, "Doug Robbins - Word MVP" <d...@REMOVECAPSmvps.org>
> wrote:
[quoted text clipped - 40 lines]
>
> Thanks, Mike
Mike - 13 Feb 2007 15:06 GMT
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.
[quoted text clipped - 87 lines]
>
> - Tekst uit oorspronkelijk bericht weergeven -

Thanks for the solution!

Mike
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.