Outlook VBA 开发第二讲-保存选中邮件的所有附件到一个目录中
(如有问题,请联系 dsd999@sohu.com)
需求:添加按钮,保存选中邮件的所有附件到一个目录中。
代码:
Private WithEvents vsoCommbandButton As CommandBarButton
Private WithEvents vsoCommbandSaveAttach As CommandBarButton
Private Sub Application_Startup()
Call addTotalButton
End Sub
增加工具栏
Sub addTotalButton()
On Error Resume Next
Dim vsoCommandBar As CommandBar
‘得到要添加的工具栏
Set vsoCommandBar = Outlook.ActiveExplorer.CommandBars("ExcelClub")
‘如果工具栏为空,则增加
If (vsoCommandBar Is Nothing) Then
Set vsoCommandBar = Outlook.ActiveExplorer.CommandBars.add("ExcelClub",
msoBarTop)
‘在工具栏上增加一个按钮
Set vsoCommbandButton = vsoCommandBar.Controls.add(1)
‘按钮的名字
vsoCommbandButton.Caption = "Mail Count"
‘按钮显示的图标
vsoCommbandButton.FaceId = 65
‘按钮显示的类型是图标和文本都显示
vsoCommbandButton.Style = msoButtonIconAndCaption
‘在工具栏上增加第二个按钮
Set vsoCommbandSaveAttach = vsoCommandBar.Controls.add(1)
vsoCommbandSaveAttach.Caption = "Save Attachment"
vsoCommbandSaveAttach.FaceId = 66