Document Properties & Saving a File

  • Thread starter Gordon Bentley-Mix
  • Start date
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...
 
J

Jay Freedman

Hi Gordon,

This bug is old enough to have grown a beard. You need the workaround
from http://www.word.mvps.org/FAQs/MacrosVBA/SetDefFilename.htm.

--
Regards,
Jay Freedman
Microsoft Word MVP
Email cannot be acknowledged; please post all follow-ups to the
newsgroup so all may benefit.

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

Gordon Bentley-Mix

Well wax my ar$e and call me Lucy! I was thinking about trying something
like that, but I couldn't find the 'Document Properties' dialog box in the
Dialogs collection (obviously because it's not in there). I *did* see the
'File Summary' dialog box in there and noticed that it appeared to have the
Title document property on it, but it never crossed my mind to "repurpose"
it like this - wasn't even sure that it was the same 'Title'.

Thanks Jay! I owe you one!
--
Cheers!

Gordon Bentley-Mix

Jay Freedman said:
Hi Gordon,

This bug is old enough to have grown a beard. You need the workaround
from http://www.word.mvps.org/FAQs/MacrosVBA/SetDefFilename.htm.

--
Regards,
Jay Freedman
Microsoft Word MVP
Email cannot be acknowledged; please post all follow-ups to the
newsgroup so all may benefit.

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

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