<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