Using dsofile.dll to harvest custom document properties

M

MacCaillean

Hi

I found a Word template on the MVPS.org site which uses
VBA and dsofile.dll to return the built-in properties of
documents within a specified folder.

I wonder if anyone could post an example of how to
retrieve a custom property from a document using a similar
method?

Regards

Mac
 
J

Jonathan West

Hi Mac

The following macro lists all the custom properties of the document you
select, and inserts them into the active document

Sub TestProps()
Dim oFilePropReader As DSOleFile.PropertyReader
Dim oDocProp As DSOleFile.DocumentProperties
Dim oCustProp As DSOleFile.CustomProperty
Dim sTmp As String

Set oFilePropReader = New DSOleFile.PropertyReader

With Dialogs(wdDialogFileOpen)
If .Display = -1 Then
Set oDocProp = oFilePropReader.GetDocumentProperties( _
WordBasic.FileNameInfo$(.Name, 1))
For Each oCustProp In oDocProp.CustomProperties
sTmp = oCustProp.Name & ": " & CStr(oCustProp.Value)
Selection.InsertAfter sTmp
Selection.InsertParagraphAfter
Selection.Collapse Direction:=wdCollapseEnd
Next oCustProp
End If
End With

End Sub
 
M

MacCaillean

Hi Jonathan

Thank you very much for your code, which works exactly as
you promised.

I'll be trying to incorporate it into my task, hopefully
over the next few days, so watch this space for further
questions!

Thanks again

Mac

-----Original Message-----
Hi Mac

The following macro lists all the custom properties of the document you
select, and inserts them into the active document

Sub TestProps()
Dim oFilePropReader As DSOleFile.PropertyReader
Dim oDocProp As DSOleFile.DocumentProperties
Dim oCustProp As DSOleFile.CustomProperty
Dim sTmp As String

Set oFilePropReader = New DSOleFile.PropertyReader

With Dialogs(wdDialogFileOpen)
If .Display = -1 Then
Set oDocProp =
oFilePropReader.GetDocumentProperties( _
 

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