Diese Seite mit anderen teilen ...

Informationen zum Thema:
Forum:
WinDev Forum
Beiträge im Thema:
12
Erster Beitrag:
vor 8 Jahren, 5 Monaten
Letzter Beitrag:
vor 8 Jahren, 5 Monaten
Beteiligte Autoren:
Peter vV, Al, Glenn Rathke, PeterM

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

Startbeitrag von Al am 16.07.2009 08:49

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

Antworten:

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







von PeterM - am 16.07.2009 12:17
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

von Al - am 16.07.2009 12:56
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




von Peter vV - am 16.07.2009 14:41
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

von Peter vV - am 16.07.2009 14:43
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

von Peter vV - am 16.07.2009 14:51
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

von Peter vV - am 16.07.2009 14:53
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


von Peter vV - am 16.07.2009 14:56
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

von Glenn Rathke - am 16.07.2009 15:51
Hello Peter

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

Regards
Al

von Al - am 16.07.2009 15:54
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 :) , 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

von Al - am 16.07.2009 16:02
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


von Peter vV - am 16.07.2009 17:08
Zur Information:
MySnip.de hat keinen Einfluss auf die Inhalte der Beiträge. Bitte kontaktieren Sie den Administrator des Forums bei Problemen oder Löschforderungen über die Kontaktseite.
Falls die Kontaktaufnahme mit dem Administrator des Forums fehlschlägt, kontaktieren Sie uns bitte über die in unserem Impressum angegebenen Daten.