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
991 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

A little background as to how I came to I design this code: Around 5 years ago I designed an add-in that formatted Excel files to a corporate standard, applying different cell colours and font type depending on whether the cells contained inputs,…
Not long ago I saw a question in the VB Script forum that I thought would not take much time. You can read that question (Question ID  (http://www.experts-exchange.com/Programming/Languages/Visual_Basic/VB_Script/Q_28455246.html)28455246) Here (http…
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…
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.

910 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

24 Experts available now in Live!

Get 1:1 Help Now