?
Solved

Open all workbooks with name in a particular pattern

Posted on 2013-06-05
2
Medium Priority
?
302 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
[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 Comments
 
LVL 93

Accepted Solution

by:
Patrick Matthews earned 2000 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

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Question has a verified solution.

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

This article describes how to use a set of graphical playing cards to create a Draw Poker game in Excel or VB6.
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 how to use a scrolling table in Microsoft Excel using the INDEX function.
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

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