vba help - Copy all folder and subfolders names from previous month to next month

Mallesh23

Well-known Member
Joined
Feb 4, 2009
Messages
976
Office Version
  1. 2010
Platform
  1. Windows
Hi Team,

Need help to copy all main folders and subfolders Names from source path to Destination Folder path.
Everymonth I copy previous months folders and put in current months folder and delete all files from Current months folder.and subfolders

So in short I want only Empty folder and subfolder names without data into it.
approx 450 folders.

how to achieve via VBA
 

Attachments

  • copy_foldernames.png
    copy_foldernames.png
    57.7 KB · Views: 25

Excel Facts

What is the last column in Excel?
Excel columns run from A to Z, AA to AZ, AAA to XFD. The last column is XFD.
try if this works for you:
VBA Code:
Sub copyFolders()
    Dim src As String, dest As String, strCommand As String
    With Application.FileDialog(msoFileDialogFolderPicker)
        .AllowMultiSelect = False
        .Title = "Select source folder"
        If .show = 0 Then Exit Sub
        src = .SelectedItems(1)
    End With
    With Application.FileDialog(msoFileDialogFolderPicker)
        .AllowMultiSelect = False
        .Title = "Select destination folder"
        If .show = 0 Then Exit Sub
        dest = .SelectedItems(1)
    End With
    strCommand = "xcopy """ & src & """ """ & dest & """ /t /e"
'    CreateObject("Wscript.Shell").Exec (strCommand)
    CreateObject("Wscript.Shell").Run strCommand, 0, True
    msgbox "Ready!"
End Sub
it can be automated by directly providing src and dest folders instead of selecting them.
 
Upvote 0
Hi BobSans.

Thanks for your help, its working now.


Thanks
mg
 
Upvote 0

Forum statistics

Threads
1,214,396
Messages
6,119,268
Members
448,881
Latest member
Faxgirl

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