Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Word Document Properties

Status
Not open for further replies.

nberryman

Instructor
Jun 1, 2002
556
GB
I have the following code that loops through each file in a folder and outputs the Filename thereby giving me a list of all the files in a folder.

Sub ListFiles()
'
' ListFiles Macro
'
Dim Filearray() As String, ffile As String, MyFolder As String, count As Integer
MyFolder = ActiveDocument.Path
ffile = Dir(MyFolder & "\*.doc")
count = 1

Selection.WholeStory
Selection.Delete Unit:=wdCharacter, count:=1

Do While ffile <> &quot;&quot;

If ffile <> &quot;.&quot; And ffile <> &quot;..&quot; Then
ReDim Preserve Filearray(count)
Filearray(count) = ffile
count = count + 1
ffile = Dir()
Selection.TypeText ffile
Selection.TypeText Chr(13)
Selection.TypeText Chr(13)

End If

Loop

Selection.TypeText count & &quot; Files in &quot; & MyFolder

'Documents.Add.Content.Filearray

End Sub
*******************************************

This works fine but what I would now like to do is to add some of the document properties to the list as well something like this

Name Created Date Last edited
Policy.doc 1/1/2002 12/5/2002
Users.doc 12/2/2002 23/4/2002

And so on. How do I achieve this

Many thanks for your assistance


Neil Berryman
IT Trainer
neil_berryman@btopenworld.com
 
Check out the online help on the FileLen and FileDateTime functions.

Also check out the DateLastModified property of the Scripting object. A good example is provided in the Access 2000 VBA online help under the DateLastModified topic. I reproduce a bit of it below:

Sub ShowFileAccessInfo(filespec)
Dim fs, f, s
Set fs = CreateObject(&quot;Scripting.FileSystemObject&quot;)
Set f = fs.GetFile(filespec)
s = UCase(filespec) & vbCrLf
s = s & &quot;Created: &quot; & f.DateCreated & vbCrLf
s = s & &quot;Last Accessed: &quot; & f.DateLastAccessed & vbCrLf
s = s & &quot;Last Modified: &quot; & f.DateLastModified
MsgBox s, 0, &quot;File Access Info&quot;
End Sub

You need to obviously ensure that the Scripting object is referenced.

Hope this helps,

Cheers,

Steve Lewy
Solutions Developer
steve@lewycomputing.com.au
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top