Consulting

Results 1 to 5 of 5

Thread: Act on files in directory

  1. #1

    Act on files in directory

    Howdy,

    I do not have much experience above the file level. I have a bunch of files in one directory (different versions of the same file) and just need to run a "refresh all" in them once a month.

    Can someone help me out?

    Thanks


  2. #2
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    REfresh what?
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  3. #3
    i have some data queries and a pivottable. I can figure that out. I just need the right loop to go through the files.

    Thanks

  4. #4
    VBAX Guru Kenneth Hobs's Avatar
    Joined
    Nov 2005
    Location
    Tecumseh, OK
    Posts
    4,956
    Location
    You should test this with just a few files first. Of course you need to change FileFolder and FileSpec values to suit your needs.

    [VBA]Sub DirFiles()
    Dim FileName As String, FileSpec As String, FileFolder As String
    Dim wb As Workbook

    FileFolder = ThisWorkbook.Path & "\"
    FileSpec = FileFolder & "*.xl*"

    FileName = Dir(FileSpec)
    If FileName = "" Then Exit Sub

    ' Loop until no more matching files are found
    Do While FileName <> ""
    If IsWorkbookOpen(FileName) = False Then
    Set wb = Workbooks.Add(FileFolder & FileName)
    DoEvents
    wb.Close True
    End If
    FileName = Dir()
    Loop

    End Sub


    Function IsWorkbookOpen(stName As String) As Boolean
    Dim Wkb As Workbook
    On Error Resume Next ' In Case it isn't Open
    Set Wkb = Workbooks(stName)
    If Not Wkb Is Nothing Then IsWorkbookOpen = True
    'Boolean Function assumed To be False unless Set To True
    End Function
    [/VBA]

  5. #5
    Thanks! I can work with this.

Posting Permissions

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