Solved

Need Excel macro to open all files in specific folder that have a Created Date of the current system date

Posted on 2014-07-30
4
1,098 Views
Last Modified: 2014-07-30
I need an Excel macro that looks in a specific folder, and then opens any/all Excel files that were created on whatever the current date is.

Thanks!!!
0
Comment
Question by:BEBaldauf
[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
  • 2
4 Comments
 
LVL 22

Accepted Solution

by:
Ejgil Hedegaard earned 300 total points
ID: 40230042
Try this.
Select a folder when asked, and all Excel files in the folder from current day are opened.

Option Explicit

Sub OpenExcelFilesFromToday()
Dim Folder As String, FileToOpen As String
    Application.ScreenUpdating = False
    Folder = SelectFolder("Select Folder")
    If Folder = vbNullString Then
        MsgBox "No Folder Selected, Program Stop"
        End
    End If
    
    FileToOpen = Dir(Folder + "\*.xls*")
    Do While FileToOpen <> ""
        If DateValue(FileDateTime(Folder + "\" + FileToOpen)) = DateValue(Now) And FileToOpen <> ThisWorkbook.Name Then
            Application.EnableEvents = False
                Application.Workbooks.Open Filename:=Folder + "\" + FileToOpen
            Application.EnableEvents = True
        End If
        FileToOpen = Dir
    Loop
End Sub

Function SelectFolder(Title As String) As String
    Dim V As Variant
    With Application.FileDialog(msoFileDialogFolderPicker)
        .Title = Title
        .Show
        On Error Resume Next
        Err.Clear
        V = .SelectedItems(1)
        If Err.Number <> 0 Then
            V = vbNullString
        End If
    End With
    SelectFolder = CStr(V)
End Function

Open in new window

Open-Excel-files-from-today.xlsm
0
 

Author Closing Comment

by:BEBaldauf
ID: 40230089
Works great, thank you!!!!
0
 
LVL 27

Expert Comment

by:Glenn Ray
ID: 40230096
Hi,  the following subroutine - along with a userform that will let you browse and locate a specific folder - will open all the Excel files (*.xls*) in that folder whose creation date is the current (today's) date.
Sub Open_Current_Files()
    Dim fso, fld As Object
    Dim strPath, strFile As String
    Dim wbk As Workbook
    Dim dtCreationDate As Date
    Application.ScreenUpdating = False

    frmGetFileXLS.Show
    If Not (boolGotFile) Then Exit Sub
    strPath = frmGetFileXLS.txtPath

    Set fso = CreateObject("Scripting.FileSystemObject")
    Set fld = fso.GetFolder(strPath)

    strFile = Dir(strPath & "\*.xls*")
    
    Do While strFile <> ""
        Set wbk = Workbooks.Open(Filename:=strPath & "\" & strFile, UpdateLinks:=0, AddToMRU:=False)
        dtCreationDate = wbk.BuiltinDocumentProperties("Creation Date")
        If Round(dtCreationDate, 0) <> Round(Now(), 0) Then
            wbk.Close savechanges:=False
        End If
        strFile = Dir
    Loop
 End Sub

Open in new window


I've attached an example file that will run this; just click the macro button, browse to the folder, click any Excel file, then click OK to begin.  It will open each file in the folder, but close those with creation dates earlier than the current date, leaving the rest open.

Regards,
-Glenn
EE-Q-28487107.xlsm
0
 
LVL 27

Expert Comment

by:Glenn Ray
ID: 40230099
Ack...slow on the draw.  Should have refreshed before posting.  Cool to see another method applied, however.

-Glenn
0

Featured Post

Technology Partners: 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

This code takes an Excel list of URL’s and adds a header titled “URL List”. It then searches through all URL’s in column “A”, looking for duplicates. When a duplicate is found, it is moved to the top of the list. The duplicate URL’s are then highlig…
You need to know the location of the Office templates folder, so that when you create new templates, they are saved to that location, and thus are available for selection when creating new documents.  The steps to find the Templates folder path are …
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 demonstrate the bugs in Microsoft Excel for Mac with Pivot Charts.

696 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