|
老师好,请教一下,我找到以下这段程序,想在OUTLOOK中新建一个按钮,然后点击按钮获得发件人的邮件地址。但按钮所对应的程序不被执行。请老师帮我看看。多谢!
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)
'在工具栏上增加一个按钮
Dim vsoCommbandButton As CommandBarButton
Set vsoCommbandButton = vsoCommandBar.Controls.Add(1)
'按钮的名字
vsoCommbandButton.Caption = "GetMail&Address"
'按钮显示的图标
vsoCommbandButton.FaceId = 65
'按钮显示的类型是图标和文本都显示
vsoCommbandButton.Style = msoButtonIconAndCaption
'显示增加的工具栏
vsoCommandBar.Visible = True
End If
End Sub
Private Sub vsoCommbandButton_Click(ByVal Ctrl As Office.CommandBarButton, CancelDefault As Boolean)
Dim myOlExp As Outlook.Explorer
Dim myOlSel As Outlook.Selection
Dim MsgTxt As String
Dim x As Integer
Set myOlExp = Application.ActiveExplorer
Set myOlSel = myOlExp.Selection
For x = 1 To myOlSel.Count
Dim s As String
s = myOlSel.Item(x).SenderEmailAddress
Dim MyDataObj As New DataObject
MyDataObj.SetText s
MyDataObj.PutInClipboard
Next x
End Sub
|
|