Consulting

Results 1 to 7 of 7

Thread: Solved: Deleting file at end of code

  1. #1

    Solved: Deleting file at end of code

    I have the following file created by a press operator:
    Attachment 5520

    The coding in the "Pull Ticket" sheet is leftover from when the file was created/submited. The file (Job 123456 - Run Cover - Press 1010 - 4.17.2007.xls) is saved on our network in the following location:
    V:\press\Forum\Count Control\Pull Tickets\Verification Needed

    A supervisor will open this file and verify that all of the counts are correct. The supervisor will then click on the "Submit Supervisor Verification" button and select his name. On clicking OK, just the range of cells containing the ticket information is saved as a picture image in a newly created workbook (Job 123456 - Run Cover - Press 1010 - 4.17.2007 Verified.xls) in another network location:
    V:\press\Forum\Count Control\Pull Tickets\Counts Verified
    The new workbook is then emailed out.

    Up to this point everything is working fine. However, now I want to delete the original file from the "Verification Needed" folder so that the verification process is shown as complete. Please help!!

    Please note, I have built everything in Excel 2003, but the primary users of this program will be using Excel 97.

  2. #2
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    Just use Kill with the original file path.

  3. #3
    Quote Originally Posted by xld
    Just use Kill with the original file path.
    I do.

    Early on in the code I define:
    [VBA]OriginalFileName = ActiveWorkbook.Name
    OriginalFile = ActiveWorkbook.FullName[/VBA]
    At the end I use:
    [VBA]Workbooks(OriginalFileName).Close SaveChanges:=False
    Kill OriginalFile[/VBA]

  4. #4
    Can a file kill itself? I'm wondering if that is the problem.

  5. #5
    Answered my own question. You can't kill ThisWorkbook, but you can program it to "commit suicide":
    http://puremis.net/excel/code/029.shtml

    So here's what I used at the end of the code (in place of the last two lines I mentioned above):
    [vba]'Close original without changes and then delete from folder
    Workbooks(OriginalFileName).Save
    Workbooks(OriginalFileName).ChangeFileAccess Mode:=xlReadOnly
    Kill OriginalFile
    Workbooks(OriginalFileName).Close SaveChanges:=False[/vba]

  6. #6
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    I wouldn't call that suicide, you just removed the lock that Excel has on the file, so it can still be murdered like any other.

  7. #7
    Murdered....suicide....either way, it's gone! It did exactly what I needed it to do. But I understand what you are saying.....I understand the control that Excel has a bit more.

Posting Permissions

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