Search For Text String Within Microsoft Word Docs On Mac



I’d like to demonstrate a technique that helps automating email replies – when creating a reply to a message, search for a specific string, such as a reference number or item number, from the original message; dynamically create a greeting using the search result, and then automatically insert the greeting in the reply. This technique uses the object models of both Microsoft Outlook and Microsoft Word. The Scenario The example scenario assumes Microsoft Office 2010 (Microsoft Outlook 2010 and Microsoft Word 2010), or Microsoft Office 2007 (Outlook 2007 and Word 2007), and that you include the original email message when replying to it in an Outlook inspector. I also assume the following flow of actions: 1. Click Reply on an email message that may or may not contain an item number that matches the format “Item number: “ followed by 10 characters. See Figure 1.

  1. Hyperlink Within Microsoft Word

Type your search in the search bar on the top right of the folder. There is a line above the results that says: Search: This Mac 'Your Folder Name' Click on the name of your folder to restrict the search to the folder instead of the whole computer, which is what the default selection 'This Mac' does.

Create a reply email message in an inspector in compose mode. Run the macro.

The macro behaves in the following manner: 1. The macro looks for a string that follows this format: “item number: xxxxxxxxxx”, where “xxxxxxxxxx” matches any 10 characters following “item number: “. If the original email message contains a string that follows the format: “item number: xxxxxxxxxx”, then the macro does the following: a. Forms a default greeting phrase, “With reference to item number: xxxxxxxxxx”.

Keyboard shortcuts in Word for Mac. Decrease the font size + Shift + font size by 1 point + ]. Collapse text under a heading. This keyboard shortcut conflicts with a default Mac OS X key assignment. To use this Office keyboard shortcut, you must first turn off the Mac OS X keyboard shortcut for this key. Keyboard shortcuts for text size and bold mac.

Inserts the greeting phrase as the first sentence in the reply. See figure 2. Outlook inserts in the reply a greeting phrase that contains a search result 3. If the original email message does not contain a string that follows the assumed format, then the macro displays a message “There is no item number in this message”. The Macro The following is the macro. I also attached a copy to this blog, so that you can conveniently copy and paste it in the Visual Basic Editor to try it out.

Search For Text String Within Microsoft Word Docs On Mac

Sub AutomateReplyWithSearchString() Dim myInspector As Outlook.Inspector Dim myObject As Object Dim myItem As Outlook.MailItem Dim myDoc As Word.Document Dim mySelection As Word.Selection Dim strItem As String Dim strGreeting As String Set myInspector = Application.ActiveInspector Set myObject = myInspector.CurrentItem 'The active inspector is displaying a mail item. If myObject.MessageClass = 'IPM.Note' And _ myInspector.IsWordMail = True Then Set myItem = myInspector.CurrentItem 'Grab the body of the message using a Word Document object. Set myDoc = myInspector.WordEditor myDoc.Range.Find.ClearFormatting Set mySelection = myDoc.Application.Selection With mySelection.Find.Text = 'item number:??????????' .Replacement.Text = '.Forward = True.Wrap = wdFindContinue.Format = False.MatchCase = False.MatchWholeWord = False.MatchAllWordForms = False.MatchSoundsLike = False.MatchWildcards = True End With If mySelection.Find.Execute = True Then strItem = mySelection.Text 'Mail item is in compose mode in the inspector If myItem.Sent = False Then strGreeting = 'With reference to ' + strItem myDoc.Range.InsertBefore (strGreeting) End If Else MsgBox 'There is no item number in this message.'

End If End If End Sub Follow the steps below to use the macro that looks for a string that follows this format: “item number: xxxxxxxxxx”. In Outlook, make sure the Developer tab is displayed in the ribbon. The Developer tab is hidden by default. To display the Developer tab: a.

Click File, then Options. Click Customize Ribbon. Click the check box adjacent to Developer. Click Developer in the ribbon. Click Visual Basic to start the Visual Basic Editor. On the left, expand Project1 and then Microsoft Outlook Objects.

Search

Double-click ThisOutlookSession. Copy and paste the macro in the Project1 – ThisOutlookSession (Code) window. See figure 3. Paste macro into the Visual Basic Editor. Click Tools and then References. Scroll down the list of Available References and click the type library for Word 2010, Microsoft Word 14.0 Object Library, to add it as a reference. (If you are using Microsoft Office 2007, you would be adding a reference to Microsoft Office Word 12.0 Object Library.) 8.

Return to the Outlook explorer, and open an email message that you’d like to run the macro on. Click Reply in the inspector ribbon, to create your reply email message in an inspector in compose mode. This is shown in figure 1. Note: make sure you do not select any text at this point.

Go back to the Visual Basic Editor. Run the macro by clicking F5.

Return to the inspector in compose mode. If the original email message contains a string with the assumed format, you will see a greeting phrase “With reference to the item number: xxxxxxxxxx” inserted at the beginning of the reply. (“xxxxxxxxxx” is the first 10 characters following the string “item number: “ in the original email message.) See Figure 2. You can proceed to further modify the reply message before sending it. If the original email message does not contain a string of the assumed format, then you will see a message “There is no item number in this message.” The Solution The solution proposed in the last section assumes you are running Outlook 2007 or a later version, and that you have a reply window for an email message open as the current Outlook window.