brillox
brillox

Reputation: 373

Send an Outlook email with pdf attachment from Excel and disable Outlook attachment context menu

I have VBA code to send an Outlook email with a pdf attached from Excel.

I am trying to disable the Outlook attachment context menu that allows saving, printing, etc. the attachment.

Context Menu

Is this possible within Excel VBA?

I want for the attachment to open in read mode and for the user not be able to save it.

Sub SendDMR()

'some code not added for simplicity

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

    On Error Resume Next
    With OutMail
        .To = ""
        .SentOnBehalfOfName = "[email protected]"
        .CC = ""
        .BCC = ""
        .Subject = "Daily Management Report " & Format(Date - 1, "dd/mm/yyyy")
        .Body = "Good morning," & vbCr & vbCr & "Please find the Daily Management Report attached for " & Format(Date - 1, "dd/mm/yyyy") & "." & vbCr & vbCr & "Kind regards," & vbCr & vbCr & "Shift Trading Team" & vbCr & "SSE Gas Storage" & vbCr & "Inveralmond House, Perth" & vbCr & "T: +44 (0)1738 453960" & vbCr & "E: [email protected]"
        .Attachments.Add strPath & strFName
        .Permission = olDoNotForward
        .PermissionService = olWindows
        .Sensitivity = olConfidential
        .Display
    End With
    On Error GoTo 0

    Set OutMail = Nothing
    Set OutApp = Nothing

End If

Exit Sub

MsgEnd:
MsgBox "Please set the print area before continuing", vbExclamation

End Sub

Upvotes: 0

Views: 225

Answers (1)

Mathieu Guindon
Mathieu Guindon

Reputation: 71247

Yes No.

I mean yes, technically it's possible: everything is a window spewing and handling messages, and all it takes is some code to hijack that message pump, intercept the message that says "bring up that context menu", ...and eat it.

If you really want to do this, you can. Read up on subclassing, fire up Spy++ and start sniffing window messages, and then everything is possible.

But that's MUCH lower-level than the APIs VBA code typically deals with: nothing in Outlook's object model (AFAIK) is giving you easy/simple programmatic access to that context menu.

Upvotes: 1

Related Questions