0
votes

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
1
I wouldn't say it's impossible, but you most likely don't want to do this.Mathieu Guindon
@BigBen I don't think you can do this manually. I'd guess disabling that specific menu requires some serious Win32 & COM fiddling & subclassing, message pump hijacking and WM injection. As I said, not impossible, just... wow the massive pain.Mathieu Guindon
@MathieuGuindon that was my guess - which is why I deleted my comment. In any case, I'm sure there'd be a workaround for the end user to access the PDF.BigBen
Life finds a way, yes =)Mathieu Guindon
Ok thanks guys this is also what i thought (impossible or a massive pain... ) But I wanted to ask you all before giving upbrillox

1 Answers

1
votes

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.