entwined
01-17-2012, 09:43 PM
Hello troops, need some help here please. :)
I need a Word macro that will list all the files with their filesizes and pages in a single directory. The directory only contains word files (.doc, .docx) and nothing else.
I have created one (code below but i don't know if I've done it right). The filenames and filesizes are fine but the pages always displays "3" even if the word files' pages aren't really 3 pages.
The value of the input box will be the path. It'll just be pasted there. Please help I really need this. Thanks alot.... :)
============
Sub listpageandsize()
invFiles = InputBox("Input path of the files:", "Input Path")
Selection.HomeKey unit:=wdStory
Selection.TypeText "Filename" & vbTab
Selection.TypeText "Size" & vbTab
Selection.TypeText "No. of Pages" & vbCrLf
On Error Resume Next
Set fso = CreateObject("scripting.filesystemobject")
Set fld = fso.GetFolder(invFiles)
For Each fil In fld.Files
lFname = fil.Name
lSize = fil.Size
Set objWord = CreateObject("Word.Application")
Set objDoc = objWord.Documents.Open(invFiles & "\" & lFname)
lPages = objDoc.BuiltInDocumentProperties(wdPropertyPages)
objDoc.Save
objWord.Quit
Selection.EndKey unit:=wdStory
Selection.TypeText lFname & vbTab
Selection.TypeText lSize & vbTab
Selection.TypeText lPages & vbCrLf
Next
End Sub
I need a Word macro that will list all the files with their filesizes and pages in a single directory. The directory only contains word files (.doc, .docx) and nothing else.
I have created one (code below but i don't know if I've done it right). The filenames and filesizes are fine but the pages always displays "3" even if the word files' pages aren't really 3 pages.
The value of the input box will be the path. It'll just be pasted there. Please help I really need this. Thanks alot.... :)
============
Sub listpageandsize()
invFiles = InputBox("Input path of the files:", "Input Path")
Selection.HomeKey unit:=wdStory
Selection.TypeText "Filename" & vbTab
Selection.TypeText "Size" & vbTab
Selection.TypeText "No. of Pages" & vbCrLf
On Error Resume Next
Set fso = CreateObject("scripting.filesystemobject")
Set fld = fso.GetFolder(invFiles)
For Each fil In fld.Files
lFname = fil.Name
lSize = fil.Size
Set objWord = CreateObject("Word.Application")
Set objDoc = objWord.Documents.Open(invFiles & "\" & lFname)
lPages = objDoc.BuiltInDocumentProperties(wdPropertyPages)
objDoc.Save
objWord.Quit
Selection.EndKey unit:=wdStory
Selection.TypeText lFname & vbTab
Selection.TypeText lSize & vbTab
Selection.TypeText lPages & vbCrLf
Next
End Sub