+ Reply to Thread
Results 1 to 3 of 3

Need to perform the same macro to multiple xls files in VB2005 Exp

  1. #1
    Jhcorsair
    Guest

    Need to perform the same macro to multiple xls files in VB2005 Exp

    How do I "loop" through multiple files in a folder to perform the same task
    to each file?

  2. #2
    voodooJoe
    Guest

    Re: Need to perform the same macro to multiple xls files in VB2005 Exp

    try something like

    Sub x()

    strFolder = "c:\"

    If Right(strFolder, 1) <> "\" Then strFolder = strFolder & "\"
    f = Dir(strFolder & "*.xls")

    Do While f <> ""
    Set wb = Workbooks.Open(strFolder & f)
    Debug.Print wb.Worksheets(1).Name 'do stuff - wb will be the
    workbook object
    wb.Close
    f = Dir()
    Loop

    Set wb = Nothing
    End Sub

    don't forget to turn off screen updating

    rgds - voodooJoe


    "Jhcorsair" <Jhcorsair@discussions.microsoft.com> wrote in message
    news:F43CC4B3-81B9-4EF3-9002-D0F561A1CE1D@microsoft.com...
    > How do I "loop" through multiple files in a folder to perform the same
    > task
    > to each file?




  3. #3
    voodooJoe
    Guest

    Re: Need to perform the same macro to multiple xls files in VB2005 Exp

    try something like

    Sub x()
    strFolder = "c:\"
    strFileType = "xls"

    If Right(strFolder, 1) <> "\" Then strFolder = strFolder & "\"
    f = Dir(strFolder & "*." & strFileType)

    Do While f <> ""
    Set wb = Workbooks.Open(strFolder & f)
    Debug.Print wb.Worksheets(1).Name 'do stuff - wb will be the
    workbook object
    wb.Close
    f = Dir()
    Loop

    Set wb = Nothing
    End Sub

    remember to turn off screen updating

    rgds- voodooJoe


    "Jhcorsair" <Jhcorsair@discussions.microsoft.com> wrote in message
    news:F43CC4B3-81B9-4EF3-9002-D0F561A1CE1D@microsoft.com...
    > How do I "loop" through multiple files in a folder to perform the same
    > task
    > to each file?




+ 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