#1
|
|||
|
|||
Get CustomDocumentProperties
I want to read CustomDocumentProperties, here is my code but i can't get the
"ActiveDocument.CustomDocumentProperties.Count " working : I tried with "ThisDocument.CustomDocumentProperties.Count" as well. In Excel, "ThisWorkbook.CustomDocumentProperties.Count" works. Code:
'Read CustomDocumentProperties in a WordDocument Dim cp As DocumentProperty 'Check if CustumDocumentProperties exist ... If ActiveDocument.CustomDocumentProperties.Count = 0 Then MsgBox "Generation path not found" Exit Sub For Each cp In ActiveDocument.CustomDocumentProperties MsgBox cp.Name & vbLf & cp.Value Next cp End If |
#2
|
||||
|
||||
Change 'Exit Sub' to 'Else'.
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
#3
|
|||
|
|||
I kept the Exit Sub and added Else afterwards.
It is working great. Thanks a lot. |
#4
|
||||
|
||||
The reason I suggested replacing 'Exit Sub' is that it's redundant. The code will perform just as you require with 'Else' instead. Delete your modified code's 'Exit Sub' and you'll see that is so.
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
#5
|
|||
|
|||
If i don't find custumdocument propreties , the code i have after this following code mustn't execute ; (no need to launch an executable without all its arguments)
Code:
'Lit les propriétés personnalisées du document Word Dim cp As DocumentProperty Dim strSVSPath 'Vérifie qu'il y a des propriétés personnalisée If ActiveDocument.CustomDocumentProperties.Count = 0 Then MsgBox "Custum properties de document non trouvé !" Exit Sub Else For Each cp In ActiveDocument.CustomDocumentProperties If cp.Name = "SVS" Then strSVSPath = cp.Value Else 'MsgBox cp.Name & vbLf & cp.Value End If Next cp End If 'MsgBox strSVSPath |
#6
|
||||
|
||||
As I keep saying, the 'Exit Sub' is redundant. You don't need it. It achieves nothing. Why else do you suppose I gave the advice I did in post #2???
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
#7
|
|||
|
|||
Thanks for your support.
One last question : I want to write into CustomDocumentProperties Code:
Sub CustDocPropUpdt() With ActiveDocument.CustomDocumentProperties .Item("SVS") = "C:\Users\Name\Desktop\Test\02_Multiplicate" End With End Sub |
#8
|
||||
|
||||
I suggest you look at: https://support.microsoft.com/en-us/kb/212618
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
#9
|
|||
|
|||
Thank you !
|
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
Document Variables vs CustomDocumentProperties | Cosmo | Word VBA | 2 | 08-11-2014 01:35 PM |