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 / February 2005

Tip: Looking for answers? Try searching our database.

Custom Document Properties

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Debra Farnham - 06 Feb 2005 02:57 GMT
Hello again

I'm still using Word 2K on Win2K

How can I check to see if a custom document property with the name Test1
already exists and if so, create a new one named Test2?

In otherwords:

If customdocumentproperty named "Test1" exists Then

   With ActiveDocument.CustomDocumentProperties
       .Add Name:="Test2", LinkToContent:=False, Value:="Whatever", _
         Type:=msoPropertyTypeString

   End With
End If

The next iteration would have to check for Test2 and create a new
customdocumentproperty named Test3 .... etc etc.  I'm quite certain I need a
loop but I'm a lost cause when it comes to devising loops.

I could possibly end up with several custom document properties named Test
and a number.  I would just like the number to increment by one based on the
highest number already in use.

I sure hope this makes sense to someone.

Thanks in advance for any help.

Debra
Greg Maxey - 06 Feb 2005 03:43 GMT
Debra,

Maybe something like:

Sub ScratchMacro()
Dim oDocProp As DocumentProperty
Dim i As Long
i = 1
Dim oPropName As String
Dim oPropValue As String

oPropValue = "whatever"

For Each oDocProp In ActiveDocument.CustomDocumentProperties
 If Left(oDocProp.Name, 4) = "Test" Then
   i = i + 1
 End If
Next
oPropName = "Test" & i
ActiveDocument.CustomDocumentProperties.Add _
   Name:=oPropName, LinkToContent:=False, Value:=oPropValue, _
   Type:=msoPropertyTypeString
End Sub

Signature

Greg Maxey/Word MVP
A Peer in Peer to Peer Support

> Hello again
>
[quoted text clipped - 27 lines]
>
> Debra
Debra Farnham - 06 Feb 2005 03:48 GMT
To my rescue once again I see Greg!

(I actually managed to get part of the way there on my own - there's hope I
think)

Thanks tons!  I owe you bigtime!  It works like a charm.

Deb

> Debra,
>
[quoted text clipped - 51 lines]
> >
> > Debra
Greg Maxey - 06 Feb 2005 03:55 GMT
Debra,

Actually it doesn't do quite what you asked which was to check to sed "if" a
Test1 exist and "if" it does create a Test2.   I cobbled together the
following that requires a Test1 to exist prior to doing anything else.

Sub ScratchMacro()
Dim oDocProp As DocumentProperty
Dim i As Long
i = 1
Dim oPropName As String
Dim oPropValue As String
Dim bExist As Boolean

oPropValue = "whatever"
bExist = False
For Each oDocProp In ActiveDocument.CustomDocumentProperties
 If oDocProp.Name = "Test1" Then bExist = True
 Exit For
Next
If bExist Then
For Each oDocProp In ActiveDocument.CustomDocumentProperties
 If Left(oDocProp.Name, 4) = "Test" Then
   i = i + 1
 End If
Next
oPropName = "Test" & i
ActiveDocument.CustomDocumentProperties.Add _
   Name:=oPropName, LinkToContent:=False, Value:=oPropValue, _
   Type:=msoPropertyTypeString
End If
End Sub

Signature

Greg Maxey/Word MVP
A Peer in Peer to Peer Support

> To my rescue once again I see Greg!
>
[quoted text clipped - 64 lines]
>>>
>>> Debra
Debra Farnham - 06 Feb 2005 04:10 GMT
I completely overlooked the IF part when I noticed that the property had
been added.  OOPS.

Thanks again Greg!

Your time and effort are HUGELY appreciated!

Deb

> Debra,
>
[quoted text clipped - 97 lines]
> >>>
> >>> Debra
 
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.