G
Gordon Bentley-Mix
Word 2003/Windows Vista
It's my understanding that, when saving a file for the first time, Word
looks at the Title document property and uses this to initialise the
filename. I also understand (from reading the help topic "Troubleshoot file
properties") that if the Title property is blank, Word then "extracts" a
pseudo-value for the Title property from the first line of the document and
uses this to initialise the filename. This extracted value isn't written
into the Title property that's displayed on the Summary tab of the Document
Properties dialog box, but it *is* displayed under 'Title' in the list on
the Contents tab of this dialog box. All well and good; however...
I have a template in which I set the Title property in code. In addition, I
have a bookmark on the first line of the document that gets replaced with
text (sourced from a TextBox in a UserForm) when the document is created.
What I'm finding is that, although the Title property that's displayed on
the Summary tab is being set correctly by the code, the value that's
displayed in the list on the Contents tab isn't updated accordingly. In
addition, the value that's displayed on the Contents tab reflects the
content of the bookmark on the first line of the document *before* it's
replaced with text from the UserForm. For example:
The first line of the template looks like
[txtWriterName]
(The square brackets represent a bookmark.)
My code for setting the Title property looks something like
ActiveDocument.BuiltInDocumentProperties("Title") = "Letter to " &
txtRecipientName.Value
("txtRecipientName" is a TextBox on the UserForm.)
When the document is created, the first line of the document might look like
JOHN SMITH
And as expected, the value displayed in the Title box on the Summary tab of
the Document Properties dialog box might say something like "Letter to Joe
Bloggs". However, the value that's displayed under 'Title' in the list on
the Contents tab of the Document Properties dialog box doesn't say "Letter
to Joe Bloggs" or even "JOHN SMITH"; it still says "txtWriterName". I
wouldn't mind this so much except that Word is then using the value from the
Contents tab ("txtWriterName") as the initial filename in the Save As dialog
box when the file is saved for the first time. I've even gone so far as to
insert a blank line before the line containing the txtWriterName bookmark,
but to no avail.
GRR!!! I'm at my wits' end! Having an initial filename of
"txtWriterName.doc" is absolutely NOT going to be acceptable to my users.
Does anybody have any ideas for forcing Word to use the Title property from
the Summary tab in the Save As dialog box or a method to prevent the value
that's displayed in the list on the Contents tab from being set to the first
line of the *template* instead of the first line of the *document* or
possibly updating this value to make it match what's on the Summary tab?
I've even looked at intercepting the Save As event and setting the .Name
property of wdDialogFileSaveAs to the Title property, but unfortunately the
initial save doesn't trigger this event. Maybe if I could figure out a way
to determine if it's the initial save and intercept that event...
It's my understanding that, when saving a file for the first time, Word
looks at the Title document property and uses this to initialise the
filename. I also understand (from reading the help topic "Troubleshoot file
properties") that if the Title property is blank, Word then "extracts" a
pseudo-value for the Title property from the first line of the document and
uses this to initialise the filename. This extracted value isn't written
into the Title property that's displayed on the Summary tab of the Document
Properties dialog box, but it *is* displayed under 'Title' in the list on
the Contents tab of this dialog box. All well and good; however...
I have a template in which I set the Title property in code. In addition, I
have a bookmark on the first line of the document that gets replaced with
text (sourced from a TextBox in a UserForm) when the document is created.
What I'm finding is that, although the Title property that's displayed on
the Summary tab is being set correctly by the code, the value that's
displayed in the list on the Contents tab isn't updated accordingly. In
addition, the value that's displayed on the Contents tab reflects the
content of the bookmark on the first line of the document *before* it's
replaced with text from the UserForm. For example:
The first line of the template looks like
[txtWriterName]
(The square brackets represent a bookmark.)
My code for setting the Title property looks something like
ActiveDocument.BuiltInDocumentProperties("Title") = "Letter to " &
txtRecipientName.Value
("txtRecipientName" is a TextBox on the UserForm.)
When the document is created, the first line of the document might look like
JOHN SMITH
And as expected, the value displayed in the Title box on the Summary tab of
the Document Properties dialog box might say something like "Letter to Joe
Bloggs". However, the value that's displayed under 'Title' in the list on
the Contents tab of the Document Properties dialog box doesn't say "Letter
to Joe Bloggs" or even "JOHN SMITH"; it still says "txtWriterName". I
wouldn't mind this so much except that Word is then using the value from the
Contents tab ("txtWriterName") as the initial filename in the Save As dialog
box when the file is saved for the first time. I've even gone so far as to
insert a blank line before the line containing the txtWriterName bookmark,
but to no avail.
GRR!!! I'm at my wits' end! Having an initial filename of
"txtWriterName.doc" is absolutely NOT going to be acceptable to my users.
Does anybody have any ideas for forcing Word to use the Title property from
the Summary tab in the Save As dialog box or a method to prevent the value
that's displayed in the list on the Contents tab from being set to the first
line of the *template* instead of the first line of the *document* or
possibly updating this value to make it match what's on the Summary tab?
I've even looked at intercepting the Save As event and setting the .Name
property of wdDialogFileSaveAs to the Title property, but unfortunately the
initial save doesn't trigger this event. Maybe if I could figure out a way
to determine if it's the initial save and intercept that event...