Move files to specified folder

dummies

New Member
Joined
Jul 10, 2020
Messages
27
Office Version
  1. 2016
Platform
  1. Windows
I have 2 folder,
1. Temp, which contains many sub folders(department or course)
2.vba , it contain files(name of the students) of the every students.
I am done with creating files and folders of every students and their department, but i am stuck with how to move files to specified folder.
Like if student A is in commerce department, i want to move that student A to commerce folder. Like wise is student B is in science, move student B to science folder, and so on. (Some students have same department as well). And all the moved file should be password protected(password should be last 4 digit of their date of birth)
It will be great help if any one could help me with this. I am really stuck here.
Thank you in advance.
 

Some videos you may like

Excel Facts

Test for Multiple Conditions in IF?
Use AND(test, test, test, test) or OR(test, test, test, ...) as the logical_test argument of IF.

dummies

New Member
Joined
Jul 10, 2020
Messages
27
Office Version
  1. 2016
Platform
  1. Windows
look at this thread is has got a very simple way of moving files once you have generated a worksheet with a list of the files you want moved and to where:
Need a macro to move files from Source Folder to Destination Folder, based on Table
I tired but this is coping only files to folder. I want files to be copied in specified folder. Like, i have two folders. 1 is name of the student.2 is department of the students.so i wanna move students file to their specified department folder. I am really stuck here.
 

offthelip

Well-known Member
Joined
Dec 23, 2017
Messages
1,660
Office Version
  1. 2010
Platform
  1. Windows
The link I gave you did exactly that for a list of files with the source in column B and the destination in column C , so put the path to the files with the names of the students in column B and the path to the departments in column C.
 

dummies

New Member
Joined
Jul 10, 2020
Messages
27
Office Version
  1. 2016
Platform
  1. Windows

ADVERTISEMENT

The link I gave you did exactly that for a list of files with the source in column B and the destination in column C , so put the path to the files with the names of the students in column B and the path to the departments in column C.
May be the path is already given in the table in the link that you have gave to me. But where as mine, i wanted to move files from one folder to specified folder.
I have files(name of the students ) and wanted to move that file to specified folder(department name according to their department).
I would be very grateful if you could help me with this.
Thank you
 

offthelip

Well-known Member
Joined
Dec 23, 2017
Messages
1,660
Office Version
  1. 2010
Platform
  1. Windows
When moving a file from one place to another there is always going to be a folder which is where the file currently is and there is going to be a folder where you want to move it to. Each folder has a full path address. When you move a file from one pace to another using the code I gave you you have the option to change the name but you don't have to you can keep the name the same and just change the path i.e the folder. So to move all your student files from the start folder you need to write down the full path of the folder they are in and add the name of each student file in column B, the for the department that you want it moved to you write the department folder full path in column C and add the student file name.
 

dummies

New Member
Joined
Jul 10, 2020
Messages
27
Office Version
  1. 2016
Platform
  1. Windows

ADVERTISEMENT

The link I gave you did exactly that for a list of files with the source in column B and the destination in column C , so put the path to the files with the names of the students in column B and the path to the departments in column C.
What i did was, 1st i did the folder loop and after that i wanted to cheak weather
When moving a file from one place to another there is always going to be a folder which is where the file currently is and there is going to be a folder where you want to move it to. Each folder has a full path address. When you move a file from one pace to another using the code I gave you you have the option to change the name but you don't have to you can keep the name the same and just change the path i.e the folder. So to move all your student files from the start folder you need to write down the full path of the folder they are in and add the name of each student file in column B, the for the department that you want it moved to you write the department folder full path in column C and add the student file name.
I dono how but i am still not getting it. I can move file one by one but couldnot move all at once . I have large numbers of file.
What i did was , loop the folder then cheak the file and after that i am lost when moving files to their particular folder.
Anyway thank you.
 

dummies

New Member
Joined
Jul 10, 2020
Messages
27
Office Version
  1. 2016
Platform
  1. Windows
When moving a file from one place to another there is always going to be a folder which is where the file currently is and there is going to be a folder where you want to move it to. Each folder has a full path address. When you move a file from one pace to another using the code I gave you you have the option to change the name but you don't have to you can keep the name the same and just change the path i.e the folder. So to move all your student files from the start folder you need to write down the full path of the folder they are in and add the name of each student file in column B, the for the department that you want it moved to you write the department folder full path in column C and add the student file name.
<Dim FSO As 0bject Set FSO = Create0biect ("Scripting.FileSystemObject Dim pfl As Obiect Set pfl = FSO.Get Folder("C:path") Dim fl As Object For Each fl In pfl.subfolders Debug.Print (fl.name) Debug.Print (fl.Path) Next Set FSO = Nothing Dim fileName As Variant fileName = Dir("C:sourcepath") While fileName < > Debug.Print fileName 'Set the fileName to the next file fileName = Dir
Wend\>
My code is something like this
When moving a file from one place to another there is always going to be a folder which is where the file currently is and there is going to be a folder where you want to move it to. Each folder has a full path address. When you move a file from one pace to another using the code I gave you you have the option to change the name but you don't have to you can keep the name the same and just change the path i.e the folder. So to move all your student files from the start folder you need to write down the full path of the folder they are in and add the name of each student file in column B, the for the department that you want it moved to you write the department folder full path in column C and add the student file name.
 

offthelip

Well-known Member
Joined
Dec 23, 2017
Messages
1,660
Office Version
  1. 2010
Platform
  1. Windows
try changing this line:
VBA Code:
lastrow = Cells(Rows.Count, "A").End(xlUp).Row
to
Code:
lastrow = Cells(Rows.Count, "B").End(xlUp).Row
 

dummies

New Member
Joined
Jul 10, 2020
Messages
27
Office Version
  1. 2016
Platform
  1. Windows
try changing this line:
VBA Code:
lastrow = Cells(Rows.Count, "A").End(xlUp).Row
to
Code:
lastrow = Cells(Rows.Count, "B").End(xlUp).Row
Thank you very much.
I have another problem, i ll be very grateful if you could help me .
I have students date of birth in column G, so i want to set a password to individual students file with their last 4 digit of their date of birth.
Like student A dob is 20000808,so i want to set password to student A's file as 0808.
Will it be possible?
Thank you in advance
 

Watch MrExcel Video

Forum statistics

Threads
1,123,087
Messages
5,599,658
Members
414,325
Latest member
kfg1287

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
Top