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

Mallesh23

Well-known Member
Joined
Feb 4, 2009
Messages
963
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: 16

Excel Facts

Get help while writing formula
Click the italics "fx" icon to the left of the formula bar to open the Functions Arguments dialog. Help is displayed for each argument.

bobsan42

Well-known Member
Joined
Jul 14, 2010
Messages
1,855
Office Version
  1. 365
  2. 2019
  3. 2016
  4. 2013
Platform
  1. Windows
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.
 

Mallesh23

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

Thanks for your help, its working now.


Thanks
mg
 
Master Excel Bundle

Excel contains over 450 functions, with more added every year. That’s a huge number, so where should you start? Right here with this bundle.

Forum statistics

Threads
1,151,857
Messages
5,766,791
Members
425,379
Latest member
thedoctor00

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