簡體   English   中英

如何使用 HTMLBody 在電子郵件上添加 VBA 簽名?

[英]How to add VBA Signature on Email with HTMLBody?

我從How to add default signature in Outlook 中得到以下信息。 但是,我不斷收到錯誤“應用程序定義或對象定義的錯誤”,其中設置了簽名變量。 我該如何解決這個錯誤?

Dim OApp As Object, OMail As Object, signature As String
Set OApp = CreateObject("Outlook.Application")
Set OMail = OApp.CreateItem(0)
With OMail
    .Display
End With
signature = OMail.body
With OMail
    '.To = "someone@somedomain.com"
    '.Subject = "Type your email subject here"
    '.Attachments.Add
    .body = "Add body text here" & vbNewLine & signature
    '.Send
End With
Set OMail = Nothing
Set OApp = Nothing

我知道我可以從 C:\\Users...\\Signatures\\ 文件夾中獲取簽名。 但是在工作中,我們都使用虛擬桌面,並且那里的權限有點不穩定。

您的簽名必須聲明為變體。

Dim OApp As Object
Dim OMail As Object
Dim Signature As Variant

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

On Error Resume Next
With OMail
    'Capture signature block.
    .Display
    Signature = .HTMLBody
    '.To = Recipients
    '.CC = CarbonCopy
    .Subject = "Subject"
    .HTMLBody = "<p>Add Body Here.</p>" & Signature
    .Display
End With
On Error GoTo 0

Set OutMail = Nothing
Set OutApp = Nothing

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM