What I want to do is (in pseudo-code):
IF I haven't done this already
THEN add a whole bunch of custom document properties
END IF
Adding the properties is easy, but what's the conditional?
TIA
If this is a "basic" question for you, you ain't no beginner!
If I understand you correctly you want to check to see if the
custom document properties you want to set are already set.
If so, you just have to loop through the document properties
collection, and see if any of them match (one of?) the ones
you want added:
Dim p As DocumentProperty, YeahItsThere As Boolean
For Each p In ActiveDocument.CustomDocumentProperties
If p.Name = "foo" Then
YeahItsThere = True
Exit For
End If
Next p
If Not YeahItsThere Then
ActiveDocument.CustomDocumentProperties.Add Name:="foo", _
LinkToContent:=False, Type:=msoPropertyTypeString, _
Value:="one stringy-dingy..."
End If
-- Mark Tangard <mtan...@speakeasy.net>, MS Word MVP -------------
-- See the MVP FAQ at http://www.mvps.org/word --------------------
-- http://www.speakeasy.org/~mtangard -----------------------------
----------- "Life is nothing if you're not obsessed." --John Waters
-------------------------------------------------------------------
Please reply ONLY to the newsgroup.
I had been trying something like:
If ActiveDocument.CustomDocumentProperties.Count = 0
Then ...
but I couldn't get it to work. (Why, I wonder?)
>.
>
No need for loops.
This is an example of a function to check whether a named item of
a collection exists.
Use it with any kind of (Word) object collection
Function DocPropExists(ByVal DocPropName As String) As Boolean
On Error Goto NotExist
'test on it's own name, if not there an error occurs
DocPropExists = (DocPropName = _
ActiveDocument.CustomDocumentProperties(DocPropName).Name)
Exit Function
NotExist:
'function remains false
Err.Clear
End Function
How to utilize the function?
Debug.Print DocPropExists("NameOfMyDocProp")
Kind regards,
Perry
"Paul H Griffiths" <paulhgr...@hotmail.com> schreef in bericht
news:b459374b.01091...@posting.google.com...