0

我希望当您点击“发送”时,您会看到一个表格。这是我在 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 个按钮。

4

2 回答 2

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

将 Statement`中的上述注释替换为Select您希望根据用户选择执行的宏名称。

快照在行动

在此处输入图像描述

这就是您选择Option D (ListIndex 3)

在此处输入图像描述

跟进

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
于 2012-07-15T14:30:18.240 回答
0

Is there a way to populate a combo-box with a list of Macros?

Not in Outlook, I'm afraid. Programmatic access to the VBA IDE isn't supported in Outlook due to the possibility of spreading viruses or conducting malicious activity via email.

See VBA Extensibility in Outlook for reference.

The closest you can come is by programmatically displaying the "Run Macro" dialog, like this:

ActiveExplorer.CommandBars.FindControl(,186).Execute

However I'm not sure if this is available in Outlook 2010.

But showing a dialog box can't possibly be your goal. Maybe if you explain what your goal is, someone can suggest a better way of reaching it that doesn't require populating a combo box with a list of macro names.

于 2012-07-15T13:03:53.760 回答