+ Reply to Thread
Results 1 to 3 of 3

Thread: FolderChange Event

  1. #1
    Valued Forum Contributor
    Join Date
    01-01-2005
    MS-Off Ver
    2007
    Posts
    257

    FolderChange Event

    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

  2. #2
    Valued Forum Contributor vlady's Avatar
    Join Date
    09-22-2011
    Location
    Philippines - Guimba-Nueva Ecija
    MS-Off Ver
    2010
    Posts
    789

    Re: FolderChange Event

    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
    Dim WithEvents myFolders As Outlook.Folders
    
    Sub Initialize_handler()
        Set myNS = Application.GetNamespace("MAPI")
        Set myFolders = myNS.GetDefaultFolder(olFolderDeletedItems).Folders
    End Sub
    Next double click the Microsoft Outlook Object( a folder - left side of screen)
    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 STAR icon 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/

  3. #3
    Valued Forum Contributor
    Join Date
    01-01-2005
    MS-Off Ver
    2007
    Posts
    257

    Re: FolderChange Event

    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

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.2.0