#1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 9
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4,391
Default 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" wrote in message
...
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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default 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
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Kill Michael Excel Programming 2 August 23rd 05 11:53 AM
'Kill' solomon_monkey Excel Programming 7 January 7th 05 09:56 AM
File kill help Marino13[_6_] Excel Programming 0 February 19th 04 01:40 PM
kill worksheets portroe Excel Programming 2 January 25th 04 11:11 PM
AutoFill KILL Frustrated[_2_] Excel Programming 1 July 29th 03 04:40 PM


All times are GMT +1. The time now is 04:11 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"