Consulting

Page 1 of 2 1 2 LastLast
Results 1 to 20 of 36

Thread: Solved: Prevent me from deleting a folder

  1. #1
    Knowledge Base Approver
    The King of Overkill!
    VBAX Master
    Joined
    Jul 2004
    Location
    Rochester, NY
    Posts
    1,727
    Location

    Solved: Prevent me from deleting a folder

    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:
    [vba]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[/vba]

    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

  2. #2
    Administrator
    VP-Knowledge Base VBAX Guru MOS MASTER's Avatar
    Joined
    Apr 2005
    Location
    Breda, The Netherlands
    Posts
    3,281
    Location
    Hi Matt,

    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?

    _________
    Groetjes,

    Joost Verdaasdonk
    M.O.S. Master

    Mark your thread solved, when it has been, by hitting the Thread Tools dropdown at the top of the thread.
    (I don't answer questions asked through E-mail or PM's)

  3. #3
    Administrator
    VP-Knowledge Base
    VBAX Grand Master mdmackillop's Avatar
    Joined
    May 2004
    Location
    Scotland
    Posts
    14,489
    Location
    How about:
    [VBA] If Folder.Deleted = True then
    With PayPal
    .Mvidas > Vbax ($10, Donate)
    End With
    End If
    [/VBA]
    MVP (Excel 2008-2010)

    Post a workbook with sample data and layout if you want a quicker solution.


    To help indent your macros try Smart Indent

    Please remember to mark threads 'Solved'

  4. #4
    Knowledge Base Approver
    The King of Overkill! VBAX Master
    Joined
    Jul 2004
    Location
    Rochester, NY
    Posts
    1,727
    Location
    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
    [vba]
    If Folder.Deleted = True Then
    With mvidas
    .Idiot = True 'Again
    .PayPal.Donate(Recipient:=vbax, Amount:=10)
    End With
    End If
    [/vba]

  5. #5
    Administrator
    VP-Knowledge Base VBAX Grand Master mdmackillop's Avatar
    Joined
    May 2004
    Location
    Scotland
    Posts
    14,489
    Location
    Thanks for the correction. I think you should submit it to the KB.
    MVP (Excel 2008-2010)

    Post a workbook with sample data and layout if you want a quicker solution.


    To help indent your macros try Smart Indent

    Please remember to mark threads 'Solved'

  6. #6
    Moderator VBAX Guru Ken Puls's Avatar
    Joined
    Aug 2004
    Location
    Nanaimo, BC, Canada
    Posts
    4,001
    Location
    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!

    An interesting question though...
    Ken Puls, CMA - Microsoft MVP (Excel)
    I hate it when my computer does what I tell it to, and not what I want it to.

    Learn how to use our KB tags! -||- Ken's Excel Website -||- Ken's Excel Forums -||- My Blog -||- Excel Training Calendar

    This is a shameless plug for my new book "RibbonX - Customizing the Office 2007 Ribbon". Find out more about it here!

    Help keep VBAX clean! Use the 'Thread Tools' menu to mark your own threads solved!





  7. #7
    VBAX Tutor
    Joined
    May 2004
    Location
    Germany, Dresden
    Posts
    217
    Location
    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

  8. #8
    Knowledge Base Approver
    The King of Overkill! VBAX Master
    Joined
    Jul 2004
    Location
    Rochester, NY
    Posts
    1,727
    Location
    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

  9. #9
    Moderator VBAX Guru Ken Puls's Avatar
    Joined
    Aug 2004
    Location
    Nanaimo, BC, Canada
    Posts
    4,001
    Location
    ROTFL!

    Nice Edits, Matt!

    VBAX Dictionary:
    Scott (v) To delete by accident

    Ken Puls, CMA - Microsoft MVP (Excel)
    I hate it when my computer does what I tell it to, and not what I want it to.

    Learn how to use our KB tags! -||- Ken's Excel Website -||- Ken's Excel Forums -||- My Blog -||- Excel Training Calendar

    This is a shameless plug for my new book "RibbonX - Customizing the Office 2007 Ribbon". Find out more about it here!

    Help keep VBAX clean! Use the 'Thread Tools' menu to mark your own threads solved!





  10. #10
    Administrator
    VP-Knowledge Base VBAX Guru MOS MASTER's Avatar
    Joined
    Apr 2005
    Location
    Breda, The Netherlands
    Posts
    3,281
    Location
    Quote Originally Posted by mvidas
    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... (That will delete it for me aswell)

    @Malcolm..ROTFL!...that was great!
    _________
    Groetjes,

    Joost Verdaasdonk
    M.O.S. Master

    Mark your thread solved, when it has been, by hitting the Thread Tools dropdown at the top of the thread.
    (I don't answer questions asked through E-mail or PM's)

  11. #11
    Administrator
    VP-Knowledge Base
    VBAX Guru MOS MASTER's Avatar
    Joined
    Apr 2005
    Location
    Breda, The Netherlands
    Posts
    3,281
    Location
    Quote Originally Posted by Steiner
    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,

    Are you using Outlook 97?

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

    Joost Verdaasdonk
    M.O.S. Master

    Mark your thread solved, when it has been, by hitting the Thread Tools dropdown at the top of the thread.
    (I don't answer questions asked through E-mail or PM's)

  12. #12
    Administrator
    VP-Knowledge Base
    VBAX Guru MOS MASTER's Avatar
    Joined
    Apr 2005
    Location
    Breda, The Netherlands
    Posts
    3,281
    Location
    Quote Originally Posted by mvidas
    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!
    Quote Originally Posted by mvidas
    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,

    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!
    _________
    Groetjes,

    Joost Verdaasdonk
    M.O.S. Master

    Mark your thread solved, when it has been, by hitting the Thread Tools dropdown at the top of the thread.
    (I don't answer questions asked through E-mail or PM's)

  13. #13
    Knowledge Base Approver
    The King of Overkill!
    VBAX Master
    Joined
    Jul 2004
    Location
    Rochester, NY
    Posts
    1,727
    Location
    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
    [vba]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[/vba]

    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

  14. #14
    Administrator
    VP-Knowledge Base VBAX Guru MOS MASTER's Avatar
    Joined
    Apr 2005
    Location
    Breda, The Netherlands
    Posts
    3,281
    Location
    Hi Matt,

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

    Building something now so I'll play with it later.
    _________
    Groetjes,

    Joost Verdaasdonk
    M.O.S. Master

    Mark your thread solved, when it has been, by hitting the Thread Tools dropdown at the top of the thread.
    (I don't answer questions asked through E-mail or PM's)

  15. #15
    VBAX Tutor
    Joined
    May 2004
    Location
    Germany, Dresden
    Posts
    217
    Location
    Hi Joost,
    I use Outlook 2000. And of course it has that event, I was just too stupid to find it, because I simply looked at the application object.
    I just did not think the Folder object has an event FolderRemove . Matt's sample code showed me that mistake...

    Daniel

  16. #16
    Administrator
    VP-Knowledge Base
    VBAX Guru MOS MASTER's Avatar
    Joined
    Apr 2005
    Location
    Breda, The Netherlands
    Posts
    3,281
    Location
    Quote Originally Posted by Steiner
    Hi Joost,
    I use Outlook 2000. And of course it has that event, I was just too stupid to find it, because I simply looked at the application object.
    I just did not think the Folder object has an event FolderRemove . Matt's sample code showed me that mistake...

    Daniel
    Hi Daniel,

    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.
    _________
    Groetjes,

    Joost Verdaasdonk
    M.O.S. Master

    Mark your thread solved, when it has been, by hitting the Thread Tools dropdown at the top of the thread.
    (I don't answer questions asked through E-mail or PM's)

  17. #17
    Moderator VBAX Master Tommy's Avatar
    Joined
    May 2004
    Location
    Houston, TX
    Posts
    1,184
    Location
    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.

  18. #18
    Administrator
    VP-Knowledge Base
    VBAX Guru MOS MASTER's Avatar
    Joined
    Apr 2005
    Location
    Breda, The Netherlands
    Posts
    3,281
    Location
    Hi Tommy,

    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 ...)

    _________
    Groetjes,

    Joost Verdaasdonk
    M.O.S. Master

    Mark your thread solved, when it has been, by hitting the Thread Tools dropdown at the top of the thread.
    (I don't answer questions asked through E-mail or PM's)

  19. #19
    Moderator VBAX Master Tommy's Avatar
    Joined
    May 2004
    Location
    Houston, TX
    Posts
    1,184
    Location
    I had it and it disapeared. I got it to work 3 times and BOOM no wanna play no more. I guess I cleaned up more than I should have. I am using the MoveTo method. Be back later with more details.

  20. #20
    Administrator
    VP-Knowledge Base
    VBAX Guru MOS MASTER's Avatar
    Joined
    Apr 2005
    Location
    Breda, The Netherlands
    Posts
    3,281
    Location
    Quote Originally Posted by Tommy
    I had it and it disapeared. I got it to work 3 times and BOOM no wanna play no more. I guess I cleaned up more than I should have. I am using the MoveTo method. Be back later with more details.
    Sounds you're having a ball over there!

    Perhaps wise to export your *pst file at this moment!
    _________
    Groetjes,

    Joost Verdaasdonk
    M.O.S. Master

    Mark your thread solved, when it has been, by hitting the Thread Tools dropdown at the top of the thread.
    (I don't answer questions asked through E-mail or PM's)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •