?
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
Medium Priority
?
1,118 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 23

Accepted Solution

by:
Ejgil Hedegaard earned 1200 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

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

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

After seeing numerous questions for Dynamic Data Validation I notice that most have used Visual Basic to solve the problem. This suggestion is purely formula based and can be used in multiple rows.
If you need to forecast numbers -- typically for finance -- the Windows and Mac versions of Excel 2016 have a basket of tools to get the job done.
This Micro Tutorial will demonstrate the scrolling table in Microsoft Excel using the INDEX function.
This Micro Tutorial demonstrates in Microsoft Excel how to consolidate your marketing data by creating an interactive charts using form controls. This creates cool drop-downs for viewers of your chart to choose from.

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