Hello everyone,
I am trying to get a list of the excel files I have in a folder
I have found this function on google:
PublicFunction GetFilesDir(ByVal sPath AsString, _OptionalByVal sFilter AsString)AsString()
'dynamic array for names
Dim aFileNames()AsString
ReDim aFileNames(0)
Dim sFile AsString
Dim nCounter AsLong
If Right(sPath,1)<>"\"Then
sPath = sPath &"\"
EndIf
If sFilter =""Then
sFilter ="*.*"
EndIf
'call with path "initializes" the dir function and returns the first file
sFile = Dir(sPath & sFilter)
'call it until there is no filename returned
DoWhile sFile <>""
'store the file name in the array
aFileNames(nCounter)= sFile
'subsequent calls without param return next file
sFile = Dir
'make sure your array is large enough for another
nCounter = nCounter +1
If nCounter > UBound(aFileNames)Then
'preserve the values and grow by reasonable amount for performance
ReDimPreserve aFileNames(UBound(aFileNames)+255)
EndIf
Loop
'truncate the array to correct size
If nCounter < UBound(aFileNames)Then
ReDimPreserve aFileNames(0To nCounter -1)
EndIf
'return the array of file names
GetFilesDir = aFileNames()
EndFunction
Pretty dumb question, but how do I call the function? I have a type mismatch error every time I try.
Thank you all for your help!