+ Reply to Thread
Results 1 to 6 of 6

Macro to delete contents of 2 directories not deleting the second

  1. #1
    Registered User
    Join Date
    05-22-2012
    Location
    Reading
    MS-Off Ver
    Excel 2007
    Posts
    47

    Macro to delete contents of 2 directories not deleting the second

    Hi,

    I have a problem that is driving me crazy!

    I have the following code which I would like to run to delete the contents of 2 separate directories:

    HTML Code: 
    However, the second Kill command doesn't work.

    I have tried running it on its own and it works perfectly but it seems that it doesn't run when run after the first kill.

    Am i missing something obvious or can you not run 2 kills in succession?

    Thanks very much in advance for your help

    :-)

  2. #2
    Forum Expert
    Join Date
    12-15-2009
    Location
    Chicago, IL
    MS-Off Ver
    Microsoft Office 365
    Posts
    3,177

    Re: Macro to delete contents of 2 directories not deleting the second

    Works for me

  3. #3
    Registered User
    Join Date
    05-22-2012
    Location
    Reading
    MS-Off Ver
    Excel 2007
    Posts
    47

    Re: Macro to delete contents of 2 directories not deleting the second

    Hi thanks for your quick reply.

    Perhaps I need to show you the wider context as I too can get it to work in isolation but not as part of my larger code.

    Before the folder clearing, I am running a merge utility which merges all files in the CAS_Forms folder.

    I then want to clear this folder and another folder called CAS_Form_Generators.

    Please see the code below:

    HTML Code: 

  4. #4
    Registered User
    Join Date
    05-22-2012
    Location
    Reading
    MS-Off Ver
    Excel 2007
    Posts
    47

    Re: Macro to delete contents of 2 directories not deleting the second

    OK, I have got a bit further with my investigations and it seems that the
    HTML Code: 
    code is not running as something from the merge code is temporarily holding onto it and causing a code 70 - access denied. This explains why the
    HTML Code: 
    code works as this folder is not referenced by the merge code but is a separate folder that also needs o be cleared.

    If I run the kill CAS forms code straight after the merge it produces a code 70 but if I go back and run the kill in isolation afterwards it works.

    Does anyone have any view as to whether there is a way round this?

  5. #5
    Registered User
    Join Date
    05-22-2012
    Location
    Reading
    MS-Off Ver
    Excel 2007
    Posts
    47

    Re: Macro to delete contents of 2 directories not deleting the second

    It would be really great if anyone has any advice for me as I have a deadline tomorrow and need to get something working!!!

    Thanks in advance


  6. #6
    Registered User
    Join Date
    05-22-2012
    Location
    Reading
    MS-Off Ver
    Excel 2007
    Posts
    47

    Re: Macro to delete contents of 2 directories not deleting the second

    I have just worked out that the kill works when I close the merged workbook (1 spreadsheet with a tab for each spreadsheet in the C:\CAS forms folder). So it is as if the merged workbook holds onto the individual workbooks it has used to create itself.

    When I close the merged workbook and run the kill it works.

    Is there anyway of releasing the tie between the component excel workbooks and the merged workbook before it is closed so that I can clear the C:\CAS Forms folder to tidy up at the end of the process?

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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