Delete, w/ copy to Recycle Bin

E

Ed

Surely there is a way to 'kill' (delete) a document via VBA but first send a
copy of it to the recycle bin, but I'll be darned if I can figure it out. Is
there any literature on this?

Thanks,

Ed
 
S

Steve Yandl

Ed,

This short script between the dotted lines could be incorporated into a VBA
routine and used to send some file existing in a folder to the recycle bin.
The example simply sends a file named "pic.tif" that's located in "C:\Test"
to the recycle bin. From your VBA routine, you would establish a file name,
do a SaveAs before running the code to send to the recycle bin and then
close the open document without saving changes.
_ _ _ _ _ _ _ _ _ _ _ _

Set objShell = CreateObject("Shell.Application")
Set objFolder = objShell.Namespace("C:\Test")
Set objFolderItem = objFolder.ParseName("pic.tif")

objFolderItem.InvokeVerb("&Delete")

_ _ _ _ _ _ _ _ _ _ _ _

The problem is that depending on the user's version of Windows and the
settings for recycle bin, the user is likely to get a dialog requesting
confirmation that they want to send the file to the recycle bin. The script
above simply replicates what happens when you right click a file in Windows
Explorer and choose "delete" from the context menu.

I've been working on a script that would write some binary data to the
registry and toggle the setting in recycle bin on user notification off to
make it simpler to send files to the bin through code but I've not finished
yet. Moveover, I suspect it will only work on WinXP and possibly Win2k.

Steve
 
E

Ed

Steve,

Thanks. I will give this a try.

Roy

Steve Yandl said:
Ed,

This short script between the dotted lines could be incorporated into a
VBA routine and used to send some file existing in a folder to the recycle
bin. The example simply sends a file named "pic.tif" that's located in
"C:\Test" to the recycle bin. From your VBA routine, you would establish
a file name, do a SaveAs before running the code to send to the recycle
bin and then close the open document without saving changes.
_ _ _ _ _ _ _ _ _ _ _ _

Set objShell = CreateObject("Shell.Application")
Set objFolder = objShell.Namespace("C:\Test")
Set objFolderItem = objFolder.ParseName("pic.tif")

objFolderItem.InvokeVerb("&Delete")

_ _ _ _ _ _ _ _ _ _ _ _

The problem is that depending on the user's version of Windows and the
settings for recycle bin, the user is likely to get a dialog requesting
confirmation that they want to send the file to the recycle bin. The
script above simply replicates what happens when you right click a file in
Windows Explorer and choose "delete" from the context menu.

I've been working on a script that would write some binary data to the
registry and toggle the setting in recycle bin on user notification off to
make it simpler to send files to the bin through code but I've not
finished yet. Moveover, I suspect it will only work on WinXP and possibly
Win2k.

Steve
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top