用于列出宏的组合框

时间:2012-07-15 11:36:07

标签: vba outlook outlook-vba

我想当你点击'发送'时,你会看到一个表格。这是我在Outlook 2010中开发的。

有没有办法用一个宏列表填充一个组合框?

Public Sub Confidential()
    Application.ActiveInspector.CurrentItem.Sensitivity = olConfidential
    Application.ActiveInspector.CurrentItem.Save
    Set MsgSub = Outlook.Application.ActiveInspector.CurrentItem
    Set objMail = Outlook.Application.ActiveInspector.CurrentItem
    Subject = MsgSub.Subject
    MsgSub.Subject = Subject + " - [CONFIDENTIAL]"
    Email = objMail.HTMLBody
    info = " <html> <body> <FONT color=#666666> <font-size: 11px> <p></p> AUTO TEXT: This message has been marked as 'CONFIDENTIAL' please treat it as such </body> </font> </html>"
    objMail.HTMLBody = Email + info
End Sub

Private Sub Sens_DropButtonClick()
    Sens.AddItem "Confidential()"
    Sens.AddItem "Normal()"
End Sub

Public Sub Send_Click()
    Set objMail = Outlook.Application.ActiveInspector.CurrentItem
    objMail.Send
End Sub

我认为这是一个公共分支是否正确?

我的目标是当您点击“发送”按钮时,表单会显示一个下拉框,这有4个选项,这些选项可以用于电子邮件,但我已将它们创建为宏并添加了代码它们(添加到消息的主题和页脚)但我不会这样,用户被迫做出选择,因此我为什么要创建这个表单而不是4个按钮。

2 个答案:

答案 0 :(得分:2)

  

我的目标是当您点击“发送”按钮时,表单会显示一个下拉框,这有4个选项,这些选项可以用于电子邮件,但我已将它们创建为宏并添加了代码他们(添加到消息的主题和页脚),但我不会这样,用户被迫做出选择,因此我为什么要创建此表单而不是4个按钮。 - Rsmithy 36分钟前

如果我理解正确,是的,你可以做你想做的事。见这个例子

假设您有一个包含4个选项A,B,C和D的用户表单,并且用户表单代码为

Private Sub UserForm_Initialize()
    ComboBox1.AddItem "A"
    ComboBox1.AddItem "B"
    ComboBox1.AddItem "C"
    ComboBox1.AddItem "D"
End Sub

Private Sub CommandButton1_Click()
    lstNo = ComboBox1.ListIndex
    Unload Me
End Sub

下一步将其粘贴到模块中

Public lstNo As Long

并在ThisOutlookSession

Private Sub Application_ItemSend(ByVal Item As Object, Cancel As Boolean)
    UserForm1.Show

    MsgBox "user chose " & lstNo & "from combo"

    Select Case lstNo
    Case -1
        'User didn't select anything in the combo
    Case 0
        'User selected option 1 in the combo
    Case 1
        'User selected option 2 in the combo
    Case 2
        'User selected option 3 in the combo
    Case 3
        'User selected option 4 in the combo
    End Select
End Sub

Select Statement`中的上述注释替换为您要执行的宏名称,具体取决于用户的选择。

行动中的快照

enter image description here

这是您选择Option D (ListIndex 3)

时获得的结果

enter image description here

<强>后续

Dim email As String, info As String

Private Sub Application_ItemSend(ByVal Item As Object, Cancel As Boolean)
    UserForm1.Show

    Select Case lstNo
        Case -1
            'User didn't select anything, default will be used
        Case 0
            With Item
                .Sensitivity = olNormal
                .Save
            End With
        Case 1
            With Item
                .Sensitivity = olPersonal
                .Save
            End With
        Case 2
            With Item
                .Sensitivity = olPrivate
                .Save
            End With
        Case 3
            With Item
                .Sensitivity = olConfidential
                .Subject = .Subject & " - [CONFIDENTIAL]"
                Email = .HTMLBody
                info = " <html> <body> <FONT color=#666666> <font-size: 11px> <p></p> AUTO TEXT: " & _
                "This message has been marked as 'CONFIDENTIAL' please treat it as such </body> </font> </html>"
                .HTMLBody = Email & info
                .Save
            End With
    End Select
End Sub

答案 1 :(得分:0)

  

有没有办法用一个宏列表填充一个组合框?

不在Outlook中,我很害怕。由于可能通过电子邮件传播病毒或进行恶意活动,因此Outlook不支持以编程方式访问VBA IDE。

请参阅VBA Extensibility in Outlook以供参考。

最接近的是通过编程方式显示“运行宏”对话框,如下所示:

ActiveExplorer.CommandBars.FindControl(,186).Execute

但是我不确定它是否在Outlook 2010中可用。

但是显示一个对话框不可能是你的目标。也许如果你解释一下你的目标是什么,有人可以建议一种更好的方法来达到它,而不需要用一个宏名列表填充一个组合框。

相关问题