When reading an email, if you wish to find and print out the paragraphs containing a specific text, you can read this article. Here we’ll teach you how to get it in a jiffy.
As we all know, in an Outlook email, it is easy to find the paragraphs containing a specific text. It can be achieved simply via “Find and Replace” feature. However, if what you want is not only finding the paragraphs but also printing them out, so as to avoid manually extracting and printing, you have to use other ways, such as applying VBA code. In the followings, we will show you such a piece of code. Now read on to get it in detail.
Print All Paragraphs Containing Specific Text in Email
- For a start, in Outlook, press “Alt + F11” to access VBA editor.
- Then, enable “MS Word Object Library” as per “How to Add an Object Library Reference in VBA“.
- Next, copy the following VBA code into a module.
Sub PrintParagraphsContainingSpecificText() Dim objMail As Outlook.MailItem Dim strTempFile As String Dim objWordApp As Word.Application Dim objMailDocument As Word.Document Dim objTempDocument As Document Dim objDocRange As Range Dim strText As String Dim objSelection As Range Set objMail = Outlook.Application.ActiveExplorer.Selection(1) strTempFile = "E:\Temp" & Format(Now, "YYMMDDHHMMSS") & ".doc" objMail.SaveAs strTempFile, olDoc Set objWordApp = CreateObject("Word.Application") objWordApp.Visible = True Set objMailDocument = objWordApp.Documents.Open(strTempFile) Set objTempDocument = objWordApp.Documents.Add objMailDocument.Activate Set objDocRange = objMailDocument.Range strText = InputBox("Enter the specific text:") With objDocRange.Find .Text = strText Do While .Execute objDocRange.Paragraphs(1).Range.HighlightColorIndex = wdYellow Loop End With With objWordApp.Selection .HomeKey Unit:=wdStory With objWordApp.Selection.Find .Highlight = True Do While .Execute If objWordApp.Selection.Range.HighlightColorIndex = wdYellow Then Set objSelection = objWordApp.Selection.Range objTempDocument.Range.InsertAfter objSelection & vbCr objWordApp.Selection.Collapse wdCollapseEnd End If Loop End With End With objTempDocument.PrintOut objTempDocument.Close False objMailDocument.Close False objWordApp.Quit Kill strTempFile End Sub
- After that, exit the current window.
- Subsequently, follow the “Optional Step” in “How to Run VBA Code in Your Outlook” to add this macro to Quick Access Toolbar.
- Finally, take the steps below to have a try.
- Firstly, select an email.
- Then, click on the macro button in Quick Access Toolbar.
- Next, in the popup dialog box, enter the specific text to search.
- At once, Outlook will print out the paragraphs containing the text in the selected email, as shown in the following figure.
Evade Outlook Risks
There are multiple harmful factors surrounding your Outlook data, such as virus, malware, software failure, hardware problems and so on. Hence, it is an arduous task to protect your Outlook data. But, you still make efforts to safeguard it. For instance, you need to make regular data backups for Outlook. Moreover, you have to learn how to find and launch inbox repair tool to repair PST. Last but not least, in case of inbuilt tool failure, you had better get hold of a reliable and potent third party tool, like DataNumen Outlook Repair.
Shirley Zhang is a data recovery expert in DataNumen, Inc., which is the world leader in data recovery technologies, including repair mdf and outlook repair software products. For more information visit www.datanumen.com