Dear All,
I'm trying to move file to proper folder which has same key word.
the dir function loose looping file name.
Please let me know for best result.
Public Sub DOCsort() Dim REF As String, FDpath As String, Pool As String, REFfolder As String, DOCpath As String, LoopFile As String Pool = "C:\Users\chris\Documents\TEST" FDpath = "C:\Users\chris\Documents\TEST\FD" LoopFile = Dir(Pool & "*"): 'find matching file Do While LoopFile <> "" REF = REFextractor(LoopFile) Select Case Len(REF) Case Is > 5 'complete number REFfolder = Dir(FDpath & "*" & REF, vbDirectory) & "" Name Pool & LoopFile As FDpath & REFfolder & LoopFile End Select 'Name Pool & LoopFile As FDpath & REFfolder & LoopFile LoopFile = Dir Loop End Sub Public Function REFextractor(str) Dim x As Integer, ext As String, txt As String If InStr(Right(str, 5), ".") Then ext = Right(Right(str, 5), Len(Right(str, 5)) - InStr(Right(str, 5), ".") + 1) txt = Replace(str, ext, "") End If txt = Replace(Replace(Replace(txt, "_", " "), "-", " "), ".", " ") REFextractor = Trim(Right(txt, Len(txt) - InStr(txt, " "))) End Function



Reply With Quote

