Consulting

Results 1 to 2 of 2

Thread: Combining two working print macros

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

    Combining two working print macros

    I have two macros in Outlook 2010 that work

    The first prints an email when it is dropped into a folder. The second one prints the first page of an email. Ideally I want to combine them both but after some experimenting I can't seem to insert the second set of code into the first in the correct place for it to work.

    Any help much appreciated

    Code one

    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").Folders(“Joey” ).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

    Code two

    Sub PrintPageOne()
    SendKeys "%FPR"
    SendKeys "%S"
    SendKeys "1"
    SendKeys "{ENTER}"
    End Sub

  2. #2
    VBAX Mentor skatonni's Avatar
    Joined
    Jun 2006
    Posts
    347
    Location
    You did not indicate what you tried so I would guess you are running PrintPageOne on the folder not the item.

    Private Sub Items_ItemAdd(ByVal Item As Object)
        If TypeOf Item Is Outlook.mailitem Then
            'PrintNewItem Item
            Item.Display
            PrintPageOne
        End If
    End Sub
    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.

Posting Permissions

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