+ Reply to Thread
Results 1 to 4 of 4

Kill Command Crashes if File is Not There

  1. #1
    Registered User
    Join Date
    01-12-2012
    Location
    USA
    MS-Off Ver
    Excel 2007, 2003
    Posts
    84

    Kill Command Crashes if File is Not There

    In order to keep users from stepping on each other while using the file we've created, we use a Auto_Open macro to immediately save the file to a safe location in the users' home directory. The goal is to minimize user input as much as possible so I placed a Kill command ahead of the SaveAs command to erase the file before saving a new copy. This eliminates the pesky "File Already Exists" alert window....again the goal is to keep the users hands off and not ask them to click or touch anything until the process is ready for them. It worked great on the first test because the Excel file in my home directory already existed and the Kill command deleted it. But when I tried it on a new user's machine, one where the Excel file did not exist in his home directory, it crashed on the kill command statement.

    Is there a way to override this or will I have to check for the existence of the xls file before executing the kill statement? And if so, how does one efficiently do that? In doing research on this it sounds like a method to have the SaveAs command automatically overwrite the existing file would be preferred. The code I just examined to check for the presence of a file was lengthy and complex.
    Last edited by Vladamir; 03-05-2012 at 05:45 PM.
    Wish I didn't know now what I didn't know then.

  2. #2
    Forum Contributor
    Join Date
    12-28-2011
    Location
    England
    MS-Off Ver
    Excel 2007
    Posts
    280

    Re: Kill Command Crashes if File is Not There

    Hi

    You could simply use On Error Resume Next to ignore the error if the workbook isn't there ge:

    Please Login or Register  to view this content.

  3. #3
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2010, 2019
    Posts
    40,689

    Re: Kill Command Crashes if File is Not There

    The code I just examined to check for the presence of a file was lengthy and complex.
    Please Login or Register  to view this content.
    Entia non sunt multiplicanda sine necessitate

  4. #4
    Registered User
    Join Date
    01-12-2012
    Location
    USA
    MS-Off Ver
    Excel 2007, 2003
    Posts
    84

    Re: Kill Command Crashes if File is Not There

    Thanks. Those are terrific ideas. But I found this in another search and it works great:

    Please Login or Register  to view this content.
    This eliminates the need for the kill statement altogether.

+ 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