DocumentBuiltiInProperteries

H

Hollis D. Paul

I have created a script that opens an Outlook message, opens a Word
Document, copies the message HTMLbody property into the document, then
saves the document as a XML file. I have taken the subject property of
the message, massaged it a little, and want to set the document's Title
and Topic (perhaps Subject) properties in the documents BuiltIn
Properties collection. Well, at least, I think that's what I am trying
to do. I want to see the string I have created in those fields when I
open the document and click properties.

When I open a word document, go to VBA, and use F2 to get the object
browser, the DocumentBuiltInProperties appears as a read only object.
I was told that some of the DocumentBuiltInProperties members were
settable. However, executing the code always kills the operation of
the script.

So, does anyone know of some other object or method that will allow me
to set those fields that I see when I open the document and then click
File-->Properties?

I figure that if I can do it from the UI, there has to be a way to do
it programmatically, and I have about 150 messages to run this script
on.

Hollis D. Paul [MVP - Outlook]
(e-mail address removed)

Using Virtual Access 4.52 build 277 (32-bit), Windows 2000 build 2600
http://search.support.microsoft.com/kb/c.asp?FR=0&SD=TECH&LN=EN-US

Mukilteo, WA USA
 
P

Peter

Try this:

Dim prop As DocumentProperty
Set prop = ActiveDocument.BuiltInDocumentProperties("Author")
prop.Value = "Me"

The above worked for me in O2k2.

You can also cut out the dim and set statements and simply do:
ActiveDocument.BuiltInDocumentProperties("Author").Value = "Me"

hth,

-Peter
 
H

Hollis D. Paul

Try this:

Dim prop As DocumentProperty
Set prop = ActiveDocument.BuiltInDocumentProperties("Author")
prop.Value = "Me"

The above worked for me in O2k2.
Well, the following code worked on the Subject field. Can you see why
it would not work on the Title field?

Set MyBIProps = MyDoc.BuiltInDocumentProperties

Set TitleProp = MyBIProps("Title")
TitleProp.Value = strSubject

Set SubjectProp = MyBIProps("Subject")
SubjectProp.Value = strSubject



Hollis D. Paul [MVP - Outlook]
(e-mail address removed)

Using Virtual Access 4.52 build 277 (32-bit), Windows 2000 build 2600
http://search.support.microsoft.com/kb/c.asp?FR=0&SD=TECH&LN=EN-US

Mukilteo, WA USA
 
P

Peter

Worked like a charm for me in Word 2002.
I amended your code a bit; dimmed the variables:

'------------ VBA ------------------------------------
Dim MyDoc As Document
Dim MyBIProps As DocumentProperties
Dim TitleProp, SubjectProp As DocumentProperty
Dim strSubject As String

strSubject = "Hello there"

Set MyDoc = ActiveDocument

Set MyBIProps = MyDoc.BuiltInDocumentProperties

Set TitleProp = MyBIProps("Title")
TitleProp.Value = strSubject

Set SubjectProp = MyBIProps("Subject")
SubjectProp.Value = strSubject
'-------------------------------------------------------

'---------- VBScript -----------------------------------
Dim oWd, MyDoc, strSubject, MyBIProps, TitleProp, SubjectProp

strSubject = "Hello there"

Set oWd = CreateObject("Word.Application")
oWd.Visible = True

Set MyDoc = oWd.Documents.Add

Set MyBIProps = MyDoc.BuiltInDocumentProperties

Set TitleProp = MyBIProps("Title")
TitleProp.Value = strSubject

Set SubjectProp = MyBIProps("Subject")
SubjectProp.Value = strSubject
'-----------------------------------------------------------

I did not save and close the document, but I checked File -> Properties and saw that the Title and Subject both had a value of "Hello there".

What about permissions? Is the document protected? Read-only? Do you have permission to edit its properties? Sometimes shots in the dark actually hit something.

-Peter

Hollis D. Paul said:
Try this:

Dim prop As DocumentProperty
Set prop = ActiveDocument.BuiltInDocumentProperties("Author")
prop.Value = "Me"

The above worked for me in O2k2.
Well, the following code worked on the Subject field. Can you see why
it would not work on the Title field?

Set MyBIProps = MyDoc.BuiltInDocumentProperties

Set TitleProp = MyBIProps("Title")
TitleProp.Value = strSubject

Set SubjectProp = MyBIProps("Subject")
SubjectProp.Value = strSubject



Hollis D. Paul [MVP - Outlook]
(e-mail address removed)

Using Virtual Access 4.52 build 277 (32-bit), Windows 2000 build 2600
http://search.support.microsoft.com/kb/c.asp?FR=0&SD=TECH&LN=EN-US

Mukilteo, WA USA
 
H

Hollis D. Paul

Sometimes shots in the dark actually hit something.
Tell me about it. I was testing the code on the client workstation
that would not set OutlookItem.Mileage. So I finally moved the .oft
file to the client that would set Mileage, and sure enough, it did fill
both the Title and Subject properts as programmed. Bummer, but I sure
do not want to spend time checking out the differences. I've got my
115 files created and loaded to a SharePoint doc library. Now to find
a way to present the files without seeing the straight HTML code.
There is always something else to do!

Hollis D. Paul [MVP - Outlook]
(e-mail address removed)

Using Virtual Access 4.52 build 277 (32-bit), Windows 2000 build 2600
http://search.support.microsoft.com/kb/c.asp?FR=0&SD=TECH&LN=EN-US

Mukilteo, WA USA
 

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