Consulting

Results 1 to 3 of 3

Thread: Print email when moved to a subfolder

  1. #1
    VBAX Newbie
    Joined
    Jun 2017
    Posts
    3
    Location

    Print email when moved to a subfolder

    Hi

    I have Outlook 2010. I'm trying to write code that will print an email when it is moved into a folder. That bit I have managed, and it works fine. However that is when moving an email into the folder "Worldox" which sits at the same level as Inbox. I can't seem to work out how to code it so that it works when moving mail into a subfolder of "Worldox", eg into "Joey"

    The other issue is that the subfolders may be added/deleted/renamed so to future proof the code it would be helpful if it could print when mail is moved into any subfolder of "Worldox" Is that possible?


    The code that I have so far is

    Private WithEvents Items As Outlook.Items
    Private Sub Application_Startup()
    Dim Ns As Outlook.NameSpace
    Set Ns = Application.GetNamespace("MAPI")
    Set Items = Ns.GetDefaultFolder(olFolderInbox).Parent.Folders("Worldox").Items
    End Sub
    Private Sub Items_ItemAdd(ByVal Item As Object)
    If TypeOf Item Is Outlook.MailItem Then
    PrintNewItem Item
    End If
    End Sub
    Private Sub PrintNewItem(Mail As Outlook.MailItem)
    On Error Resume Next
    Mail.PrintOut
    End Sub

    I'm not very good with VB so any help would be very much appreciated!

  2. #2
    VBAX Mentor skatonni's Avatar
    Joined
    Jun 2006
    Posts
    347
    Location

    Walk the chain to reference a subfolder

    You walked from the default inbox to the mailbox to Worldox so keep on walking to Joey.

    Set Items = Ns.GetDefaultFolder(olFolderInbox).Parent.Folders("Worldox").Folders("Joey" ).Items

    I believe if you want to listen to new or renamed subfolders of Worldox you will need code for each folder.
    To debug, mouse-click anywhere in the code. Press F8 repeatedly to step through the code. http://www.cpearson.com/excel/DebuggingVBA.aspx

    If your problem has been solved in your thread, mark the thread "Solved" by going to the "Thread Tools" dropdown at the top of the thread. You might also consider rating the thread by going to the "Rate Thread" dropdown.

  3. #3
    VBAX Newbie
    Joined
    Jun 2017
    Posts
    3
    Location

    Saving the Macro in another file

    That worked, thank you.

    Unfortunately we use Citrix and every time I log off I loose the macro. I know how to change where the macro is saved in Word, can't I can't seem to find how to change it in Outlook. Any ideas?

Posting Permissions

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