更改电子邮件

时间:2016-03-18 10:29:14

标签: vba ms-word outlook word-vba clipboard

我有一个将剪贴板粘贴到电子邮件中的宏,但它保留了文本的原始格式。

我无法使粘贴的文本处于正常格式或快速样式正常。首先我放一个文本,然后粘贴剪贴板,然后粘贴另一个文本。

我希望剪贴板内容与其他文本具有相同的样式,或者只是正常。

 Set OutMail = OutApp.CreateItem(0)
 With OutMail
     .To = ""
     .CC = ""
     .BCC = ""
     .Subject = ""
     Set olInsp = .GetInspector
     Set wdDoc = olInsp.WordEditor
     Set oRng = wdDoc.Range
     oRng.collapse 1
     .Display
     OutMail.HTMLBody = textB & OutMail.HTMLBody
     oRng.Paste
     OutMail.HTMLBody = textA & OutMail.HTMLBody

 End With

我尝试过:

     'oRng.Font.Bold = True ' changes the font but not the style
     'oRng.Font.Name = "Calibri (Body)" ' changes the font but not the style
     'oRng.Font.Color = vbRed ' changes the font but not the style
     'oRng.Style = 1 ' not working
     'With oRng.ParagraphFormat ' changes the spacing but not the style
     '.LineSpacingRule = wdLineSpaceAtLeast 
     '.LineSpacing = 10
     'End With
     '.BodyFormat = 1 ' not working

enter image description here

这是代码:

Sub aaaaa()
Dim OutApp As Object
Dim OutMail As Object
Dim olInsp As Object
Dim oRng As Object
Dim StrBdA As String
Dim StrBdB As String
Dim lll As String
Dim myString As String
Dim xlApp As Object
Dim sourceWB As Object
Dim sourceWS As Object

StrBdA = "<br> <br>" & "text" _
                 & "<br> <br>" & "text" _
                 & "<br> <br>" & "text" _
                 & "<br>" & "1." & "text</b>" _
                 & "<br>" & "2." & "text" _
                 & "<br>" & "3." & "text" & "<br> <br>"  


StrBdB = "<br> <br>" & "text." _
                 & "<br>" & "text" _
                 & "<br>" & "text:" _
                 & "<br>" & "<a link1>link1</a>" _
                 & "<br>" & "<a link2>link2</a>" _
                 & "<br> <br>" & "text" & "<br> <br>"

     On Error Resume Next
     Set OutApp = GetObject(, "Outlook.Application")
     If Err <> 0 Then Set OutApp = CreateObject("Outlook.Application")
     On Error GoTo 0

     Set OutMail = OutApp.CreateItem(0)
     With OutMail
         OutMail.SentOnBehalfOfName = ""
         .Importance = olImportanceHigh
         .To = ""
         '.CC = ""
         .BCC = ""
         .Subject = ""

         Set olInsp = .GetInspector
         Set wdDoc = olInsp.WordEditor
         Set oRng = wdDoc.Range
         oRng.collapse 1
         .Display
         OutMail.HTMLBody = StrBdB & OutMail.HTMLBody
          oRng.Paste
          oRng.Font.Bold = True
         OutMail.HTMLBody = StrBdA & OutMail.HTMLBody
     End With
     Set OutMail = Nothing
     Set OutApp = Nothing
     Set olInsp = Nothing
     Set wdDoc = Nothing
     Set oRng = Nothing
End Sub

1 个答案:

答案 0 :(得分:1)

你有没有尝试过基于此的东西?我最初是为Word制作的,但在我的Outlook 2010中进行了一些修改后工作正常

 <div id="captioned-gallery">
            <figure class="slider">
                <figure>
                     <figcaption>Individual Learners! Courses from £18.00     </figcaption>
             </figure>
          <figure>
            
            <figcaption>Employers! Course from £14.00 to £10.00</figcaption>
         </figure>
        <figure>
           
            <figcaption>Plus unlimited redeem codes!</figcaption>
        </figure>
        <figure>
           
            <figcaption>The more you train!, The more cost effective!</figcaption>
        </figure>
        <figure>
            <figcaption>Plus personalised training academies</figcaption>
        </figure>

        <figure>
            <figcaption>Open access courses of your choice</figcaption>
        </figure>

        <figure>
            <figcaption>Courses accepted by Local Authorities</figcaption>
        </figure>
        <figure>
            <figcaption>Instant access and outstanding support! </figcaption>
        </figure>

    </figure>
</div>