【发布时间】:2017-04-02 20:53:14
【问题描述】:
我使用的是 2007 Outlook。
我正在尝试获取一个代码,在创建新电子邮件时提示用户选择一个固定的单选按钮选项,如下所示 [A]: , [R]:, [F:] , [!] : , 空白(使主题行空白的选项)。
我希望该选择自动插入到主题行中。
我在网上找到了代码,但在代码末尾出现错误。
Private Sub m_colInspectors_NewInspector(ByVal Inspector As Outlook.Inspector)
我将此代码粘贴到 ThisOutlookSession 模块中。
Option Explicit
Private WithEvents m_colInspectors As Outlook.Inspectors
Private WithEvents CurrentInspector As Outlook.Inspector
Private Sub Application_Startup()
Set m_colInspectors = Application.Inspectors
End Sub
Private Sub CurrentInspector_Activate()
Dim oMail As Outlook.MailItem
If Len(UserForm1.SelectedSubject) Then
Set oMail = CurrentInspector.CurrentItem
oMail.Subject = UserForm1.SelectedSubject
End If
Set CurrentInspector = Nothing
End Sub
Private Sub m_colInspectors_NewInspector(ByVal Inspector As Outlook.Inspector)
If TypeOf Inspector.CurrentItem Is Outlook.MailItem Then
If Inspector.CurrentItem.EntryID = vbNullString Then
UserForm1.SelectedSubject = vbNullString
UserForm1.Show
Set CurrentInspector = Inspector
End If
End If
End Sub
我创建了一个带有单选按钮和一个命令按钮的表单,我在其中插入了以下代码。
Option Explicit
Public SelectedSubject As String
Private Sub CommandButton1_Click()
If OptionButton1.Value = True Then
SelectedSubject = "Test"
End If
Hide
End Sub
【问题讨论】:
-
我已经为你添加了 Outlook-VBA 作为标签。您的问题中没有提到 Excel,所以我认为应该删除它。
标签: vba email outlook userform