+ Reply to Thread
Results 1 to 3 of 3

Kill a File

  1. #1
    Posse John
    Guest

    Kill a File

    I have a file with the Workbook_Open routine looking at the Path for the
    current workbook.

    If the Path is not equal to the expected location, I want to close the
    active file and kill it as part of the subroutine.

    Is this possible? I've tried several variations of the KILL command, but to
    no avail.

  2. #2
    NickHK
    Guest

    Re: Kill a File

    You mean you are trying to check the path (and possibly Kill) a file from
    within it's own Workbook_Open event ?
    You can't Kill an open file, so this will fail. You have seen a Permission
    denied error.

    Why not check the path before you open it, as you must know the path in
    order to open it.
    If it is wrong, Kill it.

    NickHK

    "Posse John" <[email protected]> wrote in message
    news:[email protected]...
    > I have a file with the Workbook_Open routine looking at the Path for the
    > current workbook.
    >
    > If the Path is not equal to the expected location, I want to close the
    > active file and kill it as part of the subroutine.
    >
    > Is this possible? I've tried several variations of the KILL command, but

    to
    > no avail.




  3. #3
    Dave Peterson
    Guest

    Re: Kill a File

    option explicit
    sub workbook_open()

    dim myPath as string
    mypath = "c:\my documents\excel"

    if lcase(me.path) <> lcase(mypath) then
    Application.DisplayAlerts=False
    me.ChangeFileAccess xlReadOnly
    Kill me.FullName
    me.Close savechanges:=False
    end if

    end sub

    This is not a nice thing to do (in my opinion). I hope that the user has a
    backup and that he/she didn't save anything important to the file in that other
    location.

    I wouldn't do it.

    Posse John wrote:
    >
    > I have a file with the Workbook_Open routine looking at the Path for the
    > current workbook.
    >
    > If the Path is not equal to the expected location, I want to close the
    > active file and kill it as part of the subroutine.
    >
    > Is this possible? I've tried several variations of the KILL command, but to
    > no avail.


    --

    Dave Peterson

+ 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