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.

Thanks!
José

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

The problem you had isn't specific to the BuiltInDocumentProperties
collection;
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
was
added to the collection.

As a concrete example, the member of the BuiltInDocumentProperties
collection
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
would
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
are
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
apply
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
Indexes"
in Chip Pearson's page at http://www.cpearson.com/excel/optimize.htm or
"Accessing an Item in a Collection" in
http://www.functionx.com/vbaexcel/Lesson08.htm.

--
Regards,
Jay Freedman
Microsoft Word MVP FAQ: http://word.mvps.org
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)@weatherford.com> wrote:

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

Thanks!
José


"Jose Valdes" <jose.valdes(no_spam_please)@weatherford.com> wrote in
message
news:etCpwqQQJHA.728@xxxxxxxxxxxxxxxxxxxxxxx
In Word 2007, I am trying to change the Title property. Here's my
fledging
attempt:

ActiveDocument.BuiltInDocumentProperties(Title) = "Junk"

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

ActiveDocument.BuiltInDocumentProperties(1) = "Junk"

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

Thanks!
José




.



Relevant Pages

  • Re: Change Title property in Word 2007
    ... The problem you had isn't specific to the BuiltInDocumentProperties ... member when it was ... Its string index is "Title". ... Reference does a poor job of explaining BuiltInDocumentProperties. ...
    (microsoft.public.word.vba.beginners)
  • Re: FOF_NO_UI Constant
    ... Incidentally, below, I've copied the notes on each member from the ... This string must be double-null terminated. ... pFrom As String ... the pTo member is also a double-null ...
    (microsoft.public.vb.winapi)
  • Re: FOF_NO_UI Constant
    ... The FileOperationFlags Enum uses its own constants to declare the ... Incidentally, below, I've copied the notes on each member from the Microsoft ... This string must be double-null terminated. ... pTo must meet the following specifications: ...
    (microsoft.public.vb.winapi)
  • Re: Using C# XML comments to document
    ... // returns a class name based on the type of member ... public string className ... <!-- Template for Summary, Remarks, Returns, or Value tags ...
    (microsoft.public.dotnet.framework)
  • Re: Microsoft style:
    ... In a long member function with variables left ... The psn_n conveys absolutely nothing. ... string XXXYYZZZZ. ... It is insane to allocate fixed string sizes; I was always using char * and doing dynamic ...
    (microsoft.public.vc.mfc)