+ Reply to Thread
Results 1 to 2 of 2

copy file from excel list to other folder

Hybrid View

  1. #1
    Registered User
    Join Date
    08-20-2020
    Location
    Milan
    MS-Off Ver
    2016
    Posts
    13

    copy file from excel list to other folder

    Hi All,

    I am new in VBA, so I have a list of document (just file name, without extension .pdf, .docx, etc) in excel column. What I would like to do is to copy all document in the list, from source folder to destination folder.

    I already tried some code, it works but the code copy all the files in the folder instead of the file in list (The document list is only in B3:B10).
    Any help really appreciated.

    Thanks in advance.

    Sub copyfile()
    
    Dim r As Range
    Dim Jajal As Range
    Dim sourcePath As String, DestPath As String, FName As String
    
    sourcePath = "C:\Users\"
    DestPath = "H:\Users\"
    
    For Each r In Range(Sheet6.Range("B3"), Sheet6.Range("B10")) 'the document list is in the sheet6 B3:B10
    FName = Dir(sourcePath & r)
    'Loop while files found
    Do While FName <> ""
      'Copy the file
      FileCopy sourcePath & FName, DestPath & FName
      'Search the next file
      FName = Dir()
    Loop
    Next
    
    End Sub

  2. #2
    Forum Contributor Dante Amor's Avatar
    Join Date
    07-24-2020
    Location
    MEXICO
    MS-Off Ver
    Excel 2013
    Posts
    212

    Re: copy file from excel list to other folder

    Try this:

    Sub copyfile()
      Dim r As Range, rng As Range
      Dim sourcePath As String, DestPath As String, FName As String
      
      sourcePath = "C:\Users\"
      DestPath = "H:\Users\"
      
      For Each r In Sheet6.Range("B3:B10") 'the document list is in the sheet6 B3:B10
        If r.Value <> "" Then
          FName = Dir(sourcePath & r.Value & "*.*")
          'Loop while files found
          Do While FName <> ""
            'Copy the file
            FileCopy sourcePath & FName, DestPath & FName
            'Search the next file
            FName = Dir()
          Loop
        End If
      Next
    
    End Sub

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. copy file from excel list with extension to other folder
    By mattmar in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 08-24-2020, 01:36 PM
  2. iterate through a list and find a file, copy that file to another folder
    By yeqiu in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 02-02-2020, 11:20 PM
  3. copy image file from one folder to another based on a list
    By San75 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 10-23-2019, 06:15 AM
  4. Copy Files from One Folder to Another Folder based on a List In Excel
    By civram1982 in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 03-21-2019, 06:34 AM
  5. Replies: 18
    Last Post: 02-18-2019, 07:42 AM
  6. [SOLVED] Copy the file in your list and then move to the new folder
    By misteyoso in forum Excel Programming / VBA / Macros
    Replies: 17
    Last Post: 03-01-2017, 03:24 AM
  7. Replies: 2
    Last Post: 12-29-2015, 04:19 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