> Is there an easy way to have the title page of a document set to a custom
> layout based on the selection on a userform?
[quoted text clipped - 5 lines]
> and field elements. The field elements will be set based on other data
> from the userform, such as report title, author, etc.
I would create a number of AutoText entries, one for each title page layout.
Each AutoText should contain a number of DOCPROPERTY fields, each of which
is one of your field elements.
Then, when you display the userform, you do the following
- each of the field elements is copied into the appropriate
CustomDocumentProperty of the active document
- The appropriate AutoText entry matching the document type is added to the
start of the document. The DOCPROPERTY fields in the AutoText entry
automatically pick up the values you inserted in the custom document
properties.

Signature
Regards
Jonathan West - Word MVP
www.intelligentdocuments.co.uk
Please reply to the newsgroup
ML - 30 Jan 2005 14:34 GMT
Thanks.
So how would I define the section where the autotext would go so that I can
replace it based on the user selection?
Is there some way I can define a region so that in my code I can basically
replace the current text with the autotext of the selected type?
>> Is there an easy way to have the title page of a document set to a custom
>> layout based on the selection on a userform?
[quoted text clipped - 21 lines]
> automatically pick up the values you inserted in the custom document
> properties.
ML - 30 Jan 2005 15:44 GMT
I managed to get it to insert by using a bookmark for the range. What I
can't figure out is how to replace the autotext if a new item is selected.
As is it just inserts another entry at the bookmark and leaves the old as
well.
Is there a way to do this so it will replace the old?
>> Is there an easy way to have the title page of a document set to a custom
>> layout based on the selection on a userform?
[quoted text clipped - 21 lines]
> automatically pick up the values you inserted in the custom document
> properties.
Jay Freedman - 31 Jan 2005 00:37 GMT
It sounds like your code is inserting the autotext outside the
bookmark, so the next autotext is inserting alongside the first. What
you want is to redefine the bookmark to cover the autotext each time,
so the next one will replace the first. See
http://www.word.mvps.org/FAQs/MacrosVBA/InsertingTextAtBookmark.htm
for the necessary code.
--
Regards,
Jay Freedman
Microsoft Word MVP FAQ: http://word.mvps.org
>I managed to get it to insert by using a bookmark for the range. What I
>can't figure out is how to replace the autotext if a new item is selected.
[quoted text clipped - 27 lines]
>> automatically pick up the values you inserted in the custom document
>> properties.
ML - 31 Jan 2005 23:34 GMT
I'm trying the code as listed. I'm using the following routine:
Sub UpdateBookmark(BookmarkToUpdate As String, TextToUse As String)
Dim BMRange As Range
Set BMRange = ActiveDocument.Bookmarks(BookmarkToUpdate).Range
BMRange.Text = TextToUse
ActiveDocument.Bookmarks.Add BookmarkToUpdate, BMRange
End Sub
And I call it with:
UpdateBookmark "TitlePage", Templates(1).AutoTextEntries("Title 1")
Issue is it is just inserting the text and I lose all formatting and fields.
> It sounds like your code is inserting the autotext outside the
> bookmark, so the next autotext is inserting alongside the first. What
[quoted text clipped - 41 lines]
>>> automatically pick up the values you inserted in the custom document
>>> properties.
Jay Freedman - 01 Feb 2005 04:08 GMT
You're losing the formatting because you're passing a string to the
function, and strings have nowhere to store formatting information.
Instead, you have to insert the autotext at the bookmark, using the
RichText argument to include formatting of the autotext.
Change the subroutine to this:
Sub UpdateBookmark(BookmarkToUpdate As String, _
AutoTextToUse As String)
Dim BMRange As Range
Set BMRange = ActiveDocument.Bookmarks(BookmarkToUpdate).Range
Templates(1).AutoTextEntries(AutoTextToUse).Insert _
Where:=BMRange, RichText:=True
ActiveDocument.Bookmarks.Add BookmarkToUpdate, BMRange
End Sub
and call it like this:
UpdateBookmark "TitlePage", "Title 1"
--
Regards,
Jay Freedman
Microsoft Word MVP FAQ: http://word.mvps.org
>I'm trying the code as listed. I'm using the following routine:
>
[quoted text clipped - 55 lines]
>>>> automatically pick up the values you inserted in the custom document
>>>> properties.
ML - 01 Feb 2005 19:35 GMT
Thanks again. Got it now!
> You're losing the formatting because you're passing a string to the
> function, and strings have nowhere to store formatting information.
[quoted text clipped - 88 lines]
>>>>> automatically pick up the values you inserted in the custom document
>>>>> properties.