PDA

View Full Version : Solved: Prevent me from deleting a folder



mvidas
05-11-2005, 01:16 PM
Hi Everyone,

My Inbox has a few subfolders that I use rules to divy the messages into the appropriate folder. There is one folder that I Scott probably 99% of the messages in. When I Scott a message I use shift-delete so it doesn't even go into Scotted items, however sometimes the focus is on the foldername and not the message itself, so when I press shift-delete/enter (something my fingers are well trained for) I end up completely pulling a Scott on the entire subfolder.

I can't seem to find a setting to prevent this, so is there a vba solution (or anything) that will help me do this?

I was thinking there might be an event triggered when something is deleted. When the item being Scotted is a folder then something like this happens:
If MsgBox("You are Scotting a folder, are you sure you really want to do this?", _
vbOKCancel + vbDefaultButton2, "Don't be an idiot") = vbCancel Then
'code to prevent the folder from the wrath of Scott
End If

I'm a newbie at outlook code, so I don't know what the events are or anything. Any help would be great, as I'm sick of Scotting the folder and having to recreate it (and losing the 1% of messages I want when it happens).

Thanks
Matt

MOS MASTER
05-11-2005, 02:10 PM
Hi Matt, :D

I think this is going to extremly hard!

Outlook has an eventhandler: FolderRemove() (look it up)

The problem however is that it has no cancelable event attached to it. And that's a real shame...

But you never no.

The strange thing is that I think this problem must be version specific. Which version are you using.

I'm using 2003 and if I press SHIFT+DELETE I still get a confirmation dialog if I really want to delete this folder?

:whistle:

mdmackillop
05-11-2005, 02:28 PM
How about:
If Folder.Deleted = True then
With PayPal
.Mvidas > Vbax ($10, Donate)
End With
End If

mvidas
05-11-2005, 02:37 PM
Joost,

I will definately take a look when I get home (which is where I need this) and report back later to let you know what I found if anything. I'm using ol2000, and it does ask me to confirm it. But since I am so used to pressing Shift-Delete then Enter to remove the message completely, the same sequence of keys removes the folders. I could just be less of an idiot and actually make sure each time that I'm not on a folder, but I've tried that and since I can be an idiot, it doesn't always work :)

Malcolm,
I definately should donate something here! I remember when I wanted to paypal you a pint after all your help with one of my projects a few months back (outlook to excel maybe? or maybe my text files procedure? who knows). We'll see how it goes on my next payday :)


If Folder.Deleted = True Then
With mvidas
.Idiot = True 'Again
.PayPal.Donate(Recipient:=vbax, Amount:=10)
End With
End If

mdmackillop
05-11-2005, 02:46 PM
Thanks for the correction. I think you should submit it to the KB.

Ken Puls
05-11-2005, 03:42 PM
Wow! I never would have expected Matt to raise this kind of an issue. If something told me there was a thread asking how to prevent them from deleting somthing, my money would for sure have been on Scott! :devil:

An interesting question though... :yes

Steiner
05-11-2005, 11:23 PM
Unfortunately my Outlook seems to be too old, as I don't have a FolderRemove-event. But should it not be possible to simply copy the folder to a save location (maybe your "personal Recycle bin") and then let Outlook delete what it wants to delete.

Daniel

mvidas
05-12-2005, 06:40 AM
Daniel,
From the help file it looks like folderremove was added in outlook 2000, if that helps.

Ken,
:) I don't quite know Scotts track record for deleting things other than a few threads on here, but I've probably deleted this &*%$! folder (and one other) 5 or 6 times!

Joost,
I got the FolderRemove to work, but unfortunately it fires after the folder has been deleted. I don't use the outlook bar otherwise I could use BeforeGroupRemove, maybe a future version will include BeforeFolderRemove :)

I'm just going to have to keep it the same way, but I'll move the messages I want into my normal inbox so when I delete the folder again I won't go crazy over what I just lost.

Thanks everyone!
Matt

Ken Puls
05-12-2005, 08:18 AM
ROTFL!

Nice Edits, Matt!

VBAX Dictionary:
Scott (v) To delete by accident

:rotlaugh:

