我有VBA代码,可以发送带有Excel附件的pdf的Outlook电子邮件。
我正在尝试禁用Outlook附件上下文菜单,该菜单允许保存,打印等附件。
在Excel VBA中可能吗?
我希望附件以读取模式打开,并且用户无法保存它。
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 = "GasStorage@sse.com"
.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: gasstorage@sse.com"
.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
答案 0 :(得分:1)
我的意思是,从技术上来说是可能的:一切都是弹出和处理消息的窗口,而所要做的只是劫持该消息泵的一些代码,拦截显示“调出上下文的消息”菜单”,然后吃掉它。
如果您真的想要这样做,可以。阅读有关子类的知识,启动Spy ++并开始嗅探窗口消息,然后一切皆有可能。
但这比VBA代码通常处理的API级别低得多:Outlook对象模型(AFAIK)中的任何内容都无法使您轻松/简单地通过编程方式访问该上下文菜单。