excel 如何避免用粘贴的图像覆盖默认签名?

92vpleto  于 2023-04-22  发布在  其他
关注(0)|答案(2)|浏览(139)

我的默认电子邮件签名被嵌入的图像覆盖。签名一开始显示,然后图片取代了它的位置。
我想让这段代码对其他人有效。我如何添加默认的电子邮件签名?

Sub Send_Email()

    Dim pdfPath As String, pdfName As String

    ' PDF name same as the workbook.name
    pdfName = "VW Fuel Marks_" & Format(Date, "m.d.yyyy")

    ' PDF save path same as workbook path, where the workbook is saved
    pdfPath = ThisWorkbook.Path & "\" & pdfName & ".pdf"

    ' Selecting sheets (if any of the sheets hidden it will run to an error)
    ThisWorkbook.Sheets(Array("Daily Dashboard-Page1", "Daily Dashboard-Page2", "Daily Dashboard-Page3", "Daily Dashboard-Page4")).Select

    ' Create PDF document and open it (if a pdf with a same
    ' name is already opened it will run to an error)
    ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, Filename:=pdfPath, Quality:=xlQualityStandard, IncludeDocProperties:=True, _
      IgnorePrintAreas:=False, OpenAfterPublish:=True

    Application.Worksheets(19).Range("A1:T42").CopyPicture xlScreen, xlPicture

    Dim OApp As Object, OMail As Object, Signature As String
    Dim cell As Range, S As String, WMBody As String, lFile As Long

    Set OApp = CreateObject("Outlook.Application")
    Set OMail = OApp.CreateItem(0)

    With OMail
        .Display
    End With

    Signature = OMail.HTMLBody

    With OMail
        .To = Range("AG3").Value
        .CC = Range("AG4").Value
        .Subject = Range("A1").Value
        .HTMLBody = Replace(Signature, "<div class=WordSection1><p class=MsoNormal><o:p>", "<div class=WordSection1><p class=MsoNormal><o:p>" & sBody)
        .Attachments.Add pdfPath
        OMail.Display
    End With

    '.Attachments.Add
    Set ins = OMail.GetInspector

    ' We need to add a reference to the Microsoft Word Object Library
    Dim doc As Word.Document
    Set doc = ins.WordEditor
    doc.Select
    doc.Application.Selection.Paste
    OMail.Display

    Set OMail = Nothing
    Set OApp = Nothing

End Sub
p8ekf7hl

p8ekf7hl1#

您需要在开始的<body>标签后面插入内容。在这种情况下,其余内容将按原样保留。

With OMail
    .Display
End With

Signature = OMail.HTMLBody

With OMail
    .To = Range("AG3").Value
    .CC = Range("AG4").Value
    .Subject = Range("A1").Value

     ' here you need to find the <body> tag and insert the new content right after it
    .HTMLBody = ...

    .Attachments.Add pdfPath
    OMail.Display
End With

您可以使用VBA string functions查找<body>标记并将内容粘贴到它后面。

ycggw6v2

ycggw6v22#

选择主体,然后粘贴到其上。

Set doc = ins.WordEditor
doc.Select
doc.Application.Selection.Paste

相反,粘贴在顶部,在一个较小的尺寸。

Set doc = ins.WordEditor
doc.Range(0, 0).Paste

这将粘贴在顶部,大小与您的代码相匹配。

Set doc = ins.WordEditor
Dim wdRange As Word.Range
Set wdRange = doc.Range(0, 0)
wdRange.Select
doc.Application.Selection.Paste

相关问题