Microsoft Word stores value for built-in and custom properties in two
collections: BuiltinDocumentProperties and CustomDocumentProperties. By
opening a document through automation, you can read these values, and insert
them into a table. An example of reading the properties would be:
Function ReadWordProperties()
Dim wd As New Word.Application
Dim doc As Word.Document
Set doc = wd.Documents.Open("C:\TestDoc.doc")
Debug.Print doc.BuiltinDocumentProperties("Author").Value
Debug.Print doc.CustomDocumentProperties("SOP Number").Value
doc.Close
wd.Quit
Set doc = Nothing
Set wd = Nothing
End Function
If you have multiple documents, you can use the Dir function to loop through
the Word documents in a directory.

Signature
David Lloyd
MCSD .NET
http://LemingtonConsulting.com
This response is supplied "as is" without any representations or warranties.
I want to be able to update a Microsoft Access table with data relating to
word documents. Each document has a custom property called SOP Number, i
want to be able to drag this property data out of each document and populate
an access table. I also want to be able to pull out the creation date,
authur, and other bits and pieces.
The question is, is this possible, and if so, how would I do it?
Thanks in advance for any help
ingalla - 17 Dec 2005 21:10 GMT
David
I have got that working, thanks, but how would I open each document in the
folder in turn, rather than just a specific document?
Thanks
Andy
> Microsoft Word stores value for built-in and custom properties in two
> collections: BuiltinDocumentProperties and CustomDocumentProperties. By
[quoted text clipped - 30 lines]
>
> Thanks in advance for any help
David Lloyd - 17 Dec 2005 21:42 GMT
Andy:
The following sample iterates a directory and processes all Word documents
(*.doc) in the root C directory:
Function ReadWordProperties()
Dim wd As New Word.Application
Dim doc As Word.Document
Dim sFileName As String
'Gets the first Word document
sFileName = Dir("C:\*.doc")
Do While sFileName <> ""
Set doc = wd.Documents.Open("C:\" & sFileName)
Debug.Print sFileName, doc.BuiltinDocumentProperties("Author").Value
Debug.Print doc.CustomDocumentProperties("SOP Number").Value
doc.Close
'Get the next Word document, this will return "" when all files have
been iterated
sFileName = Dir
Loop
wd.Quit
Set doc = Nothing
Set wd = Nothing
End Function

Signature
David Lloyd
MCSD .NET
http://LemingtonConsulting.com
This response is supplied "as is" without any representations or warranties.
David
I have got that working, thanks, but how would I open each document in the
folder in turn, rather than just a specific document?
Thanks
Andy
"David Lloyd" wrote:
> Microsoft Word stores value for built-in and custom properties in two
> collections: BuiltinDocumentProperties and CustomDocumentProperties. By
[quoted text clipped - 33 lines]
>
> Thanks in advance for any help
ingalla - 18 Dec 2005 11:08 GMT
I have got all of that to work, and am now trying to get the data added to
the table "tblsops", although when this is run, it looks as if it is working
and displays all of the data correctly in the debug window nothing is being
added to the table.
Any Ideas.
Andy
--------------------------
Function ReadWordProperties()
On Error Resume Next
Dim wd As New Word.Application
Dim doc As Word.Document
Dim sFileName As String
Dim db As Database
Dim rst As Recordset
sFileName = Dir("D:\Standard Operating Procedures\Collision
Investigation\Mathematics\*.doc")
Do While sFileName <> ""
wd.Visible = False
Set doc = wd.Documents.Open("D:\Standard Operating Procedures\Collision
Investigation\Mathematics\" & sFileName)
Set db = CurrentDb()
Set rst = db.OpenRecordset("tblsops")
rst.AddNew
rst("Title") = doc.BuiltInDocumentProperties("Title").Value
rst("Subject") = doc.BuiltInDocumentProperties("Subject").Value
rst("Author") = doc.BuiltInDocumentProperties("Author").Value
rst.Update
Debug.Print doc.BuiltInDocumentProperties("Title").Value
Debug.Print doc.BuiltInDocumentProperties("Subject").Value
Debug.Print doc.BuiltInDocumentProperties("Author").Value
'Debug.Print doc.BuiltInDocumentProperties("Keywords").Value
'Debug.Print doc.BuiltInDocumentProperties("Comments").Value
'Debug.Print doc.BuiltInDocumentProperties("Template").Value
'Debug.Print doc.BuiltInDocumentProperties("Last Author").Value
'Debug.Print doc.BuiltInDocumentProperties("Revision Number").Value
'Debug.Print doc.BuiltInDocumentProperties("Application Name").Value
'Debug.Print doc.BuiltInDocumentProperties("Last Print Date").Value
'Debug.Print doc.BuiltInDocumentProperties("Creation Date").Value
'Debug.Print doc.BuiltInDocumentProperties("Last Save Time").Value
'Debug.Print doc.BuiltInDocumentProperties("Total Editing Time").Value
'Debug.Print doc.BuiltInDocumentProperties("Number of Pages").Value
'Debug.Print doc.BuiltInDocumentProperties("Number of Words").Value
'Debug.Print doc.BuiltInDocumentProperties("Number of Characters").Value
'Debug.Print doc.BuiltInDocumentProperties("Security").Value
'Debug.Print doc.BuiltInDocumentProperties("Format").Value
'Debug.Print doc.BuiltInDocumentProperties("Manager").Value
'Debug.Print doc.BuiltInDocumentProperties("Company").Value
'Debug.Print doc.BuiltInDocumentProperties("Number of Bytes").Value
'Debug.Print doc.BuiltInDocumentProperties("Number of Lines").Value
'Debug.Print doc.BuiltInDocumentProperties("Number of Paragraphs").Value
'Debug.Print doc.BuiltInDocumentProperties("Number of Characters (with
spaces)").Value
'If doc.BuiltInDocumentProperties("Company").Value <> "Collision Geomatics"
Then
' doc.BuiltInDocumentProperties("Company").Value = "Collision
Geomatics"
'End If
'Debug.Print doc.CustomDocumentProperties("SOP Number").Value
doc.Close
sFileName = Dir
Loop
wd.Quit
Set doc = Nothing
Set wd = Nothing
rst.Close
End Function
> Andy:
>
[quoted text clipped - 78 lines]
> >
> > Thanks in advance for any help
TC - 18 Dec 2005 13:18 GMT
For one thing, these lines should go /before/ the: Do While
sFileName <> "" loop, not inside it:
Set db = CurrentDb()
Set rst = db.OpenRecordset("tblsops")
HTH,
TC
ingalla - 18 Dec 2005 15:06 GMT
Moved those two lines and it still will not write the data to the table. Any
more ideas that i can try. Thanks anyway.
andy
> For one thing, these lines should go /before/ the: Do While
> sFileName <> "" loop, not inside it:
[quoted text clipped - 4 lines]
> HTH,
> TC
TC - 19 Dec 2005 02:25 GMT
Gaaah, /now/ I see it!
The "On Error Resume Next" at the top of your code!
That tells Access to totally ignore every error in your code. Get rid
of that statement, then you'll find out where the error is. It is
/never/ a good idea to use an On Error Resume Next stateent like that -
to cover a whole swag of code, for no apparent purpose.
HTH,
TC