moving folder and contents without using FSO

RhodEvans

Board Regular
Joined
Oct 31, 2012
Messages
88
Afternoon all,

I have been searching for a way of moving folders (& contents) via an excel macro. The folders are all in the same directory that the excel file is in and I want to make certain folders move to a "removed" folder that is in the same parent directory. The issue I am having is that all the examples I find use FSO (FileSystemObject) which have been disabled on the works machines.
Does anyone know if it is even possible without this, if so any suggestions?

As always I appreciate any help/advice that you are able to give!!

Rhod
 

Excel Facts

Format cells as date
Select range and press Ctrl+Shift+3 to format cells as date. (Shift 3 is the # sign which sort of looks like a small calendar).
I have been searching for a way of moving folders (& contents) via an excel macro. The folders are all in the same directory that the excel file is in and I want to make certain folders move to a "removed" folder that is in the same parent directory. The issue I am having is that all the examples I find use FSO (FileSystemObject) which have been disabled on the works machines.
Does anyone know if it is even possible without this, if so any suggestions?
What can you tell us about the names of the folders that you want to move? Do you have a list of them somewhere (where)? Do they all begin with the same text (what is it)? It is hard to write code when the specifics are unknown, so whatever you can tell us about the names of the folders that will allow you to identify them, the better.
 
Upvote 0
If command prompt is fine then it can be used via VBA.
 
Upvote 0
The folder names are all of a format Surname, First name and the ones that need moving are all in the column B(Surname), A(Firstname) starting in row 4 or a worksheet named "removed". The contents of the folders may change, but will always have at least the following two files in.

Surname, Firstname - Feedbacks.xls
Surname, Firstname - Feedbacks PPR.doc

Hopefully this is the information you needed, if not I will try to give you some more
 
Upvote 0
The folder names are all of a format Surname, First name and the ones that need moving are all in the column B(Surname), A(Firstname) starting in row 4 or a worksheet named "removed". The contents of the folders may change, but will always have at least the following two files in.

Surname, Firstname - Feedbacks.xls
Surname, Firstname - Feedbacks PPR.doc

Hopefully this is the information you needed, if not I will try to give you some more
My assumptions from reading your messsages... the "removed" directory is in the same directory as the excel file containing the macro which is also the same directory that the name directories are in. Also, the name directories have a comma/space between the surname and first name. Give this macro a try...

Code:
Sub MoveDirectoriesToRemoveDirectory()
  Dim X As Long, LastRow As Long, FileName As String
  With Sheets("removed")
    LastRow = .Cells(Rows.Count, "A").End(xlUp).Row
    For X = 4 To LastRow
      FileName = .Cells(X, "B").Value & ", " & .Cells(X, "A").Value
      Name ThisWorkbook.Path & "\" & FileName As ThisWorkbook.Path & "\removed\" & FileName
    Next
  End With
End Sub
 
Upvote 0
Reading back my original question/request I'm not sure if I explained the directory structure very well . So here goes, hopefully I can clarify it a little bit:

The Workbook that is running the code is called: "HR 1:1 waiting list"
It is in a folder called: New Waiting list
The folders to move are also in: New waiting list
The folder I am trying to move them to will be called: Removed and is: also in the folder: New Waiting list

Hopefully that helps for the relative directory structure.

Sorry if I am confusing things!
 
Upvote 0
Reading back my original question/request I'm not sure if I explained the directory structure very well . So here goes, hopefully I can clarify it a little bit:

The Workbook that is running the code is called: "HR 1:1 waiting list"
It is in a folder called: New Waiting list
The folders to move are also in: New waiting list
The folder I am trying to move them to will be called: Removed and is: also in the folder: New Waiting list

Hopefully that helps for the relative directory structure.

Sorry if I am confusing things!

That is what I assumed (I did not need to know the parent directory name specifically since I had the workbook tell it to me via the ThisWorkbook.Path call). As long as the names are located on a worksheet named "removed" and in the order and location specified in your original message, the code I posted should work directly for you. Give it a try and let me know.
 
Upvote 0
Thank you very much. I'm slowly getting better at VBA. No where near as good as you (and doubt that I'll ever have your knowledge). But one of the best way's I've found to learn is from seeing solutions on here and also attempting to help others. So you help is invaluable.
Thank you again!
 
Upvote 0
Thank you very much. I'm slowly getting better at VBA. No where near as good as you (and doubt that I'll ever have your knowledge). But one of the best way's I've found to learn is from seeing solutions on here and also attempting to help others. So you help is invaluable.
Thank you again!
Can I assume from your comment that my code worked for you?
 
Upvote 0

Forum statistics

Threads
1,214,572
Messages
6,120,306
Members
448,955
Latest member
Dreamz high

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