简体   繁体   English

将文本粘贴到指定的 position

[英]Paste Text in specified position

I have code from searches modified for my need.我有根据我的需要修改的搜索代码。

I need to position the paste under the "Conditions" text in the xOutMsg variable.我需要在 xOutMsg 变量的“条件”文本下粘贴 position。 It is pasting into the first line in the email.它粘贴到 email 的第一行。

How do I paste on the next line after the word "Conditions"?如何在“条件”一词之后粘贴到下一行?

Sub PrepareConditionsEmail()
Dim objDoc As Word.Document
Dim objSel As Word.Selection
Dim xOutApp As Object
Dim xOutMail As Object
Dim xOutMsg As String
On Error Resume Next
Set xOutApp = CreateObject("Outlook.Application")
Set xOutMail = xOutApp.CreateItem(0)
xOutMsg = "<br /><br /><b><u>Conditions:</b></u><br /><br />" & "<b><u> </b></u><br />"
With xOutMail
    '.To = "Email Address"
    .CC = ""
    .BCC = ""
    .Subject = "Conditions"
    .HTMLBody = xOutMsg
    .Display
End With
Set xOutMail = Nothing
Set xOutApp = Nothing
On Error Resume Next
Set objDoc = Application.ActiveInspector.WordEditor
Set objSel = objDoc.Windows(1).Selection
objSel.PasteSpecial Link:=False, _
DataType:=wdPasteText, _
Placement:=wdInLine, _
DisplayAsIcon:=False
End Sub

It seems you need to parse the message and insert your own text or markup there.您似乎需要解析消息并在其中插入您自己的文本或标记。 The MailItem.HTMLBody property sets a string representing the HTML body of the specified item. MailItem.HTMLBody属性设置表示指定项目的 HTML 正文的字符串。 Use the InStr function which returns a long specifying the position of the first occurrence of one string within another.使用InStr function 返回一个 long 指定一个字符串中第一次出现的 position。 After you get the keyword position you may insert your substring right after the keyword.获得关键字 position 后,您可以在关键字后面插入 substring。

 InStr(mail.HTMLBody, "keyword", 1)

Read more about the InStr function in MSDN.在 MSDN 中阅读有关InStr function的更多信息。

The Outlook object model supports three main ways of customizing the message body: Outlook object model 支持三种主要的消息体自定义方式:

  1. The Body property returns or sets a string representing the clear-text body of the Outlook item. Body属性返回或设置一个字符串,该字符串表示 Outlook 项目的明文正文。
  2. The HTMLBody property of the MailItem class returns or sets a string representing the HTML body of the specified item. MailItem class 的HTMLBody属性返回或设置表示指定项目的 HTML 正文的字符串。 Setting the HTMLBody property will always update the Body property immediately.设置 HTMLBody 属性将始终立即更新 Body 属性。 For example:例如:
     Sub CreateHTMLMail() 
       'Creates a new e-mail item and modifies its properties. 
       Dim objMail As Outlook.MailItem 
       'Create e-mail item 
       Set objMail = Application.CreateItem(olMailItem) 
       With objMail 
        'Set body format to HTML 
        .BodyFormat = olFormatHTML 
        .HTMLBody = "<HTML><BODY>Enter the message <a href="http://google.com">text</a> here. </BODY></HTML>" 
        .Display 
       End With 
     End Sub
  1. The Word object model can be used for dealing with message bodies.字 object model 可用于处理消息体。 See Chapter 17: Working with Item Bodies for more information.有关详细信息,请参阅第 17 章:使用项目实体

There is no need to mix HTMLBody and WordEditor approaches together.无需将HTMLBodyWordEditor方法混合在一起。 You can choose a single way and use it.您可以选择一种方式并使用它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM