Get document statistics - file info

F

FotoArt

hello everyone

How do I access a file and get document stats such as FileName, Directory,
Template, Title, Created, LastSaved, LastSavedBy via a macro.
the files I want to excess are on a server.

Any help will be appreciated.
 
J

Jay Freedman

hello everyone

How do I access a file and get document stats such as FileName, Directory,
Template, Title, Created, LastSaved, LastSavedBy via a macro.
the files I want to excess are on a server.

Any help will be appreciated.

See http://www.word.mvps.org/FAQs/MacrosVBA/DSOFile.htm.

Note that this works only for the Word 97-2003 file format and not for
the new Word 2007 format. If you need to deal with .docx/.docm format,
you'll need to open them as zip files and extract the appropriate bits
of XML. I don't know whether anyone has created a simple tool for that
yet.

--
Regards,
Jay Freedman
Microsoft Word MVP
Email cannot be acknowledged; please post all follow-ups to the
newsgroup so all may benefit.
 
O

old man

Hi,

Here is a function that will do basically what you want...

Sub alldocs(whatdir)
Dim allinfo As String
Dim curdocinfo As String
Dim curver As Integer
Dim mytemplate As Template

Dim f1 As String

If Right(whatdir, 1) <> Application.PathSeparator Then
whatdir = whatdir & Application.PathSeparator
End If


f1 = Dir(whatdir & "*.doc")
Do While f1 <> ""
curdocinfo = ""
Documents.Open FileName:=whatdir & f1
curdocinfo = "Document - " & f1 & " is in folder - " & whatdir & vbCrLf
curver = ActiveDocument.Versions.Count
curdocinfo = curdocinfo & "Current Version Saved By - " &
ActiveDocument.Versions(curver).SavedBy & vbCrLf
curdocinfo = curdocinfo & "Date Last Saved - " & FileDateTime(whatdir &
f1) & vbCrLf
curdocinfo = curdocinfo & "Created By - " &
ActiveDocument.Versions(1).SavedBy & vbCrLf

curdocinfo = curdocinfo & "Title - " &
ActiveDocument.BuiltInDocumentProperties(wdPropertyTitle) & vbCrLf
curdocinfo = curdocinfo & "Template - " &
ActiveDocument.BuiltInDocumentProperties(wdPropertyTemplate) & vbCrLf & vbCrLf
allinfo = allinfo & curdocinfo
ActiveDocument.Close savechanges:=False

f1 = Dir
Loop

Selection.HomeKey unit:=wdStory
Selection.InsertBefore allinfo

End Sub

invoke this with
alldocs("k:\dept25\alldocs")

Note:
you want to add error checking (on error...) and probably want to freeze the
screen while this is going on (lots of flashing as files are opened and
closed).
If a document was not saved as a version errors will be raised when this
code is run so add error checking...
This will check all the docs in the passed folder not subfolders of the
passed folder.

Old Man
 

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