MOS MASTER
05-12-2005, 10:34 AM
Joost,
But since I am so used to pressing Shift-Delete then Enter to remove the message completely, the same sequence of keys removes the folders.
Haha..yepz missed this one...:rofl: (That will delete it for me aswell)

@Malcolm..ROTFL!...that was great! :yes

MOS MASTER
05-12-2005, 10:35 AM
Unfortunately my Outlook seems to be too old, as I don't have a FolderRemove-event. But should it not be possible to simply copy the folder to a save location (maybe your "personal Recycle bin") and then let Outlook delete what it wants to delete.

Daniel
Hi Daniel, :D

Are you using Outlook 97?

Office adds more events on the way up so yes the lower versions don't have some events...:whistle: (But this one isn't much good to begin with because it lacks a Cancel...)

MOS MASTER
05-12-2005, 10:39 AM
Daniel,
From the help file it looks like folderremove was added in outlook 2000, if that helps.

Hi Matt...answered to this as well I should learn to scroll down first! :banghead:


Joost,
I got the FolderRemove to work, but unfortunately it fires after the folder has been deleted. I don't use the outlook bar otherwise I could use BeforeGroupRemove, maybe a future version will include BeforeFolderRemove :)

Hi Matt, :D

You're welcome!

Could you post the exact code your using and can you explain in which objects you've put them in the VBE? (Class/module,etc..)

I like to have a go with it and experiment a bit more...

Enjoy! :whistle:

mvidas
05-12-2005, 11:51 AM
Sure thing, Joost. I didn't use the class object method (I only saw one example of it, and the outcome seemed to be the same as what I encountered). I just have the following in my ThisOutlookSession
Dim WithEvents myFolders As Folders

Private Sub Application_Startup()
Initialize_EventHandler
End Sub

Sub Initialize_EventHandler()
Dim myNS As NameSpace
Set myNS = Application.GetNamespace("MAPI")
Set myFolders = myNS.GetDefaultFolder(olFolderInbox).Folders
End Sub

Private Sub myFolders_FolderRemove()
Stop 'folderremove event triggered
End Sub

Experiment all you want! I'd love to see this work, and as this is probably only my 4th foray into the outlook model I don't think I know enough to get it to work.
Thanks! If you can't get it to work, no harm done. Thanks again!!
Matt

MOS MASTER
05-12-2005, 12:00 PM
Hi Matt, :D

Ah ok you're using the example code thats fine.

Building something now so I'll play with it later. :whistle:

Steiner
05-12-2005, 10:32 PM
Hi Joost,
I use Outlook 2000. And of course it has that event, I was just too stupid :banghead: to find it, because I simply looked at the application object.
I just did not think the Folder object has an event FolderRemove :doh: . Matt's sample code showed me that mistake...

Daniel

MOS MASTER
05-13-2005, 10:43 AM
Hi Joost,
I use Outlook 2000. And of course it has that event, I was just too stupid :banghead: to find it, because I simply looked at the application object.
I just did not think the Folder object has an event FolderRemove :doh: . Matt's sample code showed me that mistake...

Daniel
Hi Daniel, :D

Yes I know what you mean. Outlook has quite a lot off special events so you can overlook some of them! (Been there...done that)

@Matt,

I've been working on a sollution trying to sendkeys (ESC) it out of there but it's not working!

Told you it would be hard...but still thinking about it. :think:

Tommy
05-13-2005, 10:51 AM
When the myFolders_FolderRemove fires the folder is already deleted. So I am taking the approach of copying the mail items from the deleted folder to the "new" folder. Not a real solution but may be a handy little work around until a better one comes up. :)

MOS MASTER
05-13-2005, 11:27 AM
Hi Tommy, :D

