I used the Macro from the Word MVP site to insert the names of files in a folder into my Word document. What I want to do now is limit the files that are inserted by a date range. I can create a userform that I can put a start date and finish date in but I dont know how to bring in the creation date of the files. This is what Ive done so far: Sub InsertNamesOfFilesInAFolder() Dim MyPath As String Dim MyName As String MyPath = "H:\Word" MyName = "S:\Requisitions" 'let user select a path With Dialogs(wdDialogCopyFile) If .Display() <> -1 Then Exit Sub MyPath = .Directory End With 'strip quotation marks from path If Len(MyPath) = 0 Then Exit Sub If Asc(MyPath) = 34 Then MyPath = Mid$(MyPath, 2, Len(MyPath) - 2) End If 'get files from the selected path 'and insert them into the doc MyName = Dir$(MyPath & "*.*") Do While MyName <> "" Selection.InsertAfter MyName & vbCr MyName = Dir Loop 'collapse the selection Selection.Collapse wdCollapseEnd End Sub Any help would be awesome! Thank you in advance! -Josh
The Dir function as used can not get the creation date of the files. Use FileSystemObject instead. Josh wrote: >I used the Macro from the Word MVP site to insert the names of files >in a folder into my Word document. What I want to do now is limit the >files that are inserted by a date range. I can create a userform that >I can put a start date and finish date in but I donât know how to >bring in the creation date of the files. This is what Iâve done so >far: > >Sub InsertNamesOfFilesInAFolder() > >Dim MyPath As String >Dim MyName As String > >MyPath = "H:\Word" >MyName = "S:\Requisitions" > >'let user select a path >With Dialogs(wdDialogCopyFile) > If .Display() <> -1 Then Exit Sub > MyPath = .Directory >End With > >'strip quotation marks from path > >If Len(MyPath) = 0 Then Exit Sub > >If Asc(MyPath) = 34 Then > MyPath = Mid$(MyPath, 2, Len(MyPath) - 2) >End If > >'get files from the selected path >'and insert them into the doc >MyName = Dir$(MyPath & "*.*") >Do While MyName <> "" > Selection.InsertAfter MyName & vbCr > MyName = Dir >Loop > >'collapse the selection >Selection.Collapse wdCollapseEnd > >End Sub > >Any help would be awesome! Thank you in advance! > >-Josh -- Message posted via OfficeKB.com http://www.officekb.com/Uwe/Forums.aspx/word-programming/200810/1