Hi,
I would like to use this event that I found in "http://msdn.microsoft.com/en-us/libr...ffice.12).aspx" web page. They say that:
"The sample code must be placed in a class module, and the Initialize_handler routine must be called before the event procedure can be called by Microsoft Outlook."
I really do not undestand where I have to put the code!
Dim WithEvents myFolders As Outlook.Folders Sub Initialize_handler() Set myNS = Application.GetNamespace("MAPI") Set myFolders = myNS.GetDefaultFolder(olFolderDeletedItems).Folders End Sub Private Sub myFolders_FolderChange(ByVal Folder As Outlook.Folder) If Folder.Items.Count = 0 Then MyPrompt = Folder.Name & " is empty. Do you want to delete it?" If MsgBox(MyPrompt, vbYesNo + vbQuestion) = vbYes Then Folder.Delete End If End If End Sub
A hint would be fine.
Regards,
Elio Fernandes
Hello
Try this one:
Open Outlook---
1. Click File --> Option
2. Look for Customized Ribbon --> then clcik the box in Developer (left window pane)
Ok.
you'll notice the Developer menu
1.Click the VBA Icon on the left side of the screen Under File menu.
2. Next will be the vba window-->click insert then choose Module
a small window will appear paste your code there.
First code
Next double click the Microsoft Outlook Object( a folder - left side of screen)Dim WithEvents myFolders As Outlook.Folders Sub Initialize_handler() Set myNS = Application.GetNamespace("MAPI") Set myFolders = myNS.GetDefaultFolder(olFolderDeletedItems).Folders End Sub
Then click the Theoutlooksession file
again a window will appear
paste the second code there
Private Sub myFolders_FolderChange(ByVal Folder As Outlook.Folder) If Folder.Items.Count = 0 Then MyPrompt = Folder.Name & " is empty. Do you want to delete it?" If MsgBox(MyPrompt, vbYesNo + vbQuestion) = vbYes Then Folder.Delete End If End If End Sub
then close the main window of VBA.
Last edited by vlady; 11-07-2011 at 09:11 PM.
Contributors to this forum do not get paid. They give their valuable time to help you solve your problem. That's why feel free to CLICK their STARicon to say thank you -even the given idea/solution didn't really solve your queries. The time given to you deserves a small gratitude anyway.
Dare to give a pencil to a child. http://www.blackpencilproject.org/
Hi,
I did what you told me, but if I put the first part of the code on a module, the 'dim' sentence turns red so I put this code on a 'class module'. The 2nd part I put it on the 'outlooksession'.
1) How can I try this code?
2) what do they mean with "....and the Initialize_handler routine must be called before the event procedure can be called by Microsoft Outlook."?
Regards,
Elio Fernandes
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks