VBOffice

Print First Page of an Email

This example demonstrates how to print just certain pages instead of the entire e-mail.

Last modified: 2015/10/12 | Accessed: 35.928  | #156
◀ Previous sample Next sample ▶

Content

OLKeeper OLKeeper
OLKeeper reliably prevents users from closing their Outlook window and thus possibly missing reminders or e-mails.

Print First Page

The PrintOut method of Outlook's MailItem object always prints the entire email, there's no way to specifiy to print just a part of it. However, since Outlook 2007 you can access the very powerful object library of Word, which allows to do what you want. Although it's not possible to directly print an email via Word you can copy the content of the email to a Word document, and then print that one.

This sample copies the entire content of an email to a new Word document, and then prints only page #1 of that document. The sample prints the first selected email of the active folder. You could also run the 'PrintFirstPage' script by a rule to print certain new emails automatically.

(Add a reference to the 'Microsoft Word x.0 Object Library' via Tools/References.)


tip  How to add macros to Outlook
Public Sub TestPrintFirstPage()
  Dim Mail As Outlook.MailItem
  Set Mail = Application.ActiveExplorer.Selection(1)
  PrintFirstPage Mail
End Sub

Public Sub PrintFirstPage(Mail As Outlook.MailItem)
  Dim wdApp As Word.Application
  Dim wdDoc As Word.Document
  Dim olDoc As Word.Document
  
  Set wdApp = CreateObject("Word.Application")
  Set wdDoc = wdApp.Documents.Add(Visible:=True)
  
  Set olDoc = Mail.GetInspector.WordEditor
  olDoc.Range.copy
  wdDoc.Range.Paste
  
  wdDoc.PrintOut Range:=wdPrintFromTo, From:="1", To:="1"
  
  DoEvents
  wdDoc.Close False
  wdApp.Quit
End Sub
Reporter Reporter
VBOffice Reporter is an easy to use tool for data analysis and reporting in Outlook. A single click, for instance, allows you to see the number of hours planned for meetings the next month.

Print Selected Text

This example prints the selected text of an open email.

Public Sub PrintSelection()
  Dim wdApp As Word.Application
  Dim wdDoc As Word.Document
  Dim wdSelection As Word.Selection
  Dim wdWin As Word.Window
  Dim olDoc As Word.Document
  
  Set wdApp = CreateObject("Word.Application")
  Set wdDoc = wdApp.Documents.Add(Visible:=True)
  
  Set olDoc = Application.ActiveInspector.WordEditor
  Set wdWin = olDoc.Windows(1)
  Set wdSelection = wdWin.Selection
  wdSelection.Range.copy
  wdDoc.Range.Paste
  
  wdDoc.PrintOut
  
  DoEvents
  wdDoc.Close False
  wdApp.Quit
End Sub
Category-Manager Category-Manager
With Category-Manager you can group your Outlook categories, share them with other users, filter a folder by category, automatically categorize new emails, and more. You can use the Addin even for IMAP.
email  Send a message