+ Reply to Thread
Results 1 to 2 of 2

For each workbook in Folder

  1. #1
    Forum Contributor
    Join Date
    10-03-2005
    Posts
    183

    For each workbook in Folder

    How can I open all excel workbooks in a folder which starts with "BFR"...

    Something like this:


    For each wb in folder("X")
    if filename = "BFR*" then
    end if
    Loop


    how do I write this correct?


    Thanks for the help

  2. #2
    Bob Phillips
    Guest

    Re: For each workbook in Folder

    Maybe

    Sub ProcessFiles()
    Dim FSO As Object
    Dim i As Long
    Dim sFolder As String
    Dim fldr As Object
    Dim Folder As Object
    Dim file As Object
    Dim Files As Object


    Set FSO = CreateObject("Scripting.FileSystemObject")


    sFolder = "C:\myTest\myTest"
    'sFolder = "c:\my documents\excel\test"
    If sFolder <> "" Then
    Set Folder = FSO.GetFolder(sFolder)


    Set Files = Folder.Files
    For Each file In Files
    If Left(file.Name,3) = "BFR" Then
    Workbooks.Open Filename:=file.Path
    With ActiveWorkbook
    .SaveAs Left(.FullName, Len(.FullName) - 4), _
    FileFormat:=xlTextMac
    .Close savechanges:=False
    End With
    End If
    Next file


    End If ' sFolder <> ""


    End Sub


    --

    HTH

    Bob Phillips

    (remove nothere from the email address if mailing direct)

    "Ctech" <[email protected]> wrote in
    message news:[email protected]...
    >
    > How can I open all excel workbooks in a folder which starts with
    > "BFR"...
    >
    > Something like this:
    >
    >
    > For each wb in folder("X")
    > if filename = "BFR*" then
    > end if
    > Loop
    >
    >
    > how do I write this correct?
    >
    >
    > Thanks for the help
    >
    >
    > --
    > Ctech
    >
    >
    > ------------------------------------------------------------------------
    > Ctech's Profile:

    http://www.excelforum.com/member.php...o&userid=27745
    > View this thread: http://www.excelforum.com/showthread...hreadid=505288
    >




+ 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