Solved

Open all workbooks with name in a particular pattern

Posted on 2013-06-05
2
300 Views
Last Modified: 2013-06-06
I have an ACCESS 2003 process that, when the user hits the Open button, it opens ALL Excel workbooks that have a particular name pattern.  I can open one, but I need to loop through the folder and open everyone with this pattern.

Private Sub cmdTodaysWorkbook_Click()
'/SS - Opens all workbook created with today's date.
        Dim xlApp As Excel.Application
        Dim wbk As Workbook
        Dim strExistingFileName As String
        Dim fld As Object
        Dim strSource As String

strExistingFileName = "\\SF1\User1\shared\ATMVisalosses\ATMVisaLossesTST_" & Format(Now, "mm-dd-yyyy") & ""

Set xlApp = New Excel.Application
xlApp.Visible = True



    For Each fld In strSource.SubFolders
            Set wbk = xlApp.Workbooks.Open(strExistingFileName & "*.xlsx")
            xlApp.Workbooks.Open (strExistingFileName & "*.xlsx")
    Next

xlApp.WindowState = xlMaximized
Set xlApp = Nothing

End Sub
0
Comment
Question by:ssmith94015
2 Comments
 
LVL 92

Accepted Solution

by:
Patrick Matthews earned 500 total points
ID: 39223640
Using late binding...



Private Sub cmdTodaysWorkbook_Click()
'/SS - Opens all workbook created with today's date.
    Dim xlApp As Object
    Dim strExistingFileName As String
    Dim fso As Object
    Dim fil As Object
    Dim fld As Object
    Dim sf As Object

    Const StartFolder As String = "\\SF1\User1\shared\ATMVisalosses\"

    strExistingFileName = "ATMVisaLossesTST_" & Format(Now, "mm-dd-yyyy")

    Set xlApp = CreateObject("Excel.Application"
    Set fso = CreateObject("Scripting.FileSystemObject")
    Set fld = fso.GetFolder(StartFolder)

    For Each fil In fld.Files
        If fil.Name Like strExistingFileName & "*.xlsx" Then
            xlApp.Workbooks.Open fil.Path
        End If
    Next

    For Each sf In fld.SubFolders
        For Each fil In sf.Files
            If fil.Name Like strExistingFileName & "*.xlsx" Then
                xlApp.Workbooks.Open fil.Path
            End If
        Next
    Next

    xlApp.Visible = True
    xlApp.WindowState = xlMaximized
    Set xlApp = Nothing
    Set fil = Nothing
    Set sf = Nothing
    Set fld = Nothing
    Set fso = Nothing

End Sub

Open in new window

0
 

Author Closing Comment

by:ssmith94015
ID: 39227489
Yes, it was getting around to the Like statement, I did not think it would work.

Sandra
0

Featured Post

Creating Instructional Tutorials  

For Any Use & On Any Platform

Contextual Guidance at the moment of need helps your employees/users adopt software o& achieve even the most complex tasks instantly. Boost knowledge retention, software adoption & employee engagement with easy solution.

Question has a verified solution.

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

Suggested Solutions

Access developers frequently have requirements to interact with Excel (import from or output to) in their applications.  You might be able to accomplish this with the TransferSpreadsheet and OutputTo methods, but in this series of articles I will di…
This article describes a method of delivering Word templates for use in merging Access data to Word documents, that requires no computer knowledge on the part of the recipient -- the templates are saved in table fields, and are extracted and install…
This Micro Tutorial will demonstrate how to use longer labels with horizontal bar charts instead of the vertical column chart.
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

733 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