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
956 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
Comment Utility
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
Comment Utility
Works great, thank you!!!!
0
 
LVL 27

Expert Comment

by:Glenn Ray
Comment Utility
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
Comment Utility
Ack...slow on the draw.  Should have refreshed before posting.  Cool to see another method applied, however.

-Glenn
0

Featured Post

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

Introduction While answering a recent question (http:/Q_27311462.html), I created an alternative function to the Excel Concatenate() function that you might find useful.  I tested several solutions and share the results in this article as well as t…
This article will guide you to convert a grid from a picture into Excel format using Microsoft OneNote and no other 3rd party application.
The viewer will learn how to simulate a series of sales calls dependent on a single skill level and learn how to simulate a series of sales calls dependent on two skill levels. Simulating Independent Sales Calls: Enter .75 into cell C2 – “skill leve…
The viewer will learn how to create a normally distributed random variable in Excel, use a normal distribution to simulate the return on an investment over a period of years, Create a Monte Carlo simulation using a normal random variable, and calcul…

744 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

17 Experts available now in Live!

Get 1:1 Help Now