Re: Change Title property in Word 2007

Hey Jay,

Thank you for the free lesson in accessing collections. It's helpful info
for a newbie like me.

I guess I just got carried away when I slammed Microsoft's documentation for
Word's object model. My frustration with the Help system was that I could
not find a list of members of the BuiltInDocumentProperties collection.
Since I couldn't find it, I assumed that such a list did not exist. However,
I just did a search on wdPropertyTitle and found a Help topic called,
"WdBuiltInProperty Enumeration." The info I wanted was there after all.


"Jay Freedman" <jay.freedman@xxxxxxxxxxx> wrote in message
Hi José,

The problem you had isn't specific to the BuiltInDocumentProperties
it's related to the way VBA addresses specific members of any collection.

All collections have an Item method that returns a member of the
collection. The
method takes one argument, which the Help topic calls "index". The index
can be
an integer from 1 to the number of objects in the collection; or (for most
collections) it can be a string that was assigned to the member when it
added to the collection.

As a concrete example, the member of the BuiltInDocumentProperties
that contains the document title is the first member, so its integer index
is 1.
Its string index is "Title". (The quote marks are required to tell VBA
that this
is a literal string and not a variable name.) So each of these expressions
return the same value:

result = ActiveDocument.BuiltInDocumentProperties.Item(1)
result = ActiveDocument.BuiltInDocumentProperties.Item("Title")

There are other ways to pass an integer or a string to the Item method.
For an
integer, you can use a named constant (technically, an "enumeration"
value). The
name wdPropertyTitle represents an integer value of 1. Or you can assign a
variable that holds integer values, perhaps to use it in a loop. So these
equivalent to the first expression above:

result = ActiveDocument.BuiltInDocumentProperties.Item(wdPropertyTitle)

Dim nIndex As Integer
nIndex = 1
result = ActiveDocument.BuiltInDocumentProperties.Item(nIndex)

Similarly, you can use a variable that holds string values, like this:

Dim sIndex As String
sIndex = "Title"
result = ActiveDocument.BuiltInDocumentProperties.Item(sIndex)

In this example, note that the variable name does not have quote marks,
but the
literal value does have quotes.

Finally, instead of explicitly calling the Item method as above, you can
the index directly to the collection's name as if it was an array. The
expressions above can be written as

result = ActiveDocument.BuiltInDocumentProperties(1)
result = ActiveDocument.BuiltInDocumentProperties("Title")

and so on.

For a reference on this particular point, you can look at "Collection
in Chip Pearson's page at or
"Accessing an Item in a Collection" in

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

On Fri, 14 Nov 2008 09:51:31 -0600, "Jose Valdes"
<jose.valdes(no_spam_please)> wrote:

I posted my original question because the MS Word Object Model Reference
does a poor job of explaining BuiltInDocumentProperties. Can anyone
a more comprehensive reference for this object model?


"Jose Valdes" <jose.valdes(no_spam_please)> wrote in
In Word 2007, I am trying to change the Title property. Here's my

ActiveDocument.BuiltInDocumentProperties(Title) = "Junk"

Of course, this fails every time. I suspect that I am doing a lame job
referencing the member of the collection because the following code

ActiveDocument.BuiltInDocumentProperties(1) = "Junk"

Is it possible to access the title by the name of the member?