How to access custom properties programatically

S

Steven H

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!
 
J

Jean-Guy Marcil

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

LIke this, maybe:


--

Salut!
_______________________________________
Jean-Guy Marcil - Word MVP
(e-mail address removed)
Word MVP site: http://www.word.mvps.org
 
J

Jean-Guy Marcil

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

Like this for example:

MsgBox ActiveDocument.CustomDocumentProperties("MyInfo").Value

--

Salut!
_______________________________________
Jean-Guy Marcil - Word MVP
(e-mail address removed)
Word MVP site: http://www.word.mvps.org
 
J

Jean-Guy Marcil

Jean-Guy Marcil was telling us:
Jean-Guy Marcil nous racontait que :
Steven H was telling us:
Steven H nous racontait que :


LIke this, maybe:

Ooops, don't know what happened here!

--

Salut!
_______________________________________
Jean-Guy Marcil - Word MVP
(e-mail address removed)
Word MVP site: http://www.word.mvps.org
 
J

Jean-Guy Marcil

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

--
Salut!
_______________________________________
Jean-Guy Marcil - Word MVP
(e-mail address removed)
Word MVP site: http://www.word.mvps.org
 
J

Jezebel

VBA has a special function that detects the user's idiocy level, and
disables application functionality accordingly.
 
S

Steven H

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

Jezebel

With pleasure ... just as long as you go on asking idiotic questions. You've
had the answer to this one three times now.
 
J

Jean-Guy Marcil

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.

--

Salut!
_______________________________________
Jean-Guy Marcil - Word MVP
(e-mail address removed)
Word MVP site: http://www.word.mvps.org
 

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