Hi All. Any kind of help would be really appreciated. I have below VBA project which moves files from one folder to Master folder based on the specific identification number which is "T" and then numbers. For example. T98 Contract, T12984 Contract, T 92 Lease. below is the sample of file names,
T1525 FULLY SIGNED LEASE_9263pdf
T1525_FULLY SIGNED LEASE_9263pdf
T 1525 TEMP RENEWAL_8233pdf
eT920_Principal Lease Agreement_10542pdf
eT920_RENEWAL AGREEMENT_452TIF
The current code moves the file based on initial 13 character however i want to change it to move the files based on the contract number starting from T.
I think i need to only change the StrDestFolder Code. I tried to change the line to below but its not working.
" strDestFolder = strMasterFolder & "\" & LEFT(MID(objMyFile.Name,FIND(""T"",objMyFile.Name),FIND(""_"",objMyFile.Name)-FIND(""T"",objMyFile.Name)),6)"
Option Explicit
Sub MoveFiles()
'This Macro will move the files from SourcePath Folder to MasterFolderPath.
Dim setting_sh As Worksheet
Set setting_sh = ThisWorkbook.Sheets("Macro")
Dim SourceFolderPath As String
Dim MasterFolderPath As String
Dim objFSO As Object
Dim objMyFolder As Object
Dim objMyFile As Object
Dim strSourceFolder As String
Dim strDestFolder As String
Dim strMasterFolder As String
Application.ScreenUpdating = False
strSourceFolder = setting_sh.Range("C2").Value
strMasterFolder = setting_sh.Range("C3").Value
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objMyFolder = objFSO.GetFolder(strSourceFolder)
For Each objMyFile In objMyFolder.Files
strDestFolder = strMasterFolder & "\" & Trim(Left(objMyFile.Name, 13))
If Len(Dir(strDestFolder, vbDirectory)) = 0 Then
MkDir strDestFolder
End If
'Copy the *.pdf file to the 'strDestFolder' directory
FileCopy strSourceFolder & "\" & objMyFile.Name, strDestFolder & "\" & objMyFile.Name
'Delete the *.pdf (copying the file and then deleting it from its original location is the same as moving it)
Kill strSourceFolder & "\" & objMyFile.Name
Next objMyFile
Set objFSO = Nothing
Set objMyFolder = Nothing
Application.ScreenUpdating = True
MsgBox (" All the files have been successfully moved from Source Folder to Master Folder ")
End Sub
T1525 FULLY SIGNED LEASE_9263pdf
T1525_FULLY SIGNED LEASE_9263pdf
T 1525 TEMP RENEWAL_8233pdf
eT920_Principal Lease Agreement_10542pdf
eT920_RENEWAL AGREEMENT_452TIF
The current code moves the file based on initial 13 character however i want to change it to move the files based on the contract number starting from T.
I think i need to only change the StrDestFolder Code. I tried to change the line to below but its not working.
" strDestFolder = strMasterFolder & "\" & LEFT(MID(objMyFile.Name,FIND(""T"",objMyFile.Name),FIND(""_"",objMyFile.Name)-FIND(""T"",objMyFile.Name)),6)"
Option Explicit
Sub MoveFiles()
'This Macro will move the files from SourcePath Folder to MasterFolderPath.
Dim setting_sh As Worksheet
Set setting_sh = ThisWorkbook.Sheets("Macro")
Dim SourceFolderPath As String
Dim MasterFolderPath As String
Dim objFSO As Object
Dim objMyFolder As Object
Dim objMyFile As Object
Dim strSourceFolder As String
Dim strDestFolder As String
Dim strMasterFolder As String
Application.ScreenUpdating = False
strSourceFolder = setting_sh.Range("C2").Value
strMasterFolder = setting_sh.Range("C3").Value
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objMyFolder = objFSO.GetFolder(strSourceFolder)
For Each objMyFile In objMyFolder.Files
strDestFolder = strMasterFolder & "\" & Trim(Left(objMyFile.Name, 13))
If Len(Dir(strDestFolder, vbDirectory)) = 0 Then
MkDir strDestFolder
End If
'Copy the *.pdf file to the 'strDestFolder' directory
FileCopy strSourceFolder & "\" & objMyFile.Name, strDestFolder & "\" & objMyFile.Name
'Delete the *.pdf (copying the file and then deleting it from its original location is the same as moving it)
Kill strSourceFolder & "\" & objMyFile.Name
Next objMyFile
Set objFSO = Nothing
Set objMyFolder = Nothing
Application.ScreenUpdating = True
MsgBox (" All the files have been successfully moved from Source Folder to Master Folder ")
End Sub