+ Reply to Thread
Results 1 to 4 of 4

Copy files and delete current folder and subfolders

  1. #1
    Forum Contributor
    Join Date
    10-12-2011
    Location
    Sydney
    MS-Off Ver
    Excel 2016 in 2024
    Posts
    857

    Copy files and delete current folder and subfolders

    Hi,

    I have the below macro that takes a copy of folders (and sub-folders) and places them in another file location.

    I then need to delete the folders that I copied. I was getting an error because the file or folder was in use.

    After that, I tried to create another instance of Excel and run the macro from there, however the folders do not get deleted. I suspect it is because I close the instance of Excel then I lose my reference to the file path?

    First macro:

    Please Login or Register  to view this content.
    Second macro in another workbook and instance of Excel (the part highlighted in red does not seem to execute):

    Please Login or Register  to view this content.

  2. #2
    Forum Expert JLGWhiz's Avatar
    Join Date
    02-20-2011
    Location
    Florida, USA
    MS-Off Ver
    Windows 10, Excel 2013
    Posts
    2,070

    Re: Copy files and delete current folder and subfolders

    I think maybe the syntax is the problem. Try
    Please Login or Register  to view this content.
    Also, if you had used the MoveFile method, it would not be necessary to go back and delete the old files.
    Any code provided by me should be tested on a copy or a mock up of your original data before applying it to the original. Some events in VBA cannot be reversed with the undo facility in Excel. If your original post is satisfied, please mark the thread as "Solved". To upload a file, see the banner at top of this page.
    Just when I think I am smart, I learn something new!

  3. #3
    Forum Contributor
    Join Date
    10-12-2011
    Location
    Sydney
    MS-Off Ver
    Excel 2016 in 2024
    Posts
    857

    Re: Copy files and delete current folder and subfolders

    ok I will give it a try, thank you!

    Just to confirm, how do I use MoveFile?

    Should it be here:

    Please Login or Register  to view this content.

  4. #4
    Forum Contributor
    Join Date
    10-12-2011
    Location
    Sydney
    MS-Off Ver
    Excel 2016 in 2024
    Posts
    857

    Re: Copy files and delete current folder and subfolders

    with this:

    Please Login or Register  to view this content.
    I get a "permission denied" error.

    Also,
    Please Login or Register  to view this content.
    makes no difference?

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. [SOLVED] list of subfolders in folder - without files and sub-subfolders
    By MartyZ in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 06-11-2022, 10:56 AM
  2. VBA to Delete Files within current Folder
    By midnightorion in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 06-15-2017, 10:02 AM
  3. Copy specific files from subfolders to new folder
    By dxl in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 12-28-2016, 06:06 PM
  4. VBA that goes through all xls files in folder and subfolders
    By Acxer in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 08-18-2015, 09:06 AM
  5. Needs macro to copy excel files from folders, subfolders to new folder
    By genetist in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 10-08-2014, 08:53 AM
  6. Counting files in folder including subfolders also and folder size
    By mido609 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 07-12-2012, 03:26 PM
  7. [SOLVED] copy subfolders, replace text in files and save files in copied subfolders
    By pieros in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 11-01-2005, 09:05 AM

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1