Vba 更改电子邮件中的剪贴板样式

Vba 更改电子邮件中的剪贴板样式,vba,outlook,ms-word,clipboard,Vba,Outlook,Ms Word,Clipboard,我有一个宏,可以将剪贴板粘贴到电子邮件中,但它保留了文本的原始格式 我无法将粘贴的文本设置为正常格式或快速样式。首先我放入一个文本,然后粘贴剪贴板,然后再粘贴另一个文本 我希望剪贴板内容与其他文本具有相同的样式,或者只是正常的样式 Set OutMail = OutApp.CreateItem(0) With OutMail .To = "" .CC = "" .BCC = "" .Subject = "" Set olInsp = .Get

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

我无法将粘贴的文本设置为正常格式或快速样式。首先我放入一个文本,然后粘贴剪贴板,然后再粘贴另一个文本

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

 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

这是代码:

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
Sub-aaaaa()
Dim OutApp作为对象
将邮件变暗为对象
作为对象的对象
作为物体的暗角
将StrBdA设置为字符串
将StrBdB设置为字符串
作为字符串的Dim lll
将我的字符串变暗为字符串
将xlApp作为对象
Dim sourceWB作为对象
Dim sourceWS作为对象
StrBdA=“

”和“文本”_ &“

”和“文本”_ &“

”和“文本”_ &“
”和“1.”和“文本”_ &“
”和“2.”和“文本”_ &“
”和“3.”和“文本”和“

” StrBdB=“

”和“文本”_ &“
”和“文本”_ &“
”和“文本:”_ &“
”和“link1”_ &“
”和“链接2”_ &“

”和“文本”和“

” 出错时继续下一步 Set-OutApp=GetObject(,“Outlook.Application”) 如果错误为0,则设置OutApp=CreateObject(“Outlook.Application”) 错误转到0 Set-OutMail=OutApp.CreateItem(0) 发邮件 OutMail.SentonBehalfName=“” .重要性=低重要性高 .To=“” '.CC=“” .BCC=“” .Subject=“” 设置olInsp=.GetInspector 设置wdDoc=olInsp.WordEditor 设置oRng=wdDoc.范围 突然崩溃1 .展示 OutMail.HTMLBody=StrBdB&OutMail.HTMLBody 装饰膏 oRng.Font.Bold=True OutMail.HTMLBody=StrBdA&OutMail.HTMLBody 以 发送邮件=无 设置应用程序=无 设置olInsp=Nothing 设置wdDoc=Nothing 设为零 端接头
您是否尝试了基于此的内容。我最初是为Word制作的,但在我的Outlook 2010中做了一些修改后,效果很好

Option Explicit

Sub SendMailBodyNormal()

Dim olApp As Object
Dim olEmail As Object
Dim olInsp As Object
Dim wdDoc As Object
Dim oRng As Object

    On Error Resume Next
    Set olApp = GetObject(, "Outlook.Application")
    If Err <> 0 Then Set olApp = CreateObject("Outlook.Application")
    On Error GoTo 0
    Set olEmail = olApp.CreateItem(0)
    With olEmail
        .BodyFormat = 2
        .To = ""
        .Subject = "Movies Report"
        Set olInsp = .GetInspector
        Set wdDoc = olInsp.WordEditor
        Set oRng = wdDoc.Range(0, 0)
        oRng.Paste
        oRng.Style = "Normal"
        .Display
    End With
lbl_Exit:
    Set olApp = Nothing
    Set olEmail = Nothing
    Set olInsp = Nothing
    Set wdDoc = Nothing
    Set oRng = Nothing
    Exit Sub
End Sub
选项显式
子SendMailBodyNormal()
作为对象的Dim-olApp
将邮件作为对象
作为对象的对象
Dim wdDoc作为对象
作为物体的暗角
出错时继续下一步
设置olApp=GetObject(,“Outlook.Application”)
如果错误为0,则设置olApp=CreateObject(“Outlook.Application”)
错误转到0
Set olEmail=olApp.CreateItem(0)
用电子邮件
.BodyFormat=2
.To=“”
.Subject=“电影报道”
设置olInsp=.GetInspector
设置wdDoc=olInsp.WordEditor
设置oRng=wdDoc.Range(0,0)
装饰膏
oRng.Style=“正常”
.展示
以
lbl_出口:
设置olApp=Nothing
设置olEmail=Nothing
设置olInsp=Nothing
设置wdDoc=Nothing
设为零
出口接头
端接头

在Excel中,有一个专门的
.paste
。虽然我只能找到与Excel相关的代码,但您可以尝试:
oRng.PasteAndFormat(wdFormatSurroundingFormattingWithEmphasis)
谢谢您的回答,但它不会改变任何东西。我尝试过SendKeys“{^}{A}”,True SendKeys“{+}{N}”,是的,但它不起作用,要么你自己搞糊涂了,要么你把程序搞糊涂了。您的剪贴板内容来自何处?手工复制?因为您的代码不会显示剪贴板内容的来源如果您想格式化唯一的剪贴板内容,它不是直接的。我通常更喜欢打开一个新的隐藏单词实例,并相应地格式化和关闭它。这是可行的。多谢各位。