Results 1 to 3 of 3

Move Files to Master Folder Based on the Contract no e.g T1782, T98882

Threaded View

  1. #1
    Registered User
    Join Date
    03-09-2021
    Location
    London
    MS-Off Ver
    2016
    Posts
    16

    Move Files to Master Folder Based on the Contract no e.g T1782, T98882

    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
    Attached Files Attached Files
    Last edited by alansidman; 04-18-2022 at 05:14 AM.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Move files based on specified file name so a specified folder
    By quinnwits in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 06-03-2021, 02:24 PM
  2. move files from Source Folder to Destination Folder, based on file name & Path
    By seenai in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 07-31-2020, 09:29 AM
  3. Move PDF files to a folder based on a criteria
    By lyfsbful in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 04-01-2020, 05:59 PM
  4. Re: Move Files from folder and sub folder based on date
    By flupsie in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 10-08-2017, 12:15 PM
  5. Create folder and move files to that folder based on file name
    By biznez in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 01-26-2016, 06:58 PM
  6. move files to folder based on a .igy list
    By henkdevreisch in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 02-14-2013, 01:42 PM
  7. move files from 1 folder to another based on cell values
    By aravindhan_31 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 08-26-2010, 01:03 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1