通常我的谷歌技能并不是那么糟糕。我正在寻找一种方法来发送电子邮件与VBA并选择功能区按钮。基本上我有一个自定义功能区按钮来加密电子邮件,我希望它在从VBA创建新电子邮件时切换。我一直找不到任何样品。任何帮助将不胜感激
Sub SendMail()
Dim OutMail As Outlook.MailItem
Dim outapp As Outlook.Application
With Application
.EnableEvents = False
.ScreenUpdating = False
End With
Set outapp = CreateObject("Outlook.Application")
Set OutMail = outapp.CreateItem(0)
With OutMail
.To = "Email@place.thing"
.CC = ""
.BCC = ""
.Subject = "BACON"
.HTMLBody = "TESTING"
' .Send
.Display
End With
With Application
.EnableEvents = True
.ScreenUpdating = True
End With
Set OutMail = Nothing
Set outapp = Nothing
End Sub
因此,当创建新电子邮件时,我希望按下“加密”按钮(参见下图)。这是一个切换按钮。
答案 0 :(得分:0)
这样的事情应该可以解决问题。我能够在外部应用程序中成功调用功能区按钮的过程(在PPT中测试,因为我没有随时可用的带有customUI的Outlook加载项,但是同样的方法应该适用于Outlook,Word,等)
Option Explicit
Sub CallExternalRibbon(app As Object, _
AddInName as String, _
ModuleName As String, _
ProcedureName As String)
'###
' runs a specific procedure from another application/Add-in
' AddInName is the name of the Add-in's VBAProject
' ModuleName should NOT use Option Private Module
' ProcedureName should be declared Public
'
' May also require change to application's Trust Center settings
' (specifically: allow access to VBAProject Object Model)
'###
Dim externalProcedure As String
'## concatenate the procedure string
externalProcedure = AddInName & "!" & ModuleName & "." & ProcedureName
'## run the external procedure from that application
app.Run externalProcedure
End Sub
在.Send
之前调用它。修改字符串参数以满足您的特定需求:
Call CallExternalRibbon(outApp, _
"AddIn_VBAProject_Name", _
"Module_Name", _
"Callback_Procedure_Name")
备注:强>
未经过彻底测试,但在简单的情况下工作。您可以通过在另一个应用程序中启动进程线程来解决某些问题。
这适用于使用CustomUI和XML / VBA回调创建的加载项。它可能无法运行,并且尚未在您可能已从第三方安装的任何专有加载项或其他COM加载项上进行测试。