?
Solved

Search the selected directory and list all folders and files created from 3 days ago until today.

Posted on 2016-11-01
6
Medium Priority
?
39 Views
Last Modified: 2016-11-02
I need help,

i need VBA to go through all folders and sub-folders of selected directory and list all folders and files which their creation date falls between now and 3 days ago.

thanks vert much.
0
Comment
Question by:excelismagic
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
6 Comments
 
LVL 52

Expert Comment

by:Rgonzo1971
ID: 41868868
Hi,

pls try

Sub Macro()
strYourFolder = "C:\YourFolder"
Set oFS = CreateObject("Scripting.FileSystemObject")
Set objShell = CreateObject("WScript.Shell")
Set objExecObject = objShell.Exec("cmd /c Dir """ & strYourFolder & "\*"" /s /b")
Do While Not objExecObject.StdOut.AtEndOfStream
    strtext = objExecObject.StdOut.ReadLine()
    If oFS.FolderExists(strtext) Then
        If oFS.GetFolder(strtext).DateCreated > Date - 3 Then
            strFilesList = strtext & vbCrLf & strFilesList
        End If
    Else
        If oFS.GetFile(strtext).DateCreated > Date - 3 Then
            strFilesList = strtext & vbCrLf & strFilesList
        End If
    End If
Loop
End Sub

Open in new window

0
 
LVL 3

Author Comment

by:excelismagic
ID: 41868906
thanks Rgonzo,

but it return error 53 File not Found.

although, i have folders that created just now and its name should be listed in excel. but i get the error.
0
 
LVL 52

Expert Comment

by:Rgonzo1971
ID: 41868918
What is the value of strtext at the error ( Which line as well)
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
LVL 3

Author Comment

by:excelismagic
ID: 41868970
it was giving error in line If oFS.GetFile(strtext).DateCreated > Date - 3 Then  which i solved it but removing the long named files and the error disappeared.  

thanks.

how do i put this now into excel sheet,

i used Debug.Print strFilesList  and it listed the details into immediate window.
but i dont know how to put the details instead of immediate window to activeworksheet.
0
 
LVL 52

Accepted Solution

by:
Rgonzo1971 earned 2000 total points
ID: 41869617
then try
Sub Macro()
strYourFolder = "c:\YourFolder"
Set oFS = CreateObject("Scripting.FileSystemObject")
Set objShell = CreateObject("WScript.Shell")
Set objExecObject = objShell.Exec("cmd /c Dir """ & strYourFolder & "\*"" /s /b")
Do While Not objExecObject.StdOut.AtEndOfStream
    strtext = objExecObject.StdOut.ReadLine()
    If oFS.FolderExists(strtext) Then
        If oFS.GetFolder(strtext).DateCreated > Date - 3 Then
            strFilesList = strtext & vbCrLf & strFilesList
        End If
    Else
        If oFS.GetFile(strtext).DateCreated > Date - 3 Then
            strFilesList = strtext & vbCrLf & strFilesList
        End If
    End If
Loop
aFilesList = Split(strFilesList, vbCrLf)
Workbooks.Add
Range("A1").Resize(UBound(aFilesList) + 1) = WorksheetFunction.Transpose(aFilesList)
End Sub

Open in new window

0
 
LVL 3

Author Comment

by:excelismagic
ID: 41869730
thanks very much Rgonzo.
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Do you use a spreadsheet like Microsoft's Excel?  Have you ever wanted to link out to a non excel file on your computer or network drive?  This is the way I found to do it!
The Windows Phone Theme Colours is a tight, powerful, and well balanced palette. This tiny Access application makes it a snap to select and pick a value. And it doubles as an intro to implementing WithEvents, one of Access' hidden gems.
Graphs within dashboards are meant to be dynamic, representing data from a period of time that will change each time the dashboard is updated with new data. Rather than update each graph to point to a different set within a static set of data, t…
This Micro Tutorial will demonstrate how to create pivot charts out of a data set. I also added a drop-down menu which allows to choose from different categories in the data set and the chart will automatically update.

801 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question