首页 文章

打开邮件并选择文本

提问于
浏览
1

我已使用此代码在新窗口中打开所选消息:

Dim olApp As Outlook.Application Dim Msg As Object Set olApp = Outlook.Application Set Msg = olApp.ActiveExplorer.Selection.Item(1)Msg.Display

我现在想去身体并在体内选择文本“ERROR”,然后留下进行手动治疗 .

我实际上知道这个文本出现的行号(有更多的代码) . 但我的问题是如何到达消息正文,转到行,选择文本 - 然后离开例程 .

1 回答

  • 0

    尝试使用Word . 未经测试的代码

    Sub SearchString()
    Dim myInspector As Outlook.Inspector
    Dim myObject As Object
    Dim myItem As Outlook.MailItem
    Dim myDoc As Word.Document
    
    Dim strItem 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 = "ERROR"
        End With
        If mySelection.Find.Execute = False Then
           MsgBox "There is no ERROR in this message."
        End If
    End If
    End Sub
    

    改编自http://blogs.msdn.com/b/officedevdocs/archive/2011/03/15/how-to-search-for-a-string-in-an-email-message-and-automate-a-reply-that-contains-the-string.aspx

相关问题