Yepz it's a workaround but I'm sure there has to be a way to get this done with a simpler method...(don't know how yet ...)

:whistle:

Tommy
05-13-2005, 11:34 AM
I had it and it disapeared. :dunno I got it to work 3 times and BOOM no wanna play no more.:yes I guess I cleaned up more than I should have. I am using the MoveTo method. Be back later with more details.:rotlaugh:

MOS MASTER
05-13-2005, 11:40 AM
I had it and it disapeared. :dunno I got it to work 3 times and BOOM no wanna play no more.:yes I guess I cleaned up more than I should have. I am using the MoveTo method. Be back later with more details.:rotlaugh:
Sounds you're having a ball over there! :rofl:

Perhaps wise to export your *pst file at this moment! :whip

Tommy
05-13-2005, 11:51 AM
Oh Yeah!:rotlaugh:

Ok try this one. I can place a break in the class to step through, and it works. I stop outlook and restart it it asks if I want to enable macros I pick enable macros and it complains or does nothing. The folder does not move.

I can only get it to work about 3 times in step mode. :dunno

And Yes I butchered some help files :wot

Anyway if some one else wants to play:
In a class1

Dim myolapp As New Outlook.Application
Dim WithEvents myFolders As Outlook.Folders
Sub Initialize_handler()
Dim myNs As NameSpace
Set myNs = myolapp.GetNamespace("MAPI")
Set myFolders = myNs.GetDefaultFolder(olFolderInbox).Folders
End Sub
Private Sub myFolders_FolderRemove()
Dim MvitBck As Outlook.Folders
Dim myNs As NameSpace
Set myNs = myolapp.GetNamespace("MAPI")
Set MvitBck = myNs.GetDefaultFolder(olFolderDeletedItems).Folders
For i = 1 To MvitBck.Count
If Not MvitBck("kepfromdelete") Is Nothing Then
On Error Resume Next
MvitBck("kepfromdelete").MoveTo myNs.GetDefaultFolder(olFolderInbox)
Err.Clear
On Error GoTo 0
End If
Next
Set MvitBck = Nothing
End Sub



In ThisOutlookSession


Private AllDay As Class1

Private Sub Application_Startup()
Set AllDay = New Class1
AllDay.Initialize_handler
End Sub

MOS MASTER
05-13-2005, 12:03 PM
Hi Tommy, :D

The problem however is that Matt has a passion For SHIFT+DELETE+ENTER....yepz you've guessed it the folder is now totaly gone! :rofl:

But I like the approach and look at it later because most user just use Delete and could benefit from it! :whip

MOS MASTER
05-13-2005, 02:33 PM
Hi Tommy, :D

So done with the rest of the questions play time now!

It seams your code will trigger an error because excecution seams to fast! (That's great)

So we have to give Outlook some more time to proces the folder move!
We could set-up a timer but over here the error seams to vanish after I put one littel DoEvents (Yield to the system) in the sub!

For testing purposes all is in ThisOutlookSession so just copy paste it in there:
Option Explicit
Dim myNs As Outlook.NameSpace
Dim WithEvents myFolders As Outlook.Folders

Sub Initialize_handler()
Set myNs = Application.GetNamespace("MAPI")
Set myFolders = Application.GetNamespace("MAPI").GetDefaultFolder(olFolderInbox).Folders
End Sub

Private Sub myFolders_FolderRemove()
Dim i As Integer
Dim MvitBck As Outlook.Folders
Dim myNs As Outlook.NameSpace

Set myNs = Application.GetNamespace("MAPI")
Set MvitBck = myNs.GetDefaultFolder(olFolderDeletedItems).Folders

For i = 1 To MvitBck.Count
If Not MvitBck("kepfromdelete") Is Nothing Then
DoEvents
MvitBck("kepfromdelete").MoveTo myNs.GetDefaultFolder(olFolderInbox)
End If
Next
Set MvitBck = Nothing
End Sub
Private Sub Application_Startup()
Initialize_handler
End Sub


Could you test it and confirm it also works for you! :whistle:

Tommy
05-16-2005, 06:38 AM
Confirmed. XP pro, Office 2000 will test on XP home, Office 2003 tonight.


I figured it was the myolapp As New Outlook.Application, I thought I was looking one way and working another way :rofl: since it seemed like I was cross referencing I had not considered not enough time for processing.:thumb

MOS MASTER
05-16-2005, 11:53 AM
Confirmed. XP pro, Office 2000 will test on XP home, Office 2003 tonight.


I figured it was the myolapp As New Outlook.Application, I thought I was looking one way and working another way :rofl: since it seemed like I was cross referencing I had not considered not enough time for processing.:thumb
Ah Great to see.

Well first I comment out you're Error handlings so I could get a real error msg from vba and when I had that one and code stepping worked flawlesly....

one and one got two!

Glad to see it's working on your side as well.:whistle:

mvidas
05-16-2005, 11:59 AM
I know it sounds strange but I use my deleted items folder as more of a "saved old messages" folder so my inbox doesn't get too large :) my fingers are so used to shift-delete-enter from windows explorer too, cant teach them any new tricks!

MOS MASTER
05-16-2005, 12:03 PM
I know it sounds strange but I use my deleted items folder as more of a "saved old messages" folder so my inbox doesn't get too large :) my fingers are so used to shift-delete-enter from windows explorer too, cant teach them any new tricks!
ROTFL! :devil: :rotlaugh: :rofl:

Tommy
05-16-2005, 12:28 PM
LOL, they say that about old dogs too :yes (cant teach them any new tricks) :whip

mdmackillop
05-16-2005, 12:50 PM
Not really "on topic" but for those of you who get emails advising of any new posts, Dave came up with some useful code to move duplicate entries.
http://www.vbaexpress.com/forum/showthread.php?t=1267

mvidas
05-16-2005, 01:09 PM
Good call Malcolm, I use something just like that at home! I had to mark the moved ones as read though, otherwise my 'dups' folder had too many unread messages in it :) I wish it was faster, but from all my playing around I don't think it is possible.
When I get home I'll compare it to Dave's and Howard's methods, see if theirs are any faster. Thanks for the link!

mdmackillop
05-16-2005, 01:27 PM
Hi Matt,
Since they are duplicates, I find it doesn't matter if they are marked Read or not, I check the ones left in the Inbox and just empty the Duplicates folder occasionally.

Tommy
05-16-2005, 05:15 PM
Hi MOS MASTER, :hi:
Not confirmed, does not work with XP home and office 2003. I probably wasn't holding my mouth right, :banghead: but I couldn't get it to even fire the event. I busted it out to class... and still couldn't get it to fire. I did notice that the Class_Terminate fired right after the Class_Initialize. I even set the security to low, and still no go. :dunno
Go figure.

MOS MASTER
05-17-2005, 09:54 AM
Hi Tommy, :D

Strange over here it's working on Office XP and 2003???

Oh well...if there's time we'll try something else...

Don't know if I can program Matt fingers yet...:rofl:

mvidas
05-17-2005, 10:02 AM
Don't know if I can program Matt fingers yet...:rofl: Function ReprogramFingers(ByVal vUserName As String, ByVal oldKeyComb As String, _
ByVal newKeyComb As String) As Boolean
'Requires reference to "impossible.dll" found during standard installation at
' C:\Matt\can\be\an\idiot\and\wishes\MS\had\a\read\only\setting\for\folders\
Dim vUser As EndUser
Set vUser = EndUsers(vUserName)
If vUser.DeleteFolders = oldKeyComb Then
vUser.DeleteFolders = newKeyComb
Else
MsgBox "D'oh!"
End If
End Function

Tommy
05-17-2005, 10:26 AM
:hi: By the looks of it, Matt is having a problem with programming his fingers also :rofl: Of course I could really use the "impossible.dll" sounds like we all could use some of the functionality found there!:rotlaugh:


I forgot my reading glasses so I could have been coding ummm who knows what! I started to get flustered when the events didn't fire, I'll look at it again, I was thinking on a keyboard hook for Matt's fingers using API but then we really start getting OS specific not to mention Office specific. May just be better to make an exe to help him out in Explorer also.:)

MOS MASTER
05-17-2005, 10:45 AM
Function ReprogramFingers(ByVal vUserName As String, ByVal oldKeyComb As String, _
ByVal newKeyComb As String) As Boolean
'Requires reference to "impossible.dll" found during standard installation at
' C:\Matt\can\be\an\idiot\and\wishes\MS\had\a\read\only\setting\for\folders\
Dim vUser As EndUser
Set vUser = EndUsers(vUserName)
If vUser.DeleteFolders = oldKeyComb Then
vUser.DeleteFolders = newKeyComb
Else
MsgBox "D'oh!"
End If
End Function
Truly Magnificent! :rofl:

Yes like Tommy I'd like to receive a copy of "Impossible.dll" and I'm sure many others want it is wel..

You should enter it as a kbEntry...this will make a great add! :rotlaugh: