Results 1 to 2 of 2
  1. #1
    Gold Lounger
    Join Date
    Jan 2004
    Location
    Italy
    Posts
    3,245
    Thanks
    0
    Thanked 0 Times in 0 Posts

    loop workbook in dir (2000)

    I want to loop a dir and open all xls without condition MASTER....
    But code go in error in:
    For Each WB In F

    Option Explicit
    Sub LOOP_WORKBOOK()

    Dim WS As Worksheet
    Dim WB As Workbook
    Dim F As String, FLPATH As String, MASTER As String

    FLPATH = "LEL_VECCHIO"
    If FLPATH = False Then Exit Sub
    FLPATH = Left(FLPATH, InStrRev(FLPATH, ""))

    Application.ScreenUpdating = False
    Application.DisplayAlerts = False
    Application.EnableEvents = False

    F = Dir(FLPATH & "*.xls")

    For Each WB In F
    MASTER = Mid(WS.Name, 11, 8)
    If Not MASTER = "SBILANCI" Then
    Set WB = Workbooks.Open(F)
    Application.StatusBar = "TROVATO " & WB.Name
    End If
    Next

    Application.EnableEvents = True
    Application.StatusBar = False
    Application.DisplayAlerts = True
    Application.ScreenUpdating = True

    End Sub

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: loop workbook in dir (2000)

    Dir returns a string, not a collection. If you do a search in this forum, you'll find many examples of using Dir.

Posting Permissions

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