+ Reply to Thread
Results 1 to 3 of 3

Perform action on every workbook in a directory

  1. #1
    Registered User
    Join Date
    04-20-2004
    Posts
    17

    Perform action on every workbook in a directory

    Hello everyone,

    All of my workbooks in a directory have the same format. As it stands now, I open each one manually, and have my code extract the data from a sheet and aggregate it on the appropriate sheet of my report file.

    All I am looking to do is open each workbook, perform my macro, close the work book and open the next. I figure to do this correctly, the macro would have to count the workbooks in the directory (there are 51), and from 1-n, open work book, call my macro, close workbook, next n.

    Can someone show me how to do this, if it is is even possible?

    Many thanks in advance,

    Brock

  2. #2
    Valued Forum Contributor tony h's Avatar
    Join Date
    03-14-2005
    Location
    England: London and Lincolnshire
    Posts
    1,187
    Sub a()
    Dim wkb As Workbook
    Dim strPath As String
    Dim strFile As String

    strPath = "C:\myfiles\" your path
    strFile = Dir(strPath & "*.xls")
    Do While strFile <> ""
    Set wkb = Workbooks.Open(strPath & strFile)
    'do your bits
    wkb.Close savechanges:=True
    strFile = Dir()
    Loop
    MsgBox "done"
    End Sub

    regards

  3. #3
    Registered User
    Join Date
    04-20-2004
    Posts
    17
    Thats perfect, thank you very much.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1