Group:  Microsoft Word » microsoft.public.word.vba.beginners
Thread: Change Title property in Word 2007

Change Title property in Word 2007
"Jose Valdes" <jose.valdes(no_spam_please)[ at ]weatherford.com> 11/7/2008 6:57:31 PM
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é


Re: Change Title property in Word 2007
"Jay Freedman" <jay.freedman[ at ]verizon.net> 11/7/2008 8:05:24 PM
Either use the built-in constant wdPropertyTitle (which has the value 1, so
it's equivalent to your second attempt) or call the File Summary Info dialog
as shown at http://www.word.mvps.org/FAQs/MacrosVBA/SetDefFilename.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.

Jose Valdes wrote:
[Quoted Text]
> 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é


Re: Change Title property in Word 2007
"Jose Valdes" <jose.valdes(no_spam_please)[ at ]weatherford.com> 11/7/2008 9:16:09 PM
Thanks! Wow, I didn't realize that "1" would work on any document.


"Jay Freedman" <jay.freedman[ at ]verizon.net> wrote in message
news:%23J5OuQRQJHA.1164[ at ]TK2MSFTNGP03.phx.gbl...
[Quoted Text]
> Either use the built-in constant wdPropertyTitle (which has the value 1,
> so it's equivalent to your second attempt) or call the File Summary Info
> dialog as shown at
> http://www.word.mvps.org/FAQs/MacrosVBA/SetDefFilename.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.
>
> Jose Valdes wrote:
>> 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é
>
>


Re: Change Title property in Word 2007
"Jan Hyde (VB MVP)" <StellaDrinker[ at ]REMOVE.ME.uboot.com> 11/12/2008 4:39:17 PM
"Jose Valdes"
<jose.valdes(no_spam_please)[ at ]weatherford.com>'s wild
thoughts were released on Fri, 7 Nov 2008 12:57:31 -0600
bearing the following fruit:

[Quoted Text]
>In Word 2007, I am trying to change the Title property. Here's my fledging
>attempt:
>
>ActiveDocument.BuiltInDocumentProperties(Title) = "Junk"

ActiveDocument.BuiltInDocumentProperties("Title")

J

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

--
Jan Hyde (VB MVP)

https://mvp.support.microsoft.com/profile/Jan.Hyde
Re: Change Title property in Word 2007
"Jose Valdes" <jose.valdes(no_spam_please)[ at ]weatherford.com> 11/12/2008 9:47:46 PM
Thanks Jan! I'll remember to use quotation marks from now on!

"Jan Hyde (VB MVP)" <StellaDrinker[ at ]REMOVE.ME.uboot.com> wrote in message
news:al1mh4lelrotft0fpm0krr8hsa7ra5u66f[ at ]4ax.com...
[Quoted Text]
> "Jose Valdes"
> <jose.valdes(no_spam_please)[ at ]weatherford.com>'s wild
> thoughts were released on Fri, 7 Nov 2008 12:57:31 -0600
> bearing the following fruit:
>
>>In Word 2007, I am trying to change the Title property. Here's my fledging
>>attempt:
>>
>>ActiveDocument.BuiltInDocumentProperties(Title) = "Junk"
>
> ActiveDocument.BuiltInDocumentProperties("Title")
>
> J
>
>>
>>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é
>>
>
> --
> Jan Hyde (VB MVP)
>
> https://mvp.support.microsoft.com/profile/Jan.Hyde


Re: Change Title property in Word 2007
"Jose Valdes" <jose.valdes(no_spam_please)[ at ]weatherford.com> 11/14/2008 3:51:31 PM
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)[ at ]weatherford.com> wrote in message
news:etCpwqQQJHA.728[ at ]TK2MSFTNGP05.phx.gbl...
[Quoted Text]
> 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é
>


Re: Change Title property in Word 2007
Jay Freedman <jay.freedman[ at ]verizon.net> 11/14/2008 7:26:56 PM
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)[ at ]weatherford.com> wrote:

[Quoted Text]
>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)[ at ]weatherford.com> wrote in message
>news:etCpwqQQJHA.728[ at ]TK2MSFTNGP05.phx.gbl...
>> 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é
>>
>
Re: Change Title property in Word 2007
"Jose Valdes" <jose.valdes(no_spam_please)[ at ]weatherford.com> 11/17/2008 8:47:24 PM
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[ at ]verizon.net> wrote in message
news:hbirh4d84ml68rdaa02k29iifh1i19l5gd[ at ]4ax.com...
[Quoted Text]
> 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)[ at ]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)[ at ]weatherford.com> wrote in
>>message
>>news:etCpwqQQJHA.728[ at ]TK2MSFTNGP05.phx.gbl...
>>> 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é
>>>
>>


Re: Change Title property in Word 2007
"Jay Freedman" <jay.freedman[ at ]verizon.net> 11/17/2008 8:56:16 PM
You're welcome! :-)

Jose Valdes wrote:
[Quoted Text]
> 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[ at ]verizon.net> wrote in message
> news:hbirh4d84ml68rdaa02k29iifh1i19l5gd[ at ]4ax.com...
>> 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)[ at ]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)[ at ]weatherford.com> wrote in
>>> message
>>> news:etCpwqQQJHA.728[ at ]TK2MSFTNGP05.phx.gbl...
>>>> 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é


Home | Search | Terms | Imprint
Newsgroups Reader