Results 1 to 6 of 6

Copy, Rename and validate multiple excel files

Threaded View

  1. #1
    Registered User
    Join Date
    09-07-2020
    Location
    Melbourne
    MS-Off Ver
    10
    Posts
    3

    Post Copy, Rename and validate multiple excel files

    Hi All, Been scratching around for the last 5 days to find something that works for multiple files. Many a late night/early hours of the morning unsuccessfully piecing together/coding to get a result.
    Thanks in advance.

    The following code is from get-digital-help.com/copyrename-a-file-excel-vba written by Oscar
    I'd really like each row to look at the source path, source file name, destination path and destination file:

    For each row:
    Column A list the source path
    Column B lists the source file name
    Column C lists to destination path
    Column D lists the new file name

    Column E writes "Success" or "Fail" validation.
    - if file name already exists in destination, then "Fail"
    - If source file doesn't exist, then "Fail"


    Nice to have/completely optional!!!
    Check if source file column A&B exists, = True or False in column F. Where True, then proceed with copy and rename.
    If destination file already exist, the fail and column F = duplicate


    Sub CopyRenameFile()
    
    'Dimension variables and declare data types
    Dim src As String, dst As String, fl As String
    Dim rfl As String
    
    'Save source directory specified in cell A2 to variable src
    src = Range("A2")
    
    'Save destination directory specified in cell C2 to variable dst
    dst = Range("C2")
    
    'Save file name specified in cell B2 to variable fl
    fl = Range("B2")
    
    'Save new file name specified in cell D2 to variable rfl
    rfl = Range("D2")
    
    'Enable error handling
    On Error Resume Next
    
    'Copy file based on variables src and fl to destination folder based on variable dst and name file based on value in rfl
    FileCopy src & "\" & fl, dst & "\" & rfl
    
    'Check if an error has occurred
    If Err.Number <> 0 Then
    
    'Show error using message box
        MsgBox "Copy error: " & src & "\" & rfl
    End If
    
    'Disable error handling
    On Error GoTo 0
    
    End Sub
    Last edited by Bart101; 09-08-2020 at 07:12 PM.

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Ability to rename multiple files from a path and move and rename to another.
    By X82 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 01-20-2020, 09:54 PM
  2. Rename Multiple PDF Files using Excel VBA
    By swithinmurickal in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 03-07-2018, 01:21 PM
  3. Rename Multiple PDF files in a folder per the list in Excel spreadsheet
    By vmanil75 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 11-18-2017, 09:40 AM
  4. [SOLVED] Copy/Rename Multiple files in Excel
    By chris619 in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 11-13-2017, 02:44 PM
  5. [SOLVED] rename multiple excel files as per its own cell value A2
    By raj soni in forum Excel Programming / VBA / Macros
    Replies: 11
    Last Post: 09-11-2017, 01:55 AM
  6. [SOLVED] Copy/Rename Multiple files using Excel values in columns
    By felizeng in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 08-25-2017, 10:52 AM
  7. How to copy and rename files in vba by searching multiple folders for files
    By razorace in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 01-04-2014, 04:21 AM

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