Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.misc
gemnnsw
 
Posts: n/a
Default Delete excel spreadsheets within excel


Can anyone please advise how to delete excel spreadsheets within excel,
rather than doing this through windows explorer. This would be
particularly useful after viewing a spreadsheet and then deciding it
was no longer needed and could be deleted on the spot.


--
gemnnsw
------------------------------------------------------------------------
gemnnsw's Profile: http://www.excelforum.com/member.php...o&userid=30456
View this thread: http://www.excelforum.com/showthread...hreadid=501225

  #2   Report Post  
Posted to microsoft.public.excel.misc
Paul B
 
Posts: n/a
Default Delete excel spreadsheets within excel

gemnnsw, here is one way, put in your personal workbook code

Option Explicit
'delete open file in Excel, run DeleteThisFile
'By: Jonathan West
'This code is based on Randy Birch's article at
'http://www.mvps.org/vbnet/index.html?code/shell/recyclebin.htm


Private Type SHFILEOPSTRUCT
hWnd As Long
wFunc As Long
pFrom As String
pTo As String
fFlags As Integer
fAborted As Boolean
hNameMaps As Long
sProgress As String
End Type

Private Const FO_DELETE As Long = &H3
Private Const FOF_ALLOWUNDO As Long = &H40
Private Const FOF_NOCONFIRMATION = &H10 ' Don't prompt the user

Private Declare Function SHFileOperation Lib "shell32" _
Alias "SHFileOperationA" _
(lpFileOp As SHFILEOPSTRUCT) As Long

Public Sub SendToRecycle(sFile As String, Optional bConfirm As Boolean =
False)

'set some working variables
Dim shf As SHFILEOPSTRUCT

'terminate the file string with
'a pair of null chars
sFile = sFile & vbNullChar & vbNullChar

'set up the SHFile options
With shf
.wFunc = FO_DELETE 'action to perform
.pFrom = sFile 'the file to act on
If bConfirm Then
.fFlags = FOF_ALLOWUNDO 'special flags
Else
.fFlags = FOF_ALLOWUNDO Or FOF_NOCONFIRMATION 'special flags
End If
End With

'perform the delete
Call SHFileOperation(shf)

End Sub

Sub DeleteThisFile()
Dim MyFile As String

MyFile = ActiveWorkbook.Path + "\" + ActiveWorkbook.Name
If MsgBox(MyFile + " will be deleted !" & vbLf & vbLf & _
" Do you want to delete this file?", _
vbYesNo, "Delete this File?") = vbYes Then
Application.DisplayAlerts = False
ActiveWorkbook.Close

SendToRecycle MyFile

'***comment above and uncomment below to bypass the recycling
bin
'Kill MyFile
End If
Application.DisplayAlerts = True
End Sub


--
Paul B
Always backup your data before trying something new
Please post any response to the newsgroups so others can benefit from it
Feedback on answers is always appreciated!
Using Excel 2002 & 2003

"gemnnsw" wrote in
message ...

Can anyone please advise how to delete excel spreadsheets within excel,
rather than doing this through windows explorer. This would be
particularly useful after viewing a spreadsheet and then deciding it
was no longer needed and could be deleted on the spot.


--
gemnnsw
------------------------------------------------------------------------
gemnnsw's Profile:

http://www.excelforum.com/member.php...o&userid=30456
View this thread: http://www.excelforum.com/showthread...hreadid=501225



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
excel file deleted. Now howdo you delete file NAME NANMAC New Users to Excel 8 September 2nd 05 07:26 AM
Can't print a group of spreadsheets Excel 2003 DebbyD Excel Discussion (Misc queries) 1 August 31st 05 09:10 PM
How can we delete rows permanently from excel sheet Nehal Shah Excel Discussion (Misc queries) 1 August 1st 05 01:58 PM
can't delete a cell content in excel Mark B New Users to Excel 3 May 6th 05 06:42 PM
Viewing Excel spreadsheets Jimbola Excel Discussion (Misc queries) 1 November 28th 04 06:59 PM


All times are GMT +1. The time now is 07:34 PM.

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"