Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Open all workbooks with name in a particular pattern

Posted on 2013-06-05
2
Medium Priority
?
303 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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

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…
Microsoft Access is a place to store data within tables and represent this stored data using multiple database objects such as in form of macros, forms, reports, etc. After a MS Access database is created there is need to improve the performance and…
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…

618 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