Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Word / Programming / December 2006

Tip: Looking for answers? Try searching our database.

How to access custom properties programatically

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Steven H - 01 Dec 2006 00:56 GMT
Looking to update the values in some Custom document poperties.  How can I
do this using Word 2007 and VSTO?  Need to do it while document is open and
avtive.

Specifically I have a Ribbon that is used to launch and interface to select
and update custom metat data that is included as REF filds in the document.

Thanks!
Jean-Guy Marcil - 01 Dec 2006 04:06 GMT
Steven H  was telling us:
Steven H nous racontait que :

> Looking to update the values in some Custom document poperties.  How
> can I do this using Word 2007 and VSTO?  Need to do it while document
[quoted text clipped - 3 lines]
> select and update custom metat data that is included as REF filds in
> the document.

LIke this, maybe:

Signature

Salut!
_______________________________________
Jean-Guy Marcil - Word MVP
jmarcilREMOVE@CAPSsympatico.caTHISTOO
Word MVP site: http://www.word.mvps.org

Jean-Guy Marcil - 01 Dec 2006 12:29 GMT
Jean-Guy Marcil was telling us:
Jean-Guy Marcil nous racontait que :

> Steven H  was telling us:
> Steven H nous racontait que :
[quoted text clipped - 8 lines]
>
> LIke this, maybe:

Ooops, don't know what happened here!

Signature

Salut!
_______________________________________
Jean-Guy Marcil - Word MVP
jmarcilREMOVE@CAPSsympatico.caTHISTOO
Word MVP site: http://www.word.mvps.org

Jean-Guy Marcil - 01 Dec 2006 04:07 GMT
Steven H  was telling us:
Steven H nous racontait que :

> Looking to update the values in some Custom document poperties.  How
> can I do this using Word 2007 and VSTO?  Need to do it while document
[quoted text clipped - 4 lines]
> the document.
> Thanks!

Like this for example:

MsgBox ActiveDocument.CustomDocumentProperties("MyInfo").Value

Signature

Salut!
_______________________________________
Jean-Guy Marcil - Word MVP
jmarcilREMOVE@CAPSsympatico.caTHISTOO
Word MVP site: http://www.word.mvps.org

Steven H - 01 Dec 2006 16:42 GMT
I neet to SET the value.  It looks like that is not supported :(

> Steven H  was telling us:
> Steven H nous racontait que :
[quoted text clipped - 11 lines]
>
> MsgBox ActiveDocument.CustomDocumentProperties("MyInfo").Value
Jean-Guy Marcil - 01 Dec 2006 16:54 GMT
Steven H was telling us:
Steven H nous racontait que :

> I neet to SET the value.  It looks like that is not supported :(

Have you looked at the online help for the code I suggested
(CustomDocumentProperties)?

CustomDocumentProperties Property

Returns a DocumentProperties collection that represents all the custom
document properties for the specified document.

expression.CustomDocumentProperties
expression    Required. An expression that returns one of the objects in the
Applies To list.

Remarks
Use the BuiltInDocumentProperties property to return the collection of
built-in document properties.

For information about returning a single member of a collection, see
Returning an Object from a Collection.

Example
This example inserts a list of custom built-in properties at the end of the
active document.

Set myRange = ActiveDocument.Content
myRange.Collapse Direction:=wdCollapseEnd
For Each prop In ActiveDocument.CustomDocumentProperties
   With myRange
       .InsertParagraphAfter
       .InsertAfter prop.Name & "= "
       .InsertAfter prop.Value
   End With
Next

This example adds a custom built-in property to Sales.doc.

thename = InputBox("Please type your name", "Name")
Documents("Sales.doc").CustomDocumentProperties.Add _
   Name:="YourName", LinkToContent:=False, Value:=thename, _
   Type:=msoPropertyTypeString

So, if you can create it, you can certainly change the value, as exemplified
in the following:

Dim strName As String

strName = InputBox("Please type your name", "Name")

With ActiveDocument
   .CustomDocumentProperties.Add "YourName", False, _
       msoPropertyTypeString, strName
   MsgBox .CustomDocumentProperties("YourName").Value

   .CustomDocumentProperties("YourName").Value = "New Name"
   MsgBox .CustomDocumentProperties("YourName").Value
End With

Signature

--
Salut!
_______________________________________
Jean-Guy Marcil - Word MVP
jmarcilREMOVE@CAPSsympatico.caTHISTOO
Word MVP site: http://www.word.mvps.org

Steven H - 03 Dec 2006 02:41 GMT
I guess I was not explicit enough in my scenario.  What you reference below
changes the field value in the document (if the custom field is refernced in
the document).

I want to change the actual custom field entry (the one you see when you use
the user interface in Word to add a custom field).

Using the code refernced does not chage the stored attribute value, thus if
the user selects the Update Filed action on the field the original text
stored on the document custom proerty default value is returned.

> Steven H was telling us:
> Steven H nous racontait que :
[quoted text clipped - 63 lines]
> jmarcilREMOVE@CAPSsympatico.caTHISTOO
> Word MVP site: http://www.word.mvps.org
Jezebel - 03 Dec 2006 04:05 GMT
You really have a problem reading Help, don't you?

>I guess I was not explicit enough in my scenario.  What you reference below
>changes the field value in the document (if the custom field is refernced
[quoted text clipped - 74 lines]
>> jmarcilREMOVE@CAPSsympatico.caTHISTOO
>> Word MVP site: http://www.word.mvps.org
Jean-Guy Marcil - 04 Dec 2006 02:26 GMT
Steven H was telling us:
Steven H nous racontait que :

> I guess I was not explicit enough in my scenario.  What you reference
> below changes the field value in the document (if the custom field is
> refernced in the document).

No it does not.

> I want to change the actual custom field entry (the one you see when
> you use the user interface in Word to add a custom field).

This is what my code does and the help form Microsoft suggest you can do.

> Using the code refernced does not chage the stored attribute value,

Yes it does.
(The code I posted creates a custom document property, displays the stored
value, changes the stored value and displays this new value. Actual document
content is not even touched.)

> thus if the user selects the Update Filed action on the field the
> original text stored on the document custom proerty default value is
> returned.

I'll resist the temptation to be as caustic as other people...
(Remember that none of use here are paid to do this, we actually take some
of our free time to try to help others, I think the least one can do when
receiving help is actually trying the suggested procedure.)

But please, have you actually read my post (which included verbatim text
from the Microsoft Word VBA help file)?
Have you actually tried the suggest code?

If you have and did not get the results you wanted, please, post back
describing the exact steps you used and outlining the differences between
actual and expected results.

Signature

Salut!
_______________________________________
Jean-Guy Marcil - Word MVP
jmarcilREMOVE@CAPSsympatico.caTHISTOO
Word MVP site: http://www.word.mvps.org

Jezebel - 01 Dec 2006 23:13 GMT
VBA has a special function that detects the user's idiocy level, and
disables application functionality accordingly.

>I neet to SET the value.  It looks like that is not supported :(
>
[quoted text clipped - 13 lines]
>>
>> MsgBox ActiveDocument.CustomDocumentProperties("MyInfo").Value
Steven H - 03 Dec 2006 02:41 GMT
ha ha Jezebel, you are very entertaining.  Keep up the ever so useful posts.

> VBA has a special function that detects the user's idiocy level, and
> disables application functionality accordingly.
[quoted text clipped - 16 lines]
>>>
>>> MsgBox ActiveDocument.CustomDocumentProperties("MyInfo").Value
Jezebel - 03 Dec 2006 04:07 GMT
With pleasure ... just as long as you go on asking idiotic questions. You've
had the answer to this one three times now.

> ha ha Jezebel, you are very entertaining.  Keep up the ever so useful
> posts.
[quoted text clipped - 19 lines]
>>>>
>>>> MsgBox ActiveDocument.CustomDocumentProperties("MyInfo").Value
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.