Sie sind auf Seite 1von 8

1/29/2019 How to copy or move files from one folder to another based on a list in Excel?

 ExtendOffice (https://www.extendoffice.com)

 Tips & Tricks for Excel  Tips & Tricks for Word  Tips & Tricks for Outlook
(/documents/excel.html) (/documents/word.html) (/documents/outlook.html)

How To Copy Or Move Files From One Folder To Another


Based On A List In Excel?
If you have a list of file names in a column in a worksheet, and the files locate in a folder in your
computor. But, now, you need to move or copy these files which names are listed into the
worksheet from their original folder to another one as following screenshot shown. How could you
finish this task as quickly as you can in Excel?

Copy or move files from one folder to another based on a list in Excel with VBA code

 Copy Or Move Files From One Folder To Another Based On A List In Excel
With VBA Code

(/product/office-tab.html)

60-Day Free Trial! Free Download and Safe! -- 300+ handy add-ins for your Excel!
Amazing! Using Efficient Tabs In Excel Like Chrome, Firefox
i (//www.addthis.com/website-tools/overview?utm_source=AddThis%20Tools&utm_medium=image&utm_campaign=Marketing%20tool%20logo)
Yes please! (https://www.extendoffice.com/download/kutools-for-excel.html)
https://www.extendoffice.com/documents/excel/4775-move-files-based-on-excel-list.html 1/8
1/29/2019 How to copy or move files from one folder to another based on a list in Excel?

To move the files from one folder to another based on a list of files names, the following VBA
code may do you a favor, please do as this:

1. Hold down the Alt + F11 keys in Excel, and it opens the Microsoft Visual Basic for
Applications window.

2. Click Insert > Module, and paste the following VBA code in the Module Window.

VBA code: Move files from one folder to another based on a list in Excel

1 Sub movefiles()
2 'Updateby Extendoffice
3 Dim xRg As Range, xCell As Range
4 Dim xSFileDlg As FileDialog, xDFileDlg As FileDialog
5 Dim xSPathStr As Variant, xDPathStr As Variant
6 Dim xVal As String
7 On Error Resume Next
8 Set xRg = Application.InputBox("Please select the file names:", "Ku
9 If xRg Is Nothing Then Exit Sub
10 Set xSFileDlg = Application.FileDialog(msoFileDialogFolderPicker)
11 xSFileDlg.Title = " Please select the original folder:"
12 If xSFileDlg.Show <> -1 Then Exit Sub
13 xSPathStr = xSFileDlg.SelectedItems.Item(1) & "\"
14 Set xDFileDlg = Application.FileDialog(msoFileDialogFolderPicker)
15 xDFileDlg.Title = " Please select the destination folder:"
16 If xDFileDlg.Show <> -1 Then Exit Sub
17 xDPathStr = xDFileDlg.SelectedItems.Item(1) & "\"
18 For Each xCell In xRg
19 xVal = xCell.Value
20 If TypeName(xVal) = "String" And xVal <> "" Then
21 FileCopy xSPathStr & xVal, xDPathStr & xVal
22 Kill xSPathStr & xVal
23 End If
24 Next
25 End Sub

3. And then press F5 key to run this code, and a prompt box will pop out to remind you selecting
the cells which contain the file names, see screenshot:

60-Day Free Trial! Free Download and Safe! -- 300+ handy add-ins for your Excel!
i (//www.addthis.com/website-tools/overview?utm_source=AddThis%20Tools&utm_medium=image&utm_campaign=Marketing%20tool%20logo)
Yes please! (https://www.extendoffice.com/download/kutools-for-excel.html)
https://www.extendoffice.com/documents/excel/4775-move-files-based-on-excel-list.html 2/8
1/29/2019 How to copy or move files from one folder to another based on a list in Excel?

4. Then click OK button, and in the popped out window, please select the folder which contains
the files that you want to move from, see screenshot:

5. And then click OK, go on selecting the destination folder where you want to locate the files in
another popped out window, see screenshot:

60-Day Free Trial! Free Download and Safe! -- 300+ handy add-ins for your Excel!
i (//www.addthis.com/website-tools/overview?utm_source=AddThis%20Tools&utm_medium=image&utm_campaign=Marketing%20tool%20logo)
Yes please! (https://www.extendoffice.com/download/kutools-for-excel.html)
https://www.extendoffice.com/documents/excel/4775-move-files-based-on-excel-list.html 3/8
1/29/2019 How to copy or move files from one folder to another based on a list in Excel?

6. Finally, click OK to close the window, and now, the files have been moved into another folder
you specified based on the file names in worksheet list, see screenshot:

Note: If you just want to copy the files to another folder, but keep the original files, please apply
the below VBA code:

VBA code: Copy files from one folder to another based on a list in Excel

60-Day Free Trial! Free Download and Safe! -- 300+ handy add-ins for your Excel!
i (//www.addthis.com/website-tools/overview?utm_source=AddThis%20Tools&utm_medium=image&utm_campaign=Marketing%20tool%20logo)
Yes please! (https://www.extendoffice.com/download/kutools-for-excel.html)
https://www.extendoffice.com/documents/excel/4775-move-files-based-on-excel-list.html 4/8
1/29/20191 Sub copyfiles() How to copy or move files from one folder to another based on a list in Excel?
2 'Updateby Extendoffice
3 Dim xRg As Range, xCell As Range
4 Dim xSFileDlg As FileDialog, xDFileDlg As FileDialog
5 Dim xSPathStr As Variant, xDPathStr As Variant
6 Dim xVal As String
7 On Error Resume Next
8 Set xRg = Application.InputBox("Please select the file names:", "Ku
9 If xRg Is Nothing Then Exit Sub
10 Set xSFileDlg = Application.FileDialog(msoFileDialogFolderPicker)
11 xSFileDlg.Title = "Please select the original folder:"
12 If xSFileDlg.Show <> -1 Then Exit Sub
13 xSPathStr = xSFileDlg.SelectedItems.Item(1) & "\"
14 Set xDFileDlg = Application.FileDialog(msoFileDialogFolderPicker)
15 xDFileDlg.Title = "Please select the destination folder:"
16 If xDFileDlg.Show <> -1 Then Exit Sub
17 xDPathStr = xDFileDlg.SelectedItems.Item(1) & "\"
18 For Each xCell In xRg
19 xVal = xCell.Value
20 If TypeName(xVal) = "String" And xVal <> "" Then
21 FileCopy xSPathStr & xVal, xDPathStr & xVal
22 End If
23 Next
24 End Sub

 Recommended For You


url=http%3
(//m.addthi
wp&per=un
4f7bf4e226
2%26at_po
1.0%26at_
list.html%2
add-color-
to-drop-
down-
excel-
1.0)
How to color coded drop down list in Excel? (//m.addthis.com/live/redirect/?
url=http%3A%2F%2Fwww
www.extendoffice.com
extendoffice com%2Fdocuments%2Fexcel%2F1417
url=http%3
(//m.addthi
wp&per=un
4f7bf4e226
2%26at_po
1.0%26at_
number.htm
generate-
invoice-
excel-
auto-
1.0)
How to automatically generate invoice number in Excel?
(//m addthis com/live/redirect/?
www.extendoffice.com

url=http%3
(//m.addthi
wp&per=un
4f7bf4e226
2%26at_po
1.0%26at_
sheets.htm
excel-list-
multiple-
values-
from-
1.0)
How to create a list from same cells across multiple sheets in Excel?
(//m addthis com/live/redirect/?
www.extendoffice.com

How to create a dynamic monthly calendar in Excel? (//m.addthis.com/live/redirect/?


url=http%3A%2F%2Fwww extendoffice com%2Fdocuments%2Fexcel%2F4029
www.extendoffice.com

i (//www.addthis.com/website-tools/overview?
utm_source=AddThis%20Tools&utm_medium=image&utm_campaign=Recommended%20content%20logo)

 Recommended Productivity Tools

Office Tab (/Product/Office-Tab.Html)

Bring handy tabs to Excel and other Office software, just like Chrome, Firefox and
60-DayExplorer.
new Internet Free Trial! Free Download and Safe! -- 300+ handy add-ins for your Excel!
i (//www.addthis.com/website-tools/overview?utm_source=AddThis%20Tools&utm_medium=image&utm_campaign=Marketing%20tool%20logo)
Yes please! (https://www.extendoffice.com/download/kutools-for-excel.html)
https://www.extendoffice.com/documents/excel/4775-move-files-based-on-excel-list.html 5/8
Kutools For Excel (/Product/Kutools-For-Excel.Html)
1/29/2019 How to copy or move files from one folder to another based on a list in Excel?

Amazing! Increase your productivity in 5 minutes. Don't need any special skills, save
two hours every day!
300 New Features for Excel, Make Excel Much Easy and Powerful:
Merge Cell/Rows/Columns without Losing Data.
Combine and Consolidate Multiple Sheets and Workbooks.
Compare Ranges, Copy Multiple Ranges, Convert Text to Date, Unit and Currency Conversion.
Count by Colors, Paging Subtotals, Advanced Sort and Super Filter,
More Select/Insert/Delete/Text/Format/Link/Comment/Workbooks/Worksheets Tools...

(/product/kutools-for-excel.html)

Read More  (/product/kutools-for-excel.html)


 60-day Unlimited Free Trial (/download/kutools-for-excel.html)
 See Price List (/order/kutools-for-excel.html)

8 Comments
60-Day Free Trial! Free Download and Safe! -- 300+ handy add-ins for your Excel! Login
i (//www.addthis.com/website-tools/overview?utm_source=AddThis%20Tools&utm_medium=image&utm_campaign=Marketing%20tool%20logo)
Yes please! (https://www.extendoffice.com/download/kutools-for-excel.html)
https://www.extendoffice.com/documents/excel/4775-move-files-based-on-excel-list.html 6/8
1/29/2019
Say something here...
How to copy or move files from one folder to another based on a list in Excel?
Sort by Newest b

Andy · 2 months ago

Any tips on how to modify the code to add a wide card? I have an archive of hundreds of PDF files that
are 10 digit numbers and revision level (XXXXXXXXXX_REVA). I can export a list of file names very
easily from our ERP system, but the list is missing the revision and file extension. Is there a way to add
wild cards into the program to ignore everything BUT the 10 digit number?
Reply Share

PWD · 2 months ago

Hello,
how to make this code copy files from subfolders?
Reply Share

Pr · 3 months ago

Hi Guys,

How I need to change '' If TypeName(xVal) = "String" And xVal <> "" Then '' to move files based on
partial file name.

Thanks in advance,
Best regards, P
Reply Share

Sidney · 5 months ago

Você não tem noção de como me ajudou com esse script... Muito bom!!! Obrigado!!!
Reply Share

Robinson · 8 months ago

Obrigado!!!!
Reply Share

1 (https://www.extendoffice.com/documents/excel/4775-move-files-based-on-excel-list.html?page_comment=1)

2 (https://www.extendoffice.com/documents/excel/4775-move-files-based-on-excel-list.html?page_comment=2)

 Home (/)  Knowledge (/documents.html)  Support (/support.html)

 Forum (/forum.html)  Privacy Policy (/privacy-policy.html)


60-Day Free Trial! Free Download and Safe! -- 300+ handy add-ins for your Excel!
 About Us (/support/about-us.html)
i (//www.addthis.com/website-tools/overview?utm_source=AddThis%20Tools&utm_medium=image&utm_campaign=Marketing%20tool%20logo)
Yes please! (https://www.extendoffice.com/download/kutools-for-excel.html)
https://www.extendoffice.com/documents/excel/4775-move-files-based-on-excel-list.html 7/8
1/29/2019 How to copy or move files from one folder to another based on a list in Excel?
Follow us

(http://www.facebook.com/extendoffice)

(http://twitter.com/intent/follow?
source=followbutton&variant=1.0&screen_name=extendoffice)
Copyright © 2009 - 2019 ExtendOffice.com | All Rights Reserved.  Sitemap
(/component/jmap/sitemap.html)
Microsoft and the Office logo are trademarks or registered trademarks of Microsoft Corporation
in the United States and/or other countries.
(https://sectigo.com/trust-seal)

60-Day Free Trial! Free Download and Safe! -- 300+ handy add-ins for your Excel!
i (//www.addthis.com/website-tools/overview?utm_source=AddThis%20Tools&utm_medium=image&utm_campaign=Marketing%20tool%20logo)
Yes please! (https://www.extendoffice.com/download/kutools-for-excel.html)
https://www.extendoffice.com/documents/excel/4775-move-files-based-on-excel-list.html 8/8