|
Modules: Lire les propriétés d'un document Word (Author, Last Print Date etc.) |
Author(s) Dev Ashish |
|
Lire les propriétés d'un document Word (Author, Last Print Date etc.)
(Q) Comment lire les diverses propriétés d'un document Word Document,
tel que Last
Print Date, Author Name, Title etc.?
(A) Vous pouvez utiliser la fonction fEnumProps qui
énumérera toutes les propriétés d'un document. Utiliser fGetDocProps pour
retourne la valeur d'une propriété.
Function fGetDocProps(strInFile As String, strProp As String)
Dim objWord As Object, objDocProps As Object
On Error GoTo Err_fGetDocProps
Set objWord = CreateObject("Word.Application")
objWord.Documents.Open strInFile
Set objDocProps = objWord.ActiveDocument.BuiltInDocumentProperties
fGetDocProps = objDocProps(strProp)
Exit_fGetDocProps:
objWord.Application.Quit savechanges:=False
Set objDocProps = Nothing
Set objWord = Nothing
Exit Function
Err_fGetDocProps:
fGetDocProps = "Error: Probably File/Property does not exist."
Resume Exit_fGetDocProps
End Function
Function fEnumProps(strInFile As String)
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
objWord.Application.Quit savechanges:=False
Set objWord = Nothing
End Function
|