Welcome! Log In Create A New Profile

Advanced

[WD14] How do I extract a Word Document's properties using Automation

Posted by Al 
Hello All

I would like to be able to extract the properties of a word document
These are the items displayed from the MS Word File > Properties menu option and include the author, subject, keywords and statistics.

I have looked at the word example that comes with WD14 but it is not much help in this case, so if anyone has some pointers or an example it would be much appreciated.

I found this example on the web and I think the "BuiltInDocumentProperties" is the object I need to interogate but I don't know how to translate this VB ? Code into Windev code

Function fEnumProps(strInFile As String)
'Usage Examples
'?fEnumProps("C:\more junk\read me.doc")
'
Dim objWord As Object, objDocProps As Object
Dim i As Integer
On Error Resume Next
Set objWord = CreateObject("Word.Application")
With objWord
.Documents.Open strInFile
Set objDocProps = objWord.ActiveDocument.BuiltInDocumentProperties
For i = 0 To objDocProps.Count - 1
Debug.Print objDocProps(i).Name, objDocProps(i).value
Next i
End With


Regards
Al




Edited 1 time(s). Last edit at 07/16/2009 11:52AM by Al.
Hi Al,

there is an example in WD where you can read the properties of a sound file(mp3)
maybe the same or similar in word ?

peter





Hello Peter

Interesting method in that example, but it does not use automation which I think is the best way to interface to a Word document. That example deconstructs the mp3 file header in fixed locations to get the information.

Thanks for the interest.

Regards
Al
Hi Al,

A simple translation: (it needs some exception handling)

 
i, j is int
objWord, ObjDocProps are Automation dynamic
objWord = new Automation ("Word.Application")
objWord>>Documents>>Open("C:\temp\test.doc")
ObjDocProps = objWord>>ActiveDocument>>BuiltInDocumentProperties()

j=ObjDocProps>>Count
// when exception DO 
FOR i = 1 TO j
	Trace(ObjDocProps>>item>>Name+"   -    "+ObjDocProps>>item>>value)
END

delete objWord
delete ObjDocProps

When you need only some properties: (p.e. the title)

 
objWord, ObjDocProp are Automation dynamic
objWord = new Automation ("Word.Application")
wdPropertyTitle is int=1
objWord>>Documents>>Open("C:\temp\test.doc")
ObjDocProp=objWord>>ActiveDocument>>BuiltInDocumentProperties(wdPropertyTitle) 
Info(ObjDocProp>>Value)
delete objWord
delete ObjDocProp

If you don't want to open the file try the dsofile.dll

--
Peter


Hi Al,

A simple translation: (it needs some exception handling)

 
i, j is int
objWord, ObjDocProps are Automation dynamic
objWord = new Automation ("Word.Application")
objWord>>Documents>>Open("C:\temp\test.doc")
ObjDocProps = objWord>>ActiveDocument>>BuiltInDocumentProperties()

j=ObjDocProps>>Count
// when exception DO 
FOR i = 1 TO j
	Trace(ObjDocProps>>item>>Name+"   -    "+ObjDocProps>>item>>value)
END

delete objWord
delete ObjDocProps

When you need only some properties: (p.e. the title)

 
objWord, ObjDocProp are Automation dynamic
objWord = new Automation ("Word.Application")
wdPropertyTitle is int=1
objWord>>Documents>>Open("C:\temp\test.doc")
ObjDocProp=objWord>>ActiveDocument>>BuiltInDocumentProperties(wdPropertyTitle) 
Info(ObjDocProp>>Value)
delete objWord
delete ObjDocProp

If you don't want to open the file try the dsofile.dll

--
Peter
Hi Al,

A simple translation: (it needs some exception handling)
 
i, j is int
objWord, ObjDocProps are Automation dynamic
objWord = new Automation ("Word.Application")
objWord>>Documents>>Open("C:\temp\test.doc")
ObjDocProps = objWord>>ActiveDocument>>BuiltInDocumentProperties()

j=ObjDocProps>>Count
// when exception DO 
FOR i = 1 TO j
     Trace(ObjDocProps>>item>>Name+"   -    "+ObjDocProps>>item>>value)
END
delete objWord
delete ObjDocProps

When you need only some properties: (p.e. the title)
 
objWord, ObjDocProp are Automation dynamic
objWord = new Automation ("Word.Application")
wdPropertyTitle is int=1
objWord>>Documents>>Open("C:\temp\test.doc")
ObjDocProp=objWord>>ActiveDocument>>BuiltInDocumentProperties(wdPropertyTitle) 
Info(ObjDocProp>>Value)
delete objWord
delete ObjDocProp

If you don't want to open the file try the dsofile.dll


Peter
Hi Al,

A simple translation: (it needs some exception handling)

 
i, j is int
objWord, ObjDocProps are Automation dynamic
objWord = new Automation ("Word.Application")
objWord>>Documents>>Open("C:\temp\test.doc")
ObjDocProps = objWord>>ActiveDocument>>BuiltInDocumentProperties()

j=ObjDocProps>>Count
// when exception DO 
FOR i = 1 TO j
	Trace(ObjDocProps>>item>>Name+"   -    "+ObjDocProps>>item>>value)
END

delete objWord
delete ObjDocProps
--
Peter
Btw, if you know what properties you want (p.e. the title)

 
objWord, ObjDocProp are Automation dynamic
objWord = new Automation ("Word.Application")
wdPropertyTitle is int=1
objWord>>Documents>>Open("C:\temp\test.doc")
ObjDocProp=objWord>>ActiveDocument>>BuiltInDocumentProperties(wdPropertyTitle) 
Info(ObjDocProp>>Value)
delete objWord
delete ObjDocProp
If you don't want to open the .doc file look for the microsoft dsofile.dll and its functions
Hello,

I would first start doing this within Word. You can turn on and record macros, then do what you need to by keystrokes, etc.. When you're finished you can look at the VBA code that was generated.

This gives you a good place to start with the code. Substitute the VBA.STUFF with VBA>>STUFF

HTH
Glenn
Hello Peter

Your examples work perfectly.
Thank you very much for the time and effort you put in to answer my query.

Regards
Al
Hello Glen

I tried the macro approach, it gave me some insights for an earlier foray into find and replace, but in this case all I could do was open the properties panel in Word and the macro did not record any actions.

I think that for me the examples from Peter were, hopefully smiling smiley , the final pieces of the automation puzzle in terms of Word. Previous examples in the forum and the PCsoft example in WD14 show me how to do things with Word and how to place information into a document but these examples show how to extract information from Word which I had no idea how to achieve till now.

Regards
Al
Al, all together only 2 examples. Posted it in different ways because the forum didn't seem to accept my postings at first (spamfilter?). Well no problem, now i am again a little higher on the postlist ... ;-)

--
Peter
Author:

Your Email:


Subject:


Spam prevention:
Please, enter the code that you see below in the input field. This is for blocking bots that try to post this form automatically. If the code is hard to read, then just try to guess it right. If you enter the wrong code, a new image is created and you get another chance to enter it right.
Message: