Ureader.com  
Microsoft software help and Community
   home   |   control panel login   |   archive   |  
 
Word
application.errors
conversions
docmanagement
drawing.graphics
formatting.longdocs
international
internet.assistant
mail
mailmerge.fields
menustoolbars
newusers
numbering
oleinterop
pagelayout
printingfonts
setup.networking
spelling.grammar
tables
vba.addins
vba.beginners
vba.customization
vba.general
vba.userforms
web.authoring
word6-7macros
word97vba
  
 
date: Fri, 3 Oct 2008 07:52:14 -0700 (PDT),    group: microsoft.public.word.vba.general        back       


Return files from a date range   
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
date: Fri, 3 Oct 2008 07:52:14 -0700 (PDT)   author:   Josh

Re: Return files from a date range   
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
date: Fri, 03 Oct 2008 17:36:07 GMT   author:   fumei via OfficeKB.com u37563@uwe

Google
 
Web ureader.com


    COPYRIGHT 2007, YARDI TECHNOLOGY LIMITED, ALL RIGHT RESERVE  |   contact us