Move certain files in a folder to another using excel VBA?

L

Legacy 293160

Guest
Hi all excel gurus!

I searched for few hours before disturbing you guys but didnt find anything useful.

I have a folder with a number of files and want to move some of them to another folder

the way I'd like it to be done is that in the excel spreadsheet, I list the path and names of the source files then in the next column lists the path and names of the destination folder.

then I need a macro to go an find these files and move them to new destination.

please see below of what I mean


-- removed inline image ---



any help much appreciated

thanks very much
 
Hello. I was wondering how this could be modified so the popup asking if the user wants to create a directory each time one does not already exist? I was going to make a user form with the option Yes to All, but I would rather the code just create directories that do not already exist, rather than asking many times.

Thanks!

Kris
 
Upvote 0

Excel Facts

Excel Can Read to You
Customize Quick Access Toolbar. From All Commands, add Speak Cells or Speak Cells on Enter to QAT. Select cells. Press Speak Cells.
Bertie,

Hello. Your code used to work for me, but something strange recently began happening. Everything is fine (I can edit the file folder and file names and/or move either the file folder or files around) until I try to delete a folder. The files within will be deleted, but the folder itself reappears and then will not allow me to delete it. It is as if the permission setting of the folder becomes corrupt. If I delete the files in the folder first and then try to delete the folder, the some thing occurs. Initially, the folder does go away as if successfully deleted, but if I back out a level or so and then return to where the folder was, it has reappeared.

Sorry if I am not explaining that well, but do you have any thoughts?
 
Upvote 0
Hi, this code works great. However, one problem. I get a "file already exists" error when running more than once. I will need to move the same filename multiple times, so I need it to automatically overwrite the existing file if it already exists. I tried the "Application.DisplayAlerts" and it doesn't work. Any help would be appreciated.
 
Upvote 0
Replace "Name oldFileName As newFileName" (Name moves the file) with "FileCopy oldFileName, newFileName" under the 'move file comment.
 
Upvote 0
Thank you for your code here Bertie, I was also able to use this code and it has greatly helped me. Thanks!!
 
Upvote 0

Forum statistics

Threads
1,215,813
Messages
6,127,026
Members
449,352
Latest member
Tileni

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top