Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 18
Default Delete (Kill) Active Workbook

Hi,
I'd like to open an existing file, save it automatically by macro in a
different location with a new file name. This portion i can do. I'd like then
to delete the original, still active/open workbook. Any suggestions?
Thank you,
Stefan
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 129
Default Delete (Kill) Active Workbook

Hi,

Here is an example:

Sub Test()
On Error GoTo ErrorHandler
If ActiveWorkbook.Path < "" Then
If Not ActiveWorkbook.ReadOnly Then
ActiveWorkbook.Saved = True
ActiveWorkbook.ChangeFileAccess xlReadOnly
End If
Kill ActiveWorkbook.FullName
End If
Exit Sub

ErrorHandler:
MsgBox "Fail to delete file: " & ActiveWorkbook.FullName
Exit Sub

End Sub

I am not sure it is perfectly all right.
I recommend to close the workbook after deleted.

--
HTH

okaizawa

stefan via OfficeKB.com wrote:
Hi,
I'd like to open an existing file, save it automatically by macro in a
different location with a new file name. This portion i can do. I'd like then
to delete the original, still active/open workbook. Any suggestions?
Thank you,
Stefan

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,120
Default Delete (Kill) Active Workbook

Why bother testing if readonly, just set it

Sub Test()
On Error GoTo ErrorHandler
With ActiveWorkbook
If .Path < "" Then
.Saved = True
.ChangeFileAccess xlReadOnly
Kill ActiveWorkbook.FullName
End If
End With
Exit Sub

ErrorHandler:
MsgBox "Fail to delete file: " & ActiveWorkbook.FullName
Exit Sub

End Sub


--
HTH

Bob Phillips

"okaizawa" wrote in message
...
Hi,

Here is an example:

Sub Test()
On Error GoTo ErrorHandler
If ActiveWorkbook.Path < "" Then
If Not ActiveWorkbook.ReadOnly Then
ActiveWorkbook.Saved = True
ActiveWorkbook.ChangeFileAccess xlReadOnly
End If
Kill ActiveWorkbook.FullName
End If
Exit Sub

ErrorHandler:
MsgBox "Fail to delete file: " & ActiveWorkbook.FullName
Exit Sub

End Sub

I am not sure it is perfectly all right.
I recommend to close the workbook after deleted.

--
HTH

okaizawa

stefan via OfficeKB.com wrote:
Hi,
I'd like to open an existing file, save it automatically by macro in a
different location with a new file name. This portion i can do. I'd like

then
to delete the original, still active/open workbook. Any suggestions?
Thank you,
Stefan



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 129
Default Delete (Kill) Active Workbook

Bob,

Why bother testing if readonly, just set it

That is only an example.
If a workbook is readonly, "ChangeFileAccess xlReadOnly" fails.
(I use Excel 2000)

--
Regards,
okaizawa
  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 18
Default Delete (Kill) Active Workbook

Hello Bob, Hello okaizawa,

Thank you for your help. This works. I went without the fail-save-option as i
am controling the workbooks that are being processed and none would be
readonly to begin with. So it should not be an issue... if so, i'd confuse
the user one way or another anyway. ;-)

Thank you again.

Stefan

okaizawa wrote:
Bob,

Why bother testing if readonly, just set it

That is only an example.
If a workbook is readonly, "ChangeFileAccess xlReadOnly" fails.
(I use Excel 2000)



--
Message posted via OfficeKB.com
http://www.officekb.com/Uwe/Forums.a...mming/200507/1
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
How can I delete a macro when the Delete button is not active? FCR Excel Worksheet Functions 0 March 9th 06 09:43 AM
copy worksheet from closed workbook to active workbook using vba mango Excel Worksheet Functions 6 December 9th 04 07:55 AM
Preventing opening workbook inside active workbook. Serge[_4_] Excel Programming 2 November 4th 03 07:51 PM
Delete Characters in an active cell Don[_9_] Excel Programming 1 September 12th 03 07:01 PM
Delete row where active cell is located using VBA Jeff Marshall Excel Programming 3 July 19th 03 05:55 PM


All times are GMT +1. The time now is 01:54 AM.

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

About Us

"It's about Microsoft Excel"