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,025 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
  • 2
4 Comments
 
LVL 21

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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Improved? Move/Copy Add-in Replacement - How to avoid the annoying, “A formula or sheet you want to move or copy contains the name XXX, which already exists on the destination worksheet.” David Miller (dlmille)  It was one of those days… I wa…
This tutorial explains how to create a series of drop-down lists that are dependent upon prior selections to guide (“force”) the user to make the correct selection and reduce data errors within Microsoft Excel. Excel 2010 was used for this tutorial;…
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…
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

813 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now