Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I got the following from How to add default signature in Outlook. However, I keep getting an error "Application-defined or object-defined error" where the signature variable is set. How can I fix this error?

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

I know I could get the signature from the C:Users...Signatures folder. However at work, we all use virtual desktops and the permissions there are a tad janky.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
319 views
Welcome To Ask or Share your Answers For Others

1 Answer

Your signature has to be declared as a variant.

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...