Consulting

Results 1 to 4 of 4

Thread: VBA Macro to copy and move all files and folders from one folder to another.

  1. #1

    VBA Macro to copy and move all files and folders from one folder to another.

    Hy everyone!

    In this path:

    D:\MIHAI\DOSARE\BAAR

    I have this folder:
    BAAR-Dosar6359_01977 CT10CXJ Dacia Logan-18.11.2015
    This folder contains more files and subfolders.

    I want to make a macro in Microsoft Word 2010 that does the following:


    1. Copy the folder:
    BAAR-Dosar6359_01977 CT10CXJ Dacia Logan-18.11.2015
    (including files and subfolders)
    to this path:
    \\Andreea\baar\BAAR dosare\BAAR-dosare primite\BAAR-dosare in lucru

    2. Move the folder:
    BAAR-Dosar6359_01977 CT10CXJ Dacia Logan-18.11.2015
    (including files and subfolders)
    to this path:
    D:\MIHAI\DOSARE\BAAR\VECHI


    If you have any ideas of how to do that I would be greatly appreciative as it would save me a great amount of time at work.
    Thanks a lot guys and have a good day!

  2. #2
    I don't know why yoiu need a macro for this. It looks like a simple drag and drop using Windows Explorer.
    Graham Mayor - MS MVP (Word) 2002-2019
    Visit my web site for more programming tips and ready made processes
    http://www.gmayor.com

  3. #3
    Microsoft Word MVP 2003-2009 VBAX Guru gmaxey's Avatar
    Joined
    Sep 2005
    Posts
    3,340
    Location
    You can do this with the FileSystemObject:

    Sub TestMoveCopy()
      'Starting with a folder "H:\Test
      MoveFolderFSO "H:\Test", "H:\Test2"
      CopyFolderFSO "H:\Test2", "H:\Test3"
    End Sub
    Sub MoveFolderFSO(strSFolder, strDFolder)
    Dim oFSO As Object 'FileSystemObject
      'This in a sense is equivelent to renaming the source folder with the destination folder name.
      Set oFSO = CreateObject("scripting.filesystemobject")
      If oFSO.FolderExists(strDFolder) Then oFSO.DeleteFolder (strDFolder)
      oFSO.MoveFolder strSFolder, strDFolder
    lbl_Exit:
      Exit Sub
    End Sub
    Sub CopyFolderFSO(strSFolder, strDFolder)
    Dim oFSO As Object 'FileSystemObject
      Set oFSO = CreateObject("scripting.filesystemobject")
      oFSO.CopyFolder strSFolder, strDFolder
    lbl_Exit:
      Exit Sub
    End Sub
    Greg

    Visit my website: http://gregmaxey.com

  4. #4
    Thanks a lot gmaxey.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •