![]() |
If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below. |
|
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
![]()
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 '************************************************* ******************** 'Procedu 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. |
#2
|
|||
|
|||
![]()
Where are you calling your InitButton sub? I didn't see a call to that. In
that sub if you want a button in the Inspector you can't be using ActiveExplorer. Use the Inspector object (objInsp) for that Inspector wrapper. You also need to add that button if it's not found using FindControl, your code doesn't do that at all. I don't see any calls to CreateAddInCommandBarButton, but if there were the ProgID you pass to that procedure would be something like "MyAddin.Connect" or whatever your connect class and addin dll are named. You wouldn't use the tag property. -- Ken Slovak [MVP - Outlook] http://www.slovaktech.com Author: Professional Programming Outlook 2007. Reminder Manager, Extended Reminders, Attachment Options. http://www.slovaktech.com/products.htm "amanat" u45636@uwe wrote in message news:89022831e133d@uwe... 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 '************************************************* ******************** 'Procedu 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. |
#3
|
|||
|
|||
![]()
Hey Ken ,
Thank you so much for replying to my query.Thanks alot.I have made changes in my code according to your suggestions, but Still I am not able to see command button at all. Can you please once again check my code .I will be very thankful. basOutlInsp Code: 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 objInspWrap.Inspector = Inspector Set objitem = Inspector.CurrentItem Select Case objitem.Class Case omail objInspWrap.Mailitem = objitem Case Else End Select objInspWrap.Key = intID strID = CStr(intID) pinsps_InspWrap.Add objInspWrap, strID objInspWrap.InitButton AddInsp = strID intID = intID + 1 Set objInspWrap = Nothing Set objitem = 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 Private Sub objInsp_Close() On Error Resume Next 'g_olApp is a global Outlook.Application object that is derived ' from the Application object passed to the COM addin in the ' On_Connection event. If objoutlook.Explorers.Count = 0 And objoutlook.Inspectors.Count = 1 Then Set objInsp = Nothing 'call the code to release all Outlook objects UnInitHandler End If End Sub Public Sub UnInitHandler() On Error Resume Next Set objoutlook = Nothing ' Set objitem = Nothing 'Set ctlbtnpriv = Nothing Set objInsp = Nothing End Sub clsinspwrap code: Option Explicit 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_intID As Integer Private mnuTag As String Private m_blnMailInspector As Boolean Private m_blnWord As Boolean Private btnTag As String Sub ctlBtnPriv_Click(ByVal Ctrl As Office.CommandBarButton, canceldefault As Boolean) Dim strNewToolTip As String On Error Resume Next strNewToolTip = "testing123" Ctrl.ToolTipText = strNewToolTip 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 End Sub Public Function InitButton() As Boolean On Error Resume Next Call CreateButton(m_objInsp) End Function 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 'can handle various events for the mail item ' in the Inspector like Close and Open. If Cancel = False Then Call KillButtons basoutlinsp.KillInsp m_intID, Me Set m_objInsp = Nothing End If 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 m_objInsp_Close() On Error Resume Next Call KillButtons basoutlinsp.KillInsp m_intID, Me Set m_objInsp = Nothing End Sub Private Sub KillButtons() Dim oControl As Office.CommandBarControl On Error Resume Next Set oControl = m_obj.CommandBars.FindControl(Tag:=btnTag) If Not oControl Is Nothing Then oControl.Delete End If Set oControl = Nothing End Sub Private Sub CreateButton(objinspector As Outlook.Inspector) On Error Resume Next 'Adding a new menu item and a button to the main menu for any Inspector ' must take a different approach if using Word as email editor. If (objinspector.IsWordMail = True) And _ (objinspector.EditorType = olEditorWord) Then m_blnWord = True Set m_obj = Nothing Else m_blnWord = False Set m_obj = objinspector Call createmenu End If Err.Clear End Sub Private Sub createmenu() Dim strToolTip As String Dim strCaption As String Dim strKey As String Dim oCommandBar As Office.CommandBar Dim oStandardBar As Office.CommandBar Dim oCBC As Office.CommandBarControl Dim oControl As Office.CommandBarControl Set oStandardBar = Nothing On Error Resume Next strKey = CStr(m_intID) 'Find Standard Toolbar For Each oCommandBar In m_obj.CommandBars If oCommandBar.Name = "Standard" Then Set oStandardBar = oCommandBar If oStandardBar Is Nothing Then Set oStandardBar = m_obj.CommandBars.FindControl(Tag:=btnTag) End If Exit For End If Next oCommandBar 'Create button If Not (oStandardBar Is Nothing) Then oStandardBar.Visible = True btnTag = "This string is unique to this button" & strKey strToolTip = "Testing123" strCaption = "Testing" Set ctlbtnpriv = oStandardBar.Controls.Add(Type:=msoControlButton, Temporary: =True) With ctlbtnpriv .Caption = strCaption .Tag = btnTag .ToolTipText = strToolTip .Style = msoButtonCaption .Visible = True End With End If Set oControl = Nothing Set oCommandBar = Nothing Set oStandardBar = Nothing 'Set oCommandBarButton = Nothing End Sub '-------------------------------------------------------------------------- Private Sub m_objInsp_Activate() On Error Resume Next 'If m_blnButtonsCreated = False Then 'Set m_obj = m_objInsp.WordEditor Call createmenu 'End If 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 '************************************************* ******************** 'Procedu 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 strID = basoutlinsp.AddInsp(Inspector) Case Else End Select Set objitem = Nothing End Sub Thank you Ken Slovak - [MVP - Outlook] wrote: Where are you calling your InitButton sub? I didn't see a call to that. In that sub if you want a button in the Inspector you can't be using ActiveExplorer. Use the Inspector object (objInsp) for that Inspector wrapper. You also need to add that button if it's not found using FindControl, your code doesn't do that at all. I don't see any calls to CreateAddInCommandBarButton, but if there were the ProgID you pass to that procedure would be something like "MyAddin.Connect" or whatever your connect class and addin dll are named. You wouldn't use the tag property. Hello All, I am having problem with my Command bar button.I am using Ken's [quoted text clipped - 336 lines] windows and gets clicked whichever is opened. Thanks in advance. Any help is appreciated. -- Message posted via OfficeKB.com http://www.officekb.com/Uwe/Forums.a...ddins/200808/1 |
#4
|
|||
|
|||
![]()
Your Activate() handler is calling to createmenu(), not to CreateButton().
It looks to me like at that call the reference to m_obj will be null (Nothing) since nothing has initialized that object. You also need to set up a Boolean flag that gets set to True when you have created the UI and check that flag in Activate() so you don't end up creating new UI each time Activate() fires. You only want to do that once. You also should step your code and observe the state of Err and your objects as you create your UI so you know what's happening. -- Ken Slovak [MVP - Outlook] http://www.slovaktech.com Author: Professional Programming Outlook 2007. Reminder Manager, Extended Reminders, Attachment Options. http://www.slovaktech.com/products.htm "amanat via OfficeKB.com" u45636@uwe wrote in message news:890d7299cd5af@uwe... Hey Ken , Thank you so much for replying to my query.Thanks alot.I have made changes in my code according to your suggestions, but Still I am not able to see command button at all. Can you please once again check my code .I will be very thankful. basOutlInsp Code: 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 objInspWrap.Inspector = Inspector Set objitem = Inspector.CurrentItem Select Case objitem.Class Case omail objInspWrap.Mailitem = objitem Case Else End Select objInspWrap.Key = intID strID = CStr(intID) pinsps_InspWrap.Add objInspWrap, strID objInspWrap.InitButton AddInsp = strID intID = intID + 1 Set objInspWrap = Nothing Set objitem = 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 Private Sub objInsp_Close() On Error Resume Next 'g_olApp is a global Outlook.Application object that is derived ' from the Application object passed to the COM addin in the ' On_Connection event. If objoutlook.Explorers.Count = 0 And objoutlook.Inspectors.Count = 1 Then Set objInsp = Nothing 'call the code to release all Outlook objects UnInitHandler End If End Sub Public Sub UnInitHandler() On Error Resume Next Set objoutlook = Nothing ' Set objitem = Nothing 'Set ctlbtnpriv = Nothing Set objInsp = Nothing End Sub clsinspwrap code: Option Explicit 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_intID As Integer Private mnuTag As String Private m_blnMailInspector As Boolean Private m_blnWord As Boolean Private btnTag As String Sub ctlBtnPriv_Click(ByVal Ctrl As Office.CommandBarButton, canceldefault As Boolean) Dim strNewToolTip As String On Error Resume Next strNewToolTip = "testing123" Ctrl.ToolTipText = strNewToolTip 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 End Sub Public Function InitButton() As Boolean On Error Resume Next Call CreateButton(m_objInsp) End Function 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 'can handle various events for the mail item ' in the Inspector like Close and Open. If Cancel = False Then Call KillButtons basoutlinsp.KillInsp m_intID, Me Set m_objInsp = Nothing End If 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 m_objInsp_Close() On Error Resume Next Call KillButtons basoutlinsp.KillInsp m_intID, Me Set m_objInsp = Nothing End Sub Private Sub KillButtons() Dim oControl As Office.CommandBarControl On Error Resume Next Set oControl = m_obj.CommandBars.FindControl(Tag:=btnTag) If Not oControl Is Nothing Then oControl.Delete End If Set oControl = Nothing End Sub Private Sub CreateButton(objinspector As Outlook.Inspector) On Error Resume Next 'Adding a new menu item and a button to the main menu for any Inspector ' must take a different approach if using Word as email editor. If (objinspector.IsWordMail = True) And _ (objinspector.EditorType = olEditorWord) Then m_blnWord = True Set m_obj = Nothing Else m_blnWord = False Set m_obj = objinspector Call createmenu End If Err.Clear End Sub Private Sub createmenu() Dim strToolTip As String Dim strCaption As String Dim strKey As String Dim oCommandBar As Office.CommandBar Dim oStandardBar As Office.CommandBar Dim oCBC As Office.CommandBarControl Dim oControl As Office.CommandBarControl Set oStandardBar = Nothing On Error Resume Next strKey = CStr(m_intID) 'Find Standard Toolbar For Each oCommandBar In m_obj.CommandBars If oCommandBar.Name = "Standard" Then Set oStandardBar = oCommandBar If oStandardBar Is Nothing Then Set oStandardBar = m_obj.CommandBars.FindControl(Tag:=btnTag) End If Exit For End If Next oCommandBar 'Create button If Not (oStandardBar Is Nothing) Then oStandardBar.Visible = True btnTag = "This string is unique to this button" & strKey strToolTip = "Testing123" strCaption = "Testing" Set ctlbtnpriv = oStandardBar.Controls.Add(Type:=msoControlButton, Temporary: =True) With ctlbtnpriv Caption = strCaption Tag = btnTag ToolTipText = strToolTip Style = msoButtonCaption Visible = True End With End If Set oControl = Nothing Set oCommandBar = Nothing Set oStandardBar = Nothing 'Set oCommandBarButton = Nothing End Sub '-------------------------------------------------------------------------- Private Sub m_objInsp_Activate() On Error Resume Next 'If m_blnButtonsCreated = False Then 'Set m_obj = m_objInsp.WordEditor Call createmenu 'End If 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 '************************************************* ******************** 'Procedu 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 strID = basoutlinsp.AddInsp(Inspector) Case Else End Select Set objitem = Nothing End Sub Thank you |
#5
|
|||
|
|||
![]()
Hey Ken ,
Thanks for quick reply, Can you please guide me in detail as to what should I do once again , I did folling changes in create menu : Private Sub createmenu() Dim oControl As office.CommandBarControl Dim m_ocontrolbar As CommandBarControl Dim strMenu As String Dim strTag As String Dim strToolTip As String Dim strCaption As String Dim strKey As String Dim blnMenuExists As Boolean Dim oCommandBar As office.CommandBar Dim oStandardBar As office.CommandBar On Error Resume Next strKey = CStr(m_intID) mnuTag = "This string is unique to this menu" & strKey strMenu = "Menu Bar" strToolTip = "The ToolTip for the menu" strCaption = "The caption for the menu" 'check for the menu existing already and do not create ' it if does exist. The checking code would set a ' Boolean variable named blnMenuExists. If Not blnMenuExists Then Set oControl = m_obj.CommandBars.FindControl(Tag:=btnTag) Else Set oControl = m_obj.CommandBars.FindControl(Tag:=btnTag) End If 'now add a button to the new menu that was created If Not (oControl Is Nothing) Then Set m_ocontrolbar = oControl strTag = "This string is unique to this button" & strKey strToolTip = "The ToolTip for the button" strCaption = "testing123" 'create the button here Set ctlbtnpriv = oStandardBar.Controls.Add(Type:=msoControlButton, Temporary:=True) With ctlbtnpriv .Caption = strCaption .Tag = btnTag .ToolTipText = strToolTip .Style = msoButtonCaption .Visible = True End With End If ' End If Set oControl = Nothing End Sub '-------------------------------------------------------------------------- Private Sub m_objInsp_Activate() On Error Resume Next Call CreateButton(m_objInsp) End Sub Please , I really need your help.Thanks Ken Slovak - [MVP - Outlook] wrote: Your Activate() handler is calling to createmenu(), not to CreateButton(). It looks to me like at that call the reference to m_obj will be null (Nothing) since nothing has initialized that object. You also need to set up a Boolean flag that gets set to True when you have created the UI and check that flag in Activate() so you don't end up creating new UI each time Activate() fires. You only want to do that once. You also should step your code and observe the state of Err and your objects as you create your UI so you know what's happening. Hey Ken , Thank you so much for replying to my query.Thanks alot.I have made [quoted text clipped - 360 lines] Thank you -- Message posted via OfficeKB.com http://www.officekb.com/Uwe/Forums.a...ddins/200808/1 |
#6
|
|||
|
|||
![]()
At module level in the Inspector wrapper:
Dim blnMenuExists As Boolean In Activate(): If Not blnMenuExists Then InitButton blnMenuExists = True End If That calls InitButton only once, which then calls CreateMenu. You needed no changes to CreateMenu. -- Ken Slovak [MVP - Outlook] http://www.slovaktech.com Author: Professional Programming Outlook 2007. Reminder Manager, Extended Reminders, Attachment Options. http://www.slovaktech.com/products.htm "amanat via OfficeKB.com" u45636@uwe wrote in message news:890de7c6ecfad@uwe... Hey Ken , Thanks for quick reply, Can you please guide me in detail as to what should I do once again , I did folling changes in create menu : Private Sub createmenu() Dim oControl As office.CommandBarControl Dim m_ocontrolbar As CommandBarControl Dim strMenu As String Dim strTag As String Dim strToolTip As String Dim strCaption As String Dim strKey As String Dim blnMenuExists As Boolean Dim oCommandBar As office.CommandBar Dim oStandardBar As office.CommandBar On Error Resume Next strKey = CStr(m_intID) mnuTag = "This string is unique to this menu" & strKey strMenu = "Menu Bar" strToolTip = "The ToolTip for the menu" strCaption = "The caption for the menu" 'check for the menu existing already and do not create ' it if does exist. The checking code would set a ' Boolean variable named blnMenuExists. If Not blnMenuExists Then Set oControl = m_obj.CommandBars.FindControl(Tag:=btnTag) Else Set oControl = m_obj.CommandBars.FindControl(Tag:=btnTag) End If 'now add a button to the new menu that was created If Not (oControl Is Nothing) Then Set m_ocontrolbar = oControl strTag = "This string is unique to this button" & strKey strToolTip = "The ToolTip for the button" strCaption = "testing123" 'create the button here Set ctlbtnpriv = oStandardBar.Controls.Add(Type:=msoControlButton, Temporary:=True) With ctlbtnpriv Caption = strCaption Tag = btnTag ToolTipText = strToolTip Style = msoButtonCaption Visible = True End With End If ' End If Set oControl = Nothing End Sub '-------------------------------------------------------------------------- Private Sub m_objInsp_Activate() On Error Resume Next Call CreateButton(m_objInsp) End Sub Please , I really need your help.Thanks |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Thread Starter | Forum | Replies | Last Post |
Inspector wrapper and Inspector close not fireing | [email protected] | Add-ins for Outlook | 1 | June 20th 08 02:53 PM |
Inspector Wrapper | goran | Add-ins for Outlook | 15 | February 4th 08 11:42 AM |
Inspector Wrapper utlook 2000 | jim | Add-ins for Outlook | 5 | February 17th 06 11:12 PM |
Command button not working on read page | jbtempe | Outlook - Using Forms | 2 | January 14th 06 12:25 AM |