MyHanhCB
New Member
- Joined
- Feb 20, 2023
- Messages
- 30
- Office Version
- 2016
- Platform
- Windows
Hello everyone on the forum!
I found on google a function as follows.
I do the following search.....
But the value after my search gets both
"CX123_E44a.pdf, CX123_E44b.pdf,CX123_E44aa.pdf,CX123_E44bb.pdf,CX123_E44aaa.pdf,CX123_E44bbb.pdf"
I want the find value to be just "CX123_E44aa.pdf,CX123_E44bb.pdf"
Look forward to the help
I found on google a function as follows.
VBA Code:
Function FilesFoldersList(ByVal RootFolder As String, ByVal ListType As Boolean, _
ByVal Search As String, ByVal InSub As Boolean)
Dim i As Long, fso As Object
Set fso = CreateObject("Scripting.FileSystemObject")
Dim sComm As String, tmp As String, str As String, tmpFile ', arrA
On Error Resume Next
If Right(RootFolder, 1) <> "\" Then RootFolder = RootFolder & "\"
str = """" & RootFolder & IIf(ListType, Search, "") & """"
With fso
tmpFile = .GetTempName
sComm = "DIR " & str & " /ON /B /A" & IIf(ListType, "-", "") & "D-S" & IIf(InSub, "/S", " ") & " >" & tmpFile
CreateObject("Wscript.Shell").Run "cmd /u /c " & sComm, 0, True
With .OpenTextFile(tmpFile, 1, , -2)
tmp = Trim(.ReadAll)
If Right(tmp, 2) = vbCrLf Then tmp = Left(tmp, Len(tmp) - 2)
If Len(tmp) Then
If InSub = False Then tmp = RootFolder & Replace(tmp, vbCrLf, vbCrLf & RootFolder)
FilesFoldersList = Split(tmp, vbCrLf)
End If
'-------------------------------------------------
.Close
End With
End With
Kill tmpFile
End Function
I do the following search.....
Code:
Sub test
Dim fldPath as string, arr, db as variant
fldPath = "C:\Users\toanndq.VBD\Desktop\New folder (3)"
Arr = FilesFoldersList(fldPath, True, "CX*44??.pdf", True)
For each db in arr
Debug.Print db
Next
End sub
"CX123_E44a.pdf, CX123_E44b.pdf,CX123_E44aa.pdf,CX123_E44bb.pdf,CX123_E44aaa.pdf,CX123_E44bbb.pdf"
I want the find value to be just "CX123_E44aa.pdf,CX123_E44bb.pdf"
Look forward to the help
Last edited: