VBA gets files for all files and sub-files directories under a folder

Source: Internet
Author: User

<strong>vba get files for all files, or sub-files directories under a folder </strong>
'-------------------------------------------' Get all the Excel files under a folder '-------------------------------------------Sub  Getexcelfile (Sfolderpath as String) on Error Resume Nextdim F as StringDim file () as StringDim xk = 1ReDim file (1) file (1) = Sfolderpath & "\" F = Dir (file (1) & "*.xlsx") ' wildcard ' * * denotes all files, *.xlsx Excel file do Until f = "" Range ("a" & x) = f Range ("a" & X). Hyperlinks.add Anchor:=range ("a" & X), Address:=file (i) & F, Texttodisplay:=f x = x + 1 f = Dir L Oopend Sub '-------------------------------------------' Get all files and subdirectories under a folder '-------------------------------------------sub Getallfile (Sfolderpath as String) ' Columns (1). Deleteon Error Resume Nextdim F as StringDim file () As StringDim I, k, xx = 1i = 1k = 1ReDim file (1 to i) file (1) = Sfolder Path & "\"--Get all subdirectories do Until i > k f = Dir (file (i), vbdirectory) do Until f = "" If InStr (F, ".") = 0 Then k = k + 1 ReDim PreserveFile (1 to K) file (k) = File (i) & F & "\" End If f = Dir Loop i = i       + 1Loop '--Get all the files under all subdirectories for i = 1 to k f = Dir (file (i) & "*. *") ' wildcard characters * * For all files, *.xlsx Excel file do Until f = "" ' Range ("a" & x) = f Range ("a" & X). Hyperlinks.add Anchor:=range ("a" & X), Address:=file (i) & F, Texttodisplay:=f x = x + 1 f = Dir L Oopnextend Sub

VBA gets files for all files and sub-files directories under a folder

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.