Results 1 to 2 of 2

Thread: VBA for Excel Help- I am lost

  1. #1

    Thread Starter
    New Member
    Join Date
    Aug 2000
    Location
    Minneapolis
    Posts
    12

    Question

    In excel I am needing to open all the files in a specified folder called TLResults that is on the C:drive. and also list all these file names in a range on sheet 1 starting on cell A1 on the excel document that I am useing when I start the macro.

    I have been looking at the code on other posts but it doesnt seen to translate to excel vba, or at least not to me.

    Any help on how to write this would be greatly appreciated.

    Douglas

  2. #2
    I'm about to be a PowerPoster! Joacim Andersson's Avatar
    Join Date
    Jan 1999
    Location
    Sweden
    Posts
    14,649
    Here's a Excel VBA macro that will do just that:
    Code:
    Sub OpenAllFiles()
        Dim sFile As String
        Dim wrkBook As Workbook
        Dim iCount%
        Const sPath As String = "c:\TLResults\"
        
        Set wrkBook = ActiveWorkbook
        sFile = Dir(sPath & "*.xls")
        Do While Len(sFile)
            iCount = iCount + 1
            Workbooks.Open sPath & sFile
            wrkBook.Activate
            wrkBook.Sheets(1).Activate
            Range("A" & iCount).Value = sPath & sFile
            sFile = Dir
        Loop
    End Sub
    Good luck!

Posting Permissions

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



Click Here to Expand Forum to Full Width