Results 1 to 7 of 7
  1. #1
    Silver Lounger
    Join Date
    Jul 2001
    Location
    Ottawa, Ontario, Canada
    Posts
    1,609
    Thanks
    0
    Thanked 1 Time in 1 Post

    Releasing Claim on Folder (VBA/Word/2003)

    I am using VBA to recognize a folder and its contents with the following process:<UL><LI>Create or identify a folder (Folder A);
    <LI>Determine whether Folder A contains a subfolder (A/[img]/forums/images/smilies/cool.gif[/img] and if necessary create it
    <LI>Copy a file to Folder A
    <LI>Determine the contents of subfolder AB[/list]Later the user may run another macro intended to delete Folder A and all of its contents. using the following command: <pre>Shell "cmd /c ""rd """ & Folder2Delete & """ /s /q"""</pre>


    If Folder A was the last folder to be recognized, the code does not delete the folder though it does delete all of the contents. Can any loungers suggest a technique to cause Word VBA to release its claim on a given folder, thereby allowing deletion of that specific folder?

    T.I.A.
    Regards
    Don

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Releasing Claim on Folder (VBA/Word/2003)

    Can you tell us more about the code you're using to "recognize" a folder?

    Why are you using Shell to delete a folder? VBA has the built-in instruction RmDir:

    RmDir Folder2Delete

  3. #3
    Silver Lounger
    Join Date
    Jul 2001
    Location
    Ottawa, Ontario, Canada
    Posts
    1,609
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: Releasing Claim on Folder (VBA/Word/2003)

    Hello Hans
    Thank you for the speedy response. It has taken me a while to gather the relevant info. I apologize in advance if it's overkill.
    <hr>Can you tell us more about the code you're using to "recognize" a folder?<hr>
    The attached file has all the particulars. Please ask if I have been unclear in any detail.

    <hr>Why are you using Shell to delete a folder?<hr>
    I was advised by a very knowledgeable gent to do so <!post=here,658120>here<!/post>.
    Attached Files Attached Files
    Regards
    Don

  4. #4
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Releasing Claim on Folder (VBA/Word/2003)

    Funny fellows, those Loungers! <img src=/S/grin.gif border=0 alt=grin width=15 height=15>

    Your attachment contains a lot of code!

  5. #5
    Silver Lounger
    Join Date
    Jul 2001
    Location
    Ottawa, Ontario, Canada
    Posts
    1,609
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: Releasing Claim on Folder (VBA/Word/2003)

    <P ID="edit" class=small>(Edited by wdwells on 18-Oct-07 18:19. "be" added to last paragraph.)</P>Hi Hans
    First off; apologies. I am attaching a module that was missing from the package I provided earlier. The project compiled successfully because a copy of the missing module was held in my Normal template.

    What should you look at? Please take a look at the attached module and advise if there is anything therein that you feel might lock a folder.

    I have just run the following series of tests on my D: drive which contains among other items an empty folder named "D:TrashTrashx". The following commands were executed from the Immediate window of the VBE unless otherwise stated.
    1. <LI> mkdir "D:trashtrash" The folder was created as requested.
      <LI> rmdir "D:trashtrash" The folder was deleted as requested
      <LI> mkdir "D:trashtrash" The folder was created as requested.
      <LI> A file was placed in "D:trashtrash" using Windows Explorer
      <LI> The file was deleted from "D:trashtrash" using the keyboard Delete key
      <LI> Windows Explorer was taken up one level to display the contents of "D:trash"
      <LI> rmdir "D:trashtrash" The folder was deleted as requested
      <LI> mkdir "D:trashtrash" The folder was created as requested.
      <LI> A file was placed in "D:trashtrash" using Windows Explorer
      <LI> ?dir("D:trashtrash*.*") Returned the file name
      <LI> The file was deleted from "D:trashtrash" using the keyboard Delete key
      <LI> Windows Explorer was taken up one level to display the contents of "D:trash"
      <LI> rmdir "D:trashtrash" An error message appeared Run Time Error 75. Path/File Access Error
      <LI> ?dir("D:trashx*.*") Returned a null string.
      <LI> rmdir "D:trashtrash" The folder was deleted as requested
    From the foregoing i understand that the Dir command can lock a folder--and be used to unlock it. Are you aware of any other VBA commands which pose the same threat?

    T.I,A.
    Attached Files Attached Files
    Regards
    Don

  6. #6
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Releasing Claim on Folder (VBA/Word/2003)

    Sorry, I have no idea what the underlying cause is.

  7. #7
    Silver Lounger
    Join Date
    Jul 2001
    Location
    Ottawa, Ontario, Canada
    Posts
    1,609
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: Releasing Claim on Folder (VBA/Word/2003)

    Thanks for the effort Hans. <img src=/S/cheers.gif border=0 alt=cheers width=30 height=16>
    Regards
    Don

Posting Permissions

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