P
Phil Roberts
Hi everyone,
Could someone please offer some advice on how to proceed with my
Outlook Addin. The goal is to add a combobox, on the standard toolbar,
to mail composition inspectors that adds the selected combobox item to
the mail subject line.
I almost have this going but am having a problem with it working for
multiple inspectors. It works well initally but then the combobox
stops working. My inspector wrapper code is below.
Thanks.
Option Explicit
Private gBaseClass As New OutAddIn
Private WithEvents cbObj As Office.CommandBarComboBox
Private WithEvents m_objInsp As Outlook.Inspector
Private m_nID As Integer
Private Sub Class_Initialize()
Set cbObj = Nothing
Set m_objInsp = Nothing
End Sub
Private Sub Class_Terminate()
Set cbObj = Nothing
Set m_objInsp = Nothing
End Sub
Public Property Let Inspector(objInspl As Outlook.Inspector)
Set m_objInsp = objInspl
End Property
Public Property Get Inspector() As Outlook.Inspector
Set Inspector = m_objInsp
End Property
Public Property Let Key(anID As Integer)
m_nID = anID
End Property
Private Sub m_objInsp_Close()
modOutInsp.KillInsp m_nID, Me
Set m_objInsp = Nothing
If golApp.Explorers.Count <= 1 Then
gBaseClass.UnInitHandler
End If
End Sub
Private Sub m_objInsp_Activate()
Dim cbStandard As CommandBar
Dim cbB As CommandBarButton
Dim cbCB As CommandBarComboBox
Set cbStandard = m_objInsp.CommandBars("Standard")
Set cbCB = cbStandard.FindControl(Tag:="cbObj")
If cbCB Is Nothing Then
Set cbB = cbStandard.FindControl(Id:=2617) 'find the "Send"
item button (ID=2617)
If cbB Is Nothing Then
Exit Sub
End If
Set cbObj = cbStandard.Controls.Add(Type:=msoControlDropdown,
before:=cbB.Index + 1, temporary:=True)
With cbObj 'set combobox properties
.ToolTipText = "Add text to the subject line"
.AddItem "Select...", 1
.AddItem "OPTION 1", 2
.AddItem "OPTION 2", 3
.ListIndex = 1
.DropDownWidth = -1
.Tag = "cbObj"
.Style = msoComboNormal
.Visible = True
.Caption = "Text:"
.OnAction = "!<OptionX.Connect>" 'assign the proc to be
called
.BeginGroup = True
End With
End If
End Sub
Private Sub cbObj_Change(ByVal Ctrl As Office.CommandBarComboBox)
Dim oMail As MailItem
On Error GoTo HelpMe
Set oMail = Application.ActiveInspector.CurrentItem
If Ctrl.Text <> "Select..." Then
oMail.SaveAs "C:\Last.msg", olMSG 'must save to get access to
current subject line
Kill "C:\Last.msg"
oMail.Subject = oMail.Subject & " : " & Ctrl.Text 'add text to
subject
End If
Ctrl.ListIndex = 1
CleanUp:
Set oMail = Nothing 'dispose of object
Exit Sub
HelpMe:
MsgBox "Help Me!", _
vbOKOnly + vbInformation, "Add Text"
GoTo CleanUp
End Sub
Could someone please offer some advice on how to proceed with my
Outlook Addin. The goal is to add a combobox, on the standard toolbar,
to mail composition inspectors that adds the selected combobox item to
the mail subject line.
I almost have this going but am having a problem with it working for
multiple inspectors. It works well initally but then the combobox
stops working. My inspector wrapper code is below.
Thanks.
Option Explicit
Private gBaseClass As New OutAddIn
Private WithEvents cbObj As Office.CommandBarComboBox
Private WithEvents m_objInsp As Outlook.Inspector
Private m_nID As Integer
Private Sub Class_Initialize()
Set cbObj = Nothing
Set m_objInsp = Nothing
End Sub
Private Sub Class_Terminate()
Set cbObj = Nothing
Set m_objInsp = Nothing
End Sub
Public Property Let Inspector(objInspl As Outlook.Inspector)
Set m_objInsp = objInspl
End Property
Public Property Get Inspector() As Outlook.Inspector
Set Inspector = m_objInsp
End Property
Public Property Let Key(anID As Integer)
m_nID = anID
End Property
Private Sub m_objInsp_Close()
modOutInsp.KillInsp m_nID, Me
Set m_objInsp = Nothing
If golApp.Explorers.Count <= 1 Then
gBaseClass.UnInitHandler
End If
End Sub
Private Sub m_objInsp_Activate()
Dim cbStandard As CommandBar
Dim cbB As CommandBarButton
Dim cbCB As CommandBarComboBox
Set cbStandard = m_objInsp.CommandBars("Standard")
Set cbCB = cbStandard.FindControl(Tag:="cbObj")
If cbCB Is Nothing Then
Set cbB = cbStandard.FindControl(Id:=2617) 'find the "Send"
item button (ID=2617)
If cbB Is Nothing Then
Exit Sub
End If
Set cbObj = cbStandard.Controls.Add(Type:=msoControlDropdown,
before:=cbB.Index + 1, temporary:=True)
With cbObj 'set combobox properties
.ToolTipText = "Add text to the subject line"
.AddItem "Select...", 1
.AddItem "OPTION 1", 2
.AddItem "OPTION 2", 3
.ListIndex = 1
.DropDownWidth = -1
.Tag = "cbObj"
.Style = msoComboNormal
.Visible = True
.Caption = "Text:"
.OnAction = "!<OptionX.Connect>" 'assign the proc to be
called
.BeginGroup = True
End With
End If
End Sub
Private Sub cbObj_Change(ByVal Ctrl As Office.CommandBarComboBox)
Dim oMail As MailItem
On Error GoTo HelpMe
Set oMail = Application.ActiveInspector.CurrentItem
If Ctrl.Text <> "Select..." Then
oMail.SaveAs "C:\Last.msg", olMSG 'must save to get access to
current subject line
Kill "C:\Last.msg"
oMail.Subject = oMail.Subject & " : " & Ctrl.Text 'add text to
subject
End If
Ctrl.ListIndex = 1
CleanUp:
Set oMail = Nothing 'dispose of object
Exit Sub
HelpMe:
MsgBox "Help Me!", _
vbOKOnly + vbInformation, "Add Text"
GoTo CleanUp
End Sub