"CustomDocumentProperties" Why does it not work?

  • Thread starter Thread starter Rigoletto Eikenberg
  • Start date Start date
R

Rigoletto Eikenberg

Hello,

i want to save .dot-Attachments with customized "CustomDocumentProperties"
in the .dot-folder.
To save the .dot-File in the folder works fine, but the
"CustomDocumentProperties" are forgotten.
I can check they after adding with
MsgBox wrd.ActiveDocument.CustomDocumentProperties("BI_NAME")
but they are not saved. I try "save" and "close" with paramenters to save
without asking for it. But it does not work too.

Can somebody help`?

Rigoletto

Office XP with SP2


Sub vorlagen_speichern_Click() ' .dot-Anlagen werden im Vorlagenverz.
gespeichert und aktuallisiert.
i = 0

Set wrd = CreateObject("Word.Application")
dotpath = wrd.Options.DefaultFilePath(2)

' wrd.Application.Visible = True

Set colAtts = Item.Attachments
If colAtts.Count > 0 Then
For Each objAtt In colAtts
If Right(objAtt.Filename, 4) = ".dot" then
strFile = dotpath & "\" & objAtt.FileName
objAtt.SaveAsFile strFile
i = i + 1

wrd.Documents.Open (strFile)

On Error Resume Next
wrd.ActiveDocument.CustomDocumentProperties("BI_NAME").Delete
On Error Goto 0
wrd.ActiveDocument.CustomDocumentProperties.Add "BI_NAME", 0, 4,
"Rigoletto Eikenberg"

wrd.ActiveDocument.Save
wrd.ActiveDocument.Close
End If
Next
MsgBox i & " Word-Vorlagen in " & dotpath & " installiert."
else
MsgBox "Es sind keine Anlagen vorhanden die als Word-Vorlage gespeichert
werden könnten."
End If

Set wrd = Nothing

End Sub
 
You might want to ask in a Word newsgroup, since after you save the attachment as a file, Outlook is no longer involved at all, and this definitely seems like a Word issue.
--
Sue Mosher, Outlook MVP
Outlook and Exchange solutions at http://www.slipstick.com
Author of
Microsoft Outlook Programming: Jumpstart
for Administrators, Power Users, and Developers
 
Hello Sue Mosher,

oh i see. But can it be a problem with outlook? Because i record parts of
the script in word as a marco and copy it to word. In word in runs fine,
only when i try to put it in outlook the problem occurs.

I post it in the word newsgroup, probably it is a problem with the
com-interface or such a strange thing!?

Your articles are very fine :-)

Greetings
Rigoletto

You might want to ask in a Word newsgroup, since after you save the
attachment as a file, Outlook is no longer involved at all, and this
definitely seems like a Word issue.
--
Sue Mosher, Outlook MVP
Outlook and Exchange solutions at http://www.slipstick.com
Author of
Microsoft Outlook Programming: Jumpstart
for Administrators, Power Users, and Developers
 
You mean that you're running the code in Outlook VBA? That shouldn't make any difference, since it's using the same object library as Word VBA. I think you could improve the code, though, by using an explicit reference to the document, rather than ActiveDocument. Since the document isn't displayed, maybe Word isn't treating it as active:

Set wrd = CreateObject("Word.Application")
strFile = "whatever yoiu named it.dot"
Set objDoc = wrd.Documents.Open (strFile)
With objDoc
.CustomDocumentProperties("BI_NAME").Delete
.CustomDocumentProperties.Add "BI_NAME", 0, 4, "Rigoletto Eikenberg"
.Save
.Close
End With
--
Sue Mosher, Outlook MVP
Outlook and Exchange solutions at http://www.slipstick.com
Author of
Microsoft Outlook Programming: Jumpstart
for Administrators, Power Users, and Developers
 
Now i got it work. Thanks for your help.
When it is finished i will public it.

Rigoletto


You mean that you're running the code in Outlook VBA? That shouldn't make
any difference, since it's using the same object library as Word VBA. I
think you could improve the code, though, by using an explicit reference to
the document, rather than ActiveDocument. Since the document isn't
displayed, maybe Word isn't treating it as active:

Set wrd = CreateObject("Word.Application")
strFile = "whatever yoiu named it.dot"
Set objDoc = wrd.Documents.Open (strFile)
With objDoc
.CustomDocumentProperties("BI_NAME").Delete
.CustomDocumentProperties.Add "BI_NAME", 0, 4, "Rigoletto Eikenberg"
.Save
.Close
End With
--
Sue Mosher, Outlook MVP
Outlook and Exchange solutions at http://www.slipstick.com
Author of
Microsoft Outlook Programming: Jumpstart
for Administrators, Power Users, and Developers
 
Back
Top