Open Template Form and insert document text

S

Steve Amey

Hi all

I am creating a macro for a friend, but haven't dealt with Word Forms
before. I have a Template document that has form fields on it. The first
section is locked (that holds the form fields) and it has another section
underneath that isn't locked.

What I would like to do is open the Template from the current document that
I am in, and insert all of the text from the current document into the
second section of the template.

In my current document I am launching the Template form using:
Documents.Add Template:="C:\MyTemplate.dot", NewTemplate:=False

This opens another document with the form fields being displayed. How do I
then insert all of the text in my current document so that it displays in
section 2, the un-protected section, so that the first page in the new
document is my form page and the rest of the pages are the pages in the
current document?

Alternatively, is there a way in which I can insert the Template page as the
first page of the current document rather than creating a new document? This
would actually be preferable, but I don't know how much work would be
involved. The current document is a CV, all I want to do is insert the Form
Fields in the template into the first page of the CV so that the form fields
act as a cover note. Is this possible?

Kind Regards,
Steve
 
D

Doug Robbins - Word MVP

Dim NewDoc as Document
Source as Document
Set Source = ActiveDocument
Set NewDoc = Documents.Add("C:\MyTemplate.dot")
NewDoc.Sections(2).Range = Source.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
 
S

Steve Amey

Hi Doug

Thank you, that works great.

1 more question if that's ok, is it possible to retain the formatting of the
Source.Range? When it goes into the new document, it gets re-formatted to
that documents format. I don't want to change the Section 1 format, just the
Section 2.

Thank you again for your help.

Kind regards,
Steve.
 
D

Doug Robbins - Word MVP

Try

NewDoc.Sections(2).Range.FormattedText = Source.Range.FormattedText

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