customdocumentproperties

G

Geir Olav Heiene

Hi all,

I am using customdocumentproperties linked to bookmark range in Word as part
of my template designs.

However, linked customdocumentproperties do not update its linked content
before the document is saved and the document reopened. I have observed that
in Word 2003 and Word 2007. I can see others have reported the same, but I
have found no good solutions.
When programmatically opening the and manually pressing OK in the
File|Properties dialog, the wanted update of the links actually do occur.
Problem is that the FileProperties dialog is modal, and I have no means of
pressing the OK button programmatically unless I monitor it from an external
exe in its own process. I have actually done that - but its not a good
solution indeed.
Another "dirty solution" I made is to establish "shadow"
customdocumentproperties entries with e.g. a "_Hot" extension in the name
that updates on BeforeSave event.

The ultimate and only good solution would IMO be to call a currently not
exposed or not documented procedure that actually happens behind the mentiond
OK button in the FileProperties dialog box.

Are there any suggestions?
Could it be that the Word team could help us with provide a such function or
a code snippet to accomplish it in the meantime?
 
D

Doug Robbins - Word MVP

How about tell us what you really need to do (that is the end result) rather
than how you have gone about it as that may not be the best way.

--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP
 
G

Geir Olav Heiene

Hi Doug

When saving a word document directly into the storage of Sharepoint or e.g.
an archiving solution like Meridio, the target system like the above will
look for if there are customdocumentproperties in the document matching field
names in e.g. sharepoint. If yes, the content of the customdocumentproperties
will be extracted and populate sharepoint as searchable meta data for later
search and retrieval.

As documents will not first be stored on the file system, then reopend and
then saved in the sharepoint or Meridio store, its crucial that the linked
properties are updated with the data from the referenced linked bookmark
ranges at the very first save.
If I had a way of programmatically force a refresh, I would do that in the
BeforeSave app event for the document.

Hope this clearifies the context and explains why what I ask for would be
useful.
 
O

old man

Hi,

I wrote this code segment to reproduce all linked custom properties -
running this should 'refresh' the properties. I save the values of the custom
properties, remove the properties and recreate them...

Since the value comes from the boomarked range I am not sure what the value
parameter (in the add) does. You may have to replace it with the current
value of the bookmarked range. It may be there so that the custom property
value is easily accessible. Nonlinked custom properties are ignored by the
code.

MSDN indicates that custome properties are not updated until the document is
saved but my code works without having to save the document.
sub updatecustombookmarks

On Error GoTo xx
Dim namesL(), valuesL(), typesL(), linksourceL(), dp(), linktocontentL()
Dim CustomPropCount As Integer
Dim i As Integer

CustomPropCount = ActiveDocument.CustomDocumentProperties.Count
ReDim dp(1 To CustomPropCount)
ReDim namesL(1 To CustomPropCount)
ReDim valuesL(1 To CustomPropCount)
ReDim typesL(1 To CustomPropCount)
ReDim linksourceL(1 To CustomPropCount)
ReDim linktocontentL(1 To CustomPropCount)

For i = 1 To CustomPropCount
Set dp(i) = ActiveDocument.CustomDocumentProperties(i)
Next i

For i = 1 To CustomPropCount
linktocontentL(i) = dp(i).LinkToContent
If linktocontentL(i) = True Then
namesL(i) = dp(i).Name
valuesL(i) = dp(i).Value
typesL(i) = dp(i).Type
linksourceL(i) = dp(i).LinkSource
End If
Next

For i = CustomPropCount To 1 Step -1
If linktocontentL(i) = True Then
ActiveDocument.CustomDocumentProperties(i).Delete
End If

Next

For i = 1 To CustomPropCount
If linktocontentL(i) = True Then

ActiveDocument.CustomDocumentProperties.Add _
Name:=namesL(i), _
LinkToContent:=True, _
Value:=valuesL(i), _
Type:=typesL(i), _
LinkSource:=linksourceL(i)

End If

Next i


Exit Sub
xx: MsgBox Err.Description

End Sub

old man
 
G

Geir Olav Heiene

Hi

Great thanks for the reply!
I actually did try that approach as part of my initial search for
workarounds, but it do not work - at least not in my environment.

When running this code the property is added, but it returns a zero-length
string although it refers to a bookmark range that makes up a word:
Debug.Print ActiveDocument.CustomDocumentProperties.Add("testProp", True, 4,
, "bmTest").Value
I also tried deleting and recreating programmatically as mentioned, but with
no luck as expected.

If your code actually work on your place, it would be useful for me to know
the version of Word - or any other possible environment difference that could
explain it.

In the meantime I would still need the "behind the scene" routine that the
FileProperties dialog is running. If not a solution will come up in this
thread I will need to escalate it as a support case with the appropriate
Microsoft support team.

goh
 
O

old man

Hi,

I tested it by adding new customproperties (Office 2003 11.8125 SP2) and it
worked. I did not try modifying existing customproperties. I also looked at
dialog boxes (to programmically use dlg.show, dlg.execute) but in MS list of
dialogs I could not find any that match the dialog you are referring to.
There is C code on (from which you would have to create a dll) MSDN that
does something similar to what you need.

old man
 

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