I kind of did BUT indirectly, so what I did is modify the code to copy the files not move them with the subfolder If (CreateObject("scripting.FileSystemObject").GetFolder(xStr).Files.Count = 0) _Īnd (CreateObject("scripting.FileSystemObject").GetFolder(xStr).SubFolders.Count = 0) Then XStr = xDPathStr & "\" & xF.Name ' Replace(xF.ShortPath, xSPathStr, xDPathStr)Ĭall sMoveFiles(xRg, xF.ShortPath & "\", xStr & "\") Set fso = CreateObject("Scripting.FileSystemObject") If TypeName(xVal) = "String" And Not (xVal = "") Then Sub sMoveFiles(xRg As Range, xSPathStr As Variant, xDPathStr As Variant) To move files from folder and subfolders based on cell values, please apply the below VBA code:Ĭall sMoveFiles(xRg, xSPathStr, xDPathStr) Easy deploying in your enterprise or organization. Combine Workbooks and WorkSheets Merge Tables based on key columns Split Data into Multiple Sheets Batch Convert xls, xlsx and PDF.ģ00 powerful features.Super Filter (save and apply filter schemes to other sheets) Advanced Sort by month/week/day, frequency and more Special Filter by bold, italic. Extract Text, Add Text, Remove by Position, Remove Space Create and Print Paging Subtotals Convert Between Cells Content and Comments.Exact Copy Multiple Cells without changing formula reference Auto Create References to Multiple Sheets Insert Bullets, Check Boxes and more.Select Duplicate or Unique Rows Select Blank Rows (all cells are empty) Super Find and Fuzzy Find in Many Workbooks Random Select.Merge Cells/Rows/Columns without losing Data Split Cells Content Combine Duplicate Rows/Columns.Super Formula Bar (easily edit multiple lines of text and formula) Reading Layout (easily read and edit large numbers of cells) Paste to Filtered Range.Reuse: Quickly insert complex formulas, charts and anything that you have used before Encrypt Cells with password Create Mailing List and send emails.The Best Office Productivity Tools Kutools for Excel Solves Most of Your Problems, and Increases Your Productivity by XDFileDlg.Title = "Please select the destination folder:" XSFileDlg.Title = "Please select the original folder:" VBA code: Copy files from one folder to another based on a list in Excel Sub copyfiles() Note: If you just want to copy the files to another folder, but keep the original files, please apply the below VBA code: 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: And then click OK, go on selecting the destination folder where you want to locate the files in another popped out window, see screenshot:Ħ. 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:ĥ. 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:Ĥ. If TypeName(xVal) = "String" And xVal "" ThenįileCopy xSPathStr & xVal, xDPathStr & xValģ. XDFileDlg.Title = " Please select the destination folder:" Set xDFileDlg = Application.FileDialog(msoFileDialogFolderPicker) XSFileDlg.Title = " Please select the original folder:" Set xSFileDlg = Application.FileDialog(msoFileDialogFolderPicker) Set xRg = Application.InputBox("Please select the file names:", "KuTools For Excel",, ,, ,, 8) VBA code: Move files from one folder to another based on a list in Excel Sub movefiles()ĭim xSFileDlg As FileDialog, xDFileDlg As FileDialogĭim xSPathStr As Variant, xDPathStr As Variant Click Insert > Module, and paste the following VBA code in the Module Window. Hold down the Alt + F11 keys in Excel, and it opens the Microsoft Visual Basic for Applications window.Ģ. 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:ġ. How could you finish this task as quickly as you can in Excel?Ĭopy or move files from one folder to another based on a list in Excel with VBA code 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. If you have a list of file names in a column in a worksheet, and the files locate in a folder in your computor. How to copy or move files from one folder to another based on a list in Excel?
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |