A
amanat
Hello All,
I am having problem with my Command bar button.I am using Ken's Inspector
wrapper. Language is VB6 and outlook 2000.
I am trying to add simple command button to the mailitem and when it gets
clicked the message get added to subject line.But I m not able to do this.
Can anyone please gude me. I have gone through Microeye.com for ItemsCb
sample, but i m not able to fix my problem.
Below is my code.
I used 1 class module called clsinswrap and one module called basoutlinsp,and
one Connect Code module
clsinswrap Code:
'Option Explicit
'Private gbaseClass As New outaddin
Private m_lngid As Integer
'Public array for forms
'This array holds folder-level custom form display name and message class
Public avarForms
'Use gstrProgID to set the OnAction property of CB buttons
Public gstrProgID As String
Dim cbrnewtoolbar As CommandBarControl
Private WithEvents objoutlook As Outlook.Application
Private WithEvents m_objInsp As Outlook.Inspector
Private WithEvents m_objmail As Outlook.Mailitem
Private WithEvents ctlbtnpriv As Office.CommandBarButton
Private m_obj As Object
Private m_strmailid As Integer
Private m_intID As Integer
Private mnuTag As String
Private m_startup As Boolean
Private m_blnMailInspector As Boolean
Private m_blnWord As Boolean
Sub ctlBtnPriv_Click(ByVal Ctrl As Office.CommandBarButton, default As
Boolean)
On Error Resume Next
'Dim m_objmail As Mailitem
Set m_objmail = objoutlook.ActiveInspector.CurrentItem
'Save the item first so that if the button is pressed qhile the
cursor is in the subject, then the
'entered subject will get appended to.
m_objmail.Save
m_objmail.Subject = "msg - " & m_objmail.Subject
End Sub
Private Sub Class_Initialize()
Set m_objInsp = Nothing
Set m_objmail = Nothing
Set ctlbtnpriv = Nothing
m_blnWord = False
Set m_obj = Nothing
End Sub
Private Sub Class_Terminate()
On Error Resume Next
Set m_objInsp = Nothing
Set m_objmail = Nothing
Set ctlbtnpriv = Nothing
Set m_obj = Nothing
Set m_obj = Nothing
End Sub
Public Property Let Mailitem(objMail As Outlook.Mailitem)
On Error Resume Next
Set m_objmail = objMail
m_strmailid = objMail.EntryID
m_blnMailInspector = True
End Property
Public Property Let Inspector(objInspector As Outlook.Inspector)
On Error Resume Next
Set m_objInsp = objInspector
End Property
Public Property Get Inspector() As Outlook.Inspector
On Error Resume Next
Set Inspector = m_objInsp
End Property
Public Property Let Key(lngID As Long)
On Error Resume Next
m_intID = lngID
End Property
Public Property Get Key() As Long
On Error Resume Next
Key = m_intID
End Property
Private Sub m_objMail_Close(Cancel As Boolean)
On Error Resume Next
If objoutlook.Explorers.Count = 0 And objoutlook.Inspectors.Count <= 1 Then
UnInitHandler
basoutlinsp.KillInsp m_intID, Me
End If
Set m_objmail = Nothing
Set objoutlook = Nothing
End Sub
Private Sub m_objMail_Open(Cancel As Boolean)
On Error Resume Next
'can handle various events for the mail item
' in the Inspector like Close and Open.
End Sub
Private Sub objInsp_Close(Cancel As Boolean)
On Error Resume Next
On Error Resume Next
basoutlinsp.KillInsp m_intID, Me
Set m_objInsp = Nothing
End Sub
Public Function InitButton() As Boolean
Set cbrnewtoolbar = objoutlook.ActiveExplorer.CommandBars("Items")
On Error Resume Next
Set ctlbtnpriv = objoutlook.ActiveExplorer.CommandBars.FindControl(Tag:
=267)
End Function
Private Sub KillButtons()
Dim oControl As Office.CommandBarControl
On Error Resume Next
Set oControl = m_obj.CommandBars.FindControl(Tag:=mnuTag)
If Not oControl Is Nothing Then
oControl.Delete
End If
Set oControl = Nothing
End Sub
Friend Sub UnInitHandler()
On Error Resume Next
Set objoutlook = Nothing
Set m_objmail = Nothing
Set ctlbtnpriv = Nothing
Set m_objInsp = Nothing
End Sub
(not sure how to do this---------what to write in OnAction???)
Public Function CreateAddInCommandBarButton _
(strProgID As String, objCommandBar As CommandBar, _
strCaption As String, strTag As String, strTip As String, _
intFaceID As Integer, blnBeginGroup As Boolean, intStyle As Integer) _
As Office.CommandBarButton
Dim ctlBtnAddin As CommandBarButton
On Error Resume Next
' Test to determine if button exists on command bar.
Set ctlBtnAddin = objCommandBar.FindControl(Tag:=strTag)
If ctlBtnAddin Is Nothing Then
' Add new button.
Set ctlBtnAddin = objCommandBar.Controls.Add(Type:=msoControlButton,
_
Parameter:=strTag)
' Set button's Caption, Tag, Style, and OnAction properties.
With ctlBtnAddin
.Caption = "kshma"
.Tag = strTag
If intStyle <> msoButtonCaption Then
.FaceId = intFaceID
End If
.Style = intStyle
.ToolTipText = strTip
.BeginGroup = blnBeginGroup
' Set the OnAction property with ProgID of Add-In
.OnAction = "<!" & 267 _
& ">"
End With
End If
' Return reference to new commandbar button.
Set CreateAddInCommandBarButton = ctlBtnAddin
End Function
Basoutlinsp code:
'************************************************************
' This code is in a code module called basOutlInsp. The
' wrapper class for an Inspector is called clsInspWrap.
' The collection that holds the Inspector wrapper
' classes is called g_colInspWrap. It is declared in a
' code module as a global Collection object.
'************************************************************
Dim omail As Outlook.Mailitem
Public pinsps_InspWrap As New Collection
Private intID As Integer
Private blnActivate As Boolean
Public Function AddInsp(Inspector As Outlook.Inspector) As String
Dim objInspWrap As New clsinspwrap
Dim objitem As Object
Dim strID As String
On Error Resume Next
'set the Inspector in the class
Set omail = Nothing
If Inspector.CurrentItem.Class = omail Then
Set omail = Inspector.curentitem
If Not (omail Is Nothing) Then
With objInspWrap
.Inspector = Inspector
.Mailitem = omail
.Key = intID
End With
pinsps_InspWrap.Add objInspWrap, CStr(strID)
intID = intID + 1
End If
End If
' AddInsp = strID
' intID = intID + 1
Set objInspWrap = Nothing
Set omail = Nothing
End Function
Public Sub KillInsp(intID As Integer, objInspWrap As clsinspwrap)
Dim objInspWrap2 As clsinspwrap
On Error Resume Next
Set objInspWrap2 = pinsps_InspWrap.Item(CStr(intID))
' check to make sure we're removing the
' correct Inspector from the collection.
If Not objInspWrap2 Is objInspWrap Then
Err.Raise 1, Description:="Unexpected Error in KillInsp"
GoTo ExitSub
End If
pinsps_InspWrap.Remove CStr(intID)
ExitSub:
Set objInspWrap2 = Nothing
End Sub
Connect code:
Option Explicit
Public WithEvents pinsps As Outlook.Inspectors
Public WithEvents objInsp As Outlook.Inspector
Public WithEvents ctlbtnpriv As CommandBarButton
Public WithEvents objoutlook As Outlook.Application
Private WithEvents m_objmail As Outlook.Mailitem
Private WithEvents colExpl As Outlook.Explorers
Private WithEvents objmailitem As Mailitem
'*********************************************************************
'IDTExtensibility2 is the interface that COM Add-Ins must implement.
'The project references the following object libraries:
'Add additional object libraries as required for your COM Add-in.
'References:
'Microsoft Add-In Designer
'Microsoft Outlook 9.0 object library
'Microsoft Office 9.0 object library
'Microsoft Word 9.0 object library
'Microsoft Excel 9.0 object library
'Microsoft PPT 9.0 object library
'Class: Connect
'Purpose: Office 2000 COM Add-in
'Initial Load: Startup
'*********************************************************************
Implements IDTExtensibility2
Private Sub IDTExtensibility2_OnAddInsupdate(custom() As Variant)
End Sub
Private Sub IDTExtensibility2_OnBeginShutdown(custom() As Variant)
'
End Sub
'*********************************************************************
'Procedure: IDTExtensibility2_OnConnection
'Purpose: Iniitialize gBaseClass and run additional startup code
'*********************************************************************
Private Sub IDTExtensibility2_OnConnection(ByVal Application As Object, _
ByVal ConnectMode As AddInDesignerObjects.ext_ConnectMode, _
ByVal AddInInst As Object, custom() As Variant)
'To debug a COM Add-in, uncomment the Stop line below or place
'a breakpoint in the procedure that you want to debug.
'If the COM Add-in is loaded as a compiled dll, you must
'first unload the COM Add-in using the COM Add-Ins dialog box.
'Place the COM Add-in project in Run mode and then
'use the COM Add-Ins dialog box to reload the COM Add-in.
'Stop
'Don't forget to recomment this line when
'you recompile your debugged add-
Set objoutlook = Application
Set pinsps = Application.Inspectors
End Sub
Private Sub IDTExtensibility2_OnDisconnection(ByVal RemoveMode _
As AddInDesignerObjects.ext_DisconnectMode, custom() As Variant)
Set objoutlook = Nothing
End Sub
Private Sub IDTExtensibility2_OnStartupComplete(custom() As Variant)
End Sub
Private Sub pInsps_NewInspector(ByVal Inspector As Inspector)
Dim objitem As Object
Dim strID As String
Set objInsp = Inspector
Set objitem = objInsp.CurrentItem
Select Case objitem.Class
Case olMail
basoutlinsp.AddInsp (Inspector)
Set m_objmail = objitem
End Select
Set objitem = Nothing
Set objInsp = Nothing
End Sub
Please help me on this , I want that button should appear in all inspector
windows and gets clicked whichever is opened.
Thanks in advance. Any help is appreciated.
I am having problem with my Command bar button.I am using Ken's Inspector
wrapper. Language is VB6 and outlook 2000.
I am trying to add simple command button to the mailitem and when it gets
clicked the message get added to subject line.But I m not able to do this.
Can anyone please gude me. I have gone through Microeye.com for ItemsCb
sample, but i m not able to fix my problem.
Below is my code.
I used 1 class module called clsinswrap and one module called basoutlinsp,and
one Connect Code module
clsinswrap Code:
'Option Explicit
'Private gbaseClass As New outaddin
Private m_lngid As Integer
'Public array for forms
'This array holds folder-level custom form display name and message class
Public avarForms
'Use gstrProgID to set the OnAction property of CB buttons
Public gstrProgID As String
Dim cbrnewtoolbar As CommandBarControl
Private WithEvents objoutlook As Outlook.Application
Private WithEvents m_objInsp As Outlook.Inspector
Private WithEvents m_objmail As Outlook.Mailitem
Private WithEvents ctlbtnpriv As Office.CommandBarButton
Private m_obj As Object
Private m_strmailid As Integer
Private m_intID As Integer
Private mnuTag As String
Private m_startup As Boolean
Private m_blnMailInspector As Boolean
Private m_blnWord As Boolean
Sub ctlBtnPriv_Click(ByVal Ctrl As Office.CommandBarButton, default As
Boolean)
On Error Resume Next
'Dim m_objmail As Mailitem
Set m_objmail = objoutlook.ActiveInspector.CurrentItem
'Save the item first so that if the button is pressed qhile the
cursor is in the subject, then the
'entered subject will get appended to.
m_objmail.Save
m_objmail.Subject = "msg - " & m_objmail.Subject
End Sub
Private Sub Class_Initialize()
Set m_objInsp = Nothing
Set m_objmail = Nothing
Set ctlbtnpriv = Nothing
m_blnWord = False
Set m_obj = Nothing
End Sub
Private Sub Class_Terminate()
On Error Resume Next
Set m_objInsp = Nothing
Set m_objmail = Nothing
Set ctlbtnpriv = Nothing
Set m_obj = Nothing
Set m_obj = Nothing
End Sub
Public Property Let Mailitem(objMail As Outlook.Mailitem)
On Error Resume Next
Set m_objmail = objMail
m_strmailid = objMail.EntryID
m_blnMailInspector = True
End Property
Public Property Let Inspector(objInspector As Outlook.Inspector)
On Error Resume Next
Set m_objInsp = objInspector
End Property
Public Property Get Inspector() As Outlook.Inspector
On Error Resume Next
Set Inspector = m_objInsp
End Property
Public Property Let Key(lngID As Long)
On Error Resume Next
m_intID = lngID
End Property
Public Property Get Key() As Long
On Error Resume Next
Key = m_intID
End Property
Private Sub m_objMail_Close(Cancel As Boolean)
On Error Resume Next
If objoutlook.Explorers.Count = 0 And objoutlook.Inspectors.Count <= 1 Then
UnInitHandler
basoutlinsp.KillInsp m_intID, Me
End If
Set m_objmail = Nothing
Set objoutlook = Nothing
End Sub
Private Sub m_objMail_Open(Cancel As Boolean)
On Error Resume Next
'can handle various events for the mail item
' in the Inspector like Close and Open.
End Sub
Private Sub objInsp_Close(Cancel As Boolean)
On Error Resume Next
On Error Resume Next
basoutlinsp.KillInsp m_intID, Me
Set m_objInsp = Nothing
End Sub
Public Function InitButton() As Boolean
Set cbrnewtoolbar = objoutlook.ActiveExplorer.CommandBars("Items")
On Error Resume Next
Set ctlbtnpriv = objoutlook.ActiveExplorer.CommandBars.FindControl(Tag:
=267)
End Function
Private Sub KillButtons()
Dim oControl As Office.CommandBarControl
On Error Resume Next
Set oControl = m_obj.CommandBars.FindControl(Tag:=mnuTag)
If Not oControl Is Nothing Then
oControl.Delete
End If
Set oControl = Nothing
End Sub
Friend Sub UnInitHandler()
On Error Resume Next
Set objoutlook = Nothing
Set m_objmail = Nothing
Set ctlbtnpriv = Nothing
Set m_objInsp = Nothing
End Sub
(not sure how to do this---------what to write in OnAction???)
Public Function CreateAddInCommandBarButton _
(strProgID As String, objCommandBar As CommandBar, _
strCaption As String, strTag As String, strTip As String, _
intFaceID As Integer, blnBeginGroup As Boolean, intStyle As Integer) _
As Office.CommandBarButton
Dim ctlBtnAddin As CommandBarButton
On Error Resume Next
' Test to determine if button exists on command bar.
Set ctlBtnAddin = objCommandBar.FindControl(Tag:=strTag)
If ctlBtnAddin Is Nothing Then
' Add new button.
Set ctlBtnAddin = objCommandBar.Controls.Add(Type:=msoControlButton,
_
Parameter:=strTag)
' Set button's Caption, Tag, Style, and OnAction properties.
With ctlBtnAddin
.Caption = "kshma"
.Tag = strTag
If intStyle <> msoButtonCaption Then
.FaceId = intFaceID
End If
.Style = intStyle
.ToolTipText = strTip
.BeginGroup = blnBeginGroup
' Set the OnAction property with ProgID of Add-In
.OnAction = "<!" & 267 _
& ">"
End With
End If
' Return reference to new commandbar button.
Set CreateAddInCommandBarButton = ctlBtnAddin
End Function
Basoutlinsp code:
'************************************************************
' This code is in a code module called basOutlInsp. The
' wrapper class for an Inspector is called clsInspWrap.
' The collection that holds the Inspector wrapper
' classes is called g_colInspWrap. It is declared in a
' code module as a global Collection object.
'************************************************************
Dim omail As Outlook.Mailitem
Public pinsps_InspWrap As New Collection
Private intID As Integer
Private blnActivate As Boolean
Public Function AddInsp(Inspector As Outlook.Inspector) As String
Dim objInspWrap As New clsinspwrap
Dim objitem As Object
Dim strID As String
On Error Resume Next
'set the Inspector in the class
Set omail = Nothing
If Inspector.CurrentItem.Class = omail Then
Set omail = Inspector.curentitem
If Not (omail Is Nothing) Then
With objInspWrap
.Inspector = Inspector
.Mailitem = omail
.Key = intID
End With
pinsps_InspWrap.Add objInspWrap, CStr(strID)
intID = intID + 1
End If
End If
' AddInsp = strID
' intID = intID + 1
Set objInspWrap = Nothing
Set omail = Nothing
End Function
Public Sub KillInsp(intID As Integer, objInspWrap As clsinspwrap)
Dim objInspWrap2 As clsinspwrap
On Error Resume Next
Set objInspWrap2 = pinsps_InspWrap.Item(CStr(intID))
' check to make sure we're removing the
' correct Inspector from the collection.
If Not objInspWrap2 Is objInspWrap Then
Err.Raise 1, Description:="Unexpected Error in KillInsp"
GoTo ExitSub
End If
pinsps_InspWrap.Remove CStr(intID)
ExitSub:
Set objInspWrap2 = Nothing
End Sub
Connect code:
Option Explicit
Public WithEvents pinsps As Outlook.Inspectors
Public WithEvents objInsp As Outlook.Inspector
Public WithEvents ctlbtnpriv As CommandBarButton
Public WithEvents objoutlook As Outlook.Application
Private WithEvents m_objmail As Outlook.Mailitem
Private WithEvents colExpl As Outlook.Explorers
Private WithEvents objmailitem As Mailitem
'*********************************************************************
'IDTExtensibility2 is the interface that COM Add-Ins must implement.
'The project references the following object libraries:
'Add additional object libraries as required for your COM Add-in.
'References:
'Microsoft Add-In Designer
'Microsoft Outlook 9.0 object library
'Microsoft Office 9.0 object library
'Microsoft Word 9.0 object library
'Microsoft Excel 9.0 object library
'Microsoft PPT 9.0 object library
'Class: Connect
'Purpose: Office 2000 COM Add-in
'Initial Load: Startup
'*********************************************************************
Implements IDTExtensibility2
Private Sub IDTExtensibility2_OnAddInsupdate(custom() As Variant)
End Sub
Private Sub IDTExtensibility2_OnBeginShutdown(custom() As Variant)
'
End Sub
'*********************************************************************
'Procedure: IDTExtensibility2_OnConnection
'Purpose: Iniitialize gBaseClass and run additional startup code
'*********************************************************************
Private Sub IDTExtensibility2_OnConnection(ByVal Application As Object, _
ByVal ConnectMode As AddInDesignerObjects.ext_ConnectMode, _
ByVal AddInInst As Object, custom() As Variant)
'To debug a COM Add-in, uncomment the Stop line below or place
'a breakpoint in the procedure that you want to debug.
'If the COM Add-in is loaded as a compiled dll, you must
'first unload the COM Add-in using the COM Add-Ins dialog box.
'Place the COM Add-in project in Run mode and then
'use the COM Add-Ins dialog box to reload the COM Add-in.
'Stop
'Don't forget to recomment this line when
'you recompile your debugged add-
Set objoutlook = Application
Set pinsps = Application.Inspectors
End Sub
Private Sub IDTExtensibility2_OnDisconnection(ByVal RemoveMode _
As AddInDesignerObjects.ext_DisconnectMode, custom() As Variant)
Set objoutlook = Nothing
End Sub
Private Sub IDTExtensibility2_OnStartupComplete(custom() As Variant)
End Sub
Private Sub pInsps_NewInspector(ByVal Inspector As Inspector)
Dim objitem As Object
Dim strID As String
Set objInsp = Inspector
Set objitem = objInsp.CurrentItem
Select Case objitem.Class
Case olMail
basoutlinsp.AddInsp (Inspector)
Set m_objmail = objitem
End Select
Set objitem = Nothing
Set objInsp = Nothing
End Sub
Please help me on this , I want that button should appear in all inspector
windows and gets clicked whichever is opened.
Thanks in advance. Any help is appreciated.