excel vba get list of Excel files in a folder

'VBA function to return an array of file names from a folder:

Public Function GetFiles(sPath$, Optional sFilter$ = "*.*")
  	Dim p&, f$, s$: s = Space(1e6)        
    f = Dir(sPath & _
        String(Abs(Right(sPath, 1) <> "\"), "\") & sFilter)
        Do While Len(f)
            Mid(s, p + 1, Len(f) + 1) = f & vbLf
            p = p + Len(f) + 1
            f = Dir
        Loop
    GetFiles = Split(Left(s, p - 1), vbLf)
End Function

'--------------------------------------------------------------------

ExcelFiles = GetFiles("C:\temp", "*.xls*")
MsgBox LBound(ExcelFiles)  '<--displays: 0

Are there any code examples left?
Create a Free Account
Unlock the power of data and AI by diving into Python, ChatGPT, SQL, Power BI, and beyond.
Sign up
Develop soft skills on BrainApps
Complete the IQ Test
Relative searches
read all folder vba excel read all files in folder vba excel get all file names in folder to excel vba excel vba directory list how to get each excel file names in folder using vba open all excel files in a folder vba excel vba list files in folder vba directory listing excel vba list of files in folder excel vba list excel files in folder excel vba get all filenames from folder path excel vba get filename all files from folder vba code to get file names in a folder vba names of files in folder vba collect the name of a file vba list files in folder get file name from folder in vba get filename from folder vba get folder in which excel document is in VBA vba dir get all files excel vba list files in directory macro to list files in a folder get all files from folder using vba Excel VBA script to list Files in folders list files in folder using vba vba excel function find file names in a folder with waildcards filesitem object get all files in folder vba get list of files in folder vba print files list in vba all files in directory vba vba code for listing files in a folder vba /A-D /O-D /TW ;list files VBA to find list of any files open VBA to find list of files open how to idetify files inside a folder in vba excel vba get all files in folder vba show files in folder excel vba get file names from folder vba getfiles in folder vba get list of files in folder excel vba make word from bytes vba read all filenames in folder list all files in directory excel vba VBA code to list filenames in a directory read a file name inside a folder vba vba get list of files in a folder excelvba get list of files in a folder excel-vba get list of files in a folder excel-vba get list of Excel files in a folder excelvba get list of Excel files in a folder vba get list of Excel files in a folder excel vba get list of Excel files in a folder
Made with love
This website uses cookies to make IQCode work for you. By using this site, you agree to our cookie policy

Welcome Back!

Sign up to unlock all of IQCode features:
  • Test your skills and track progress
  • Engage in comprehensive interactive courses
  • Commit to daily skill-enhancing challenges
  • Solve practical, real-world issues
  • Share your insights and learnings
Create an account
Sign in
Recover lost password
Or log in with

Create a Free Account

Sign up to unlock all of IQCode features:
  • Test your skills and track progress
  • Engage in comprehensive interactive courses
  • Commit to daily skill-enhancing challenges
  • Solve practical, real-world issues
  • Share your insights and learnings
Create an account
Sign up
Or sign up with
By signing up, you agree to the Terms and Conditions and Privacy Policy. You also agree to receive product-related marketing emails from IQCode, which you can unsubscribe from at any time.
Creating a new code example
Code snippet title
Source