A Microsoft Outlook email forum. Outlook Banter

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.

Go Back   Home » Outlook Banter forum » Microsoft Outlook Email Newsgroups » Outlook and VBA
Site Map Home Register Authors List Search Today's Posts Mark Forums Read Web Partners

Multiplying Inspector Toolbar in Mail Item



 
 
Thread Tools Search this Thread Display Modes
  #1  
Old December 29th 06, 03:31 PM posted to microsoft.public.outlook.program_vba
Irene
external usenet poster
 
Posts: 10
Default Multiplying Inspector Toolbar in Mail Item

Outlook 2003.
Windows XP and Word as my email editor

Hi,


I found this code on the internet which I have been playing around with. My
goal is to create two toolbars. One to show when you open a contact item and
another to show when you open, create and mail item. The contact Toolbar is
working perfect. It creates one when you open a contact item and deletes it
when you close.

However the Mail item is keeping multiplying itself every time I create a
new mail item. And it shows up in Word.This only happens when I create an new
item, not when I open an existing. Below is my code
-------------------------------------------------------------------------------------------
Class Module

Private WithEvents m_oInspector As Outlook.Inspector
Private WithEvents m_oMailItem As Outlook.MailItem
Private WithEvents m_oContactItem As Outlook.ContactItem


Private WithEvents ctlCBarControlF As Office.CommandBarButton
Private WithEvents ctlCBarControlM As Office.CommandBarButton
Private WithEvents ctlCBarControlT As Office.CommandBarButton
Private WithEvents ctlCBarControlL As Office.CommandBarButton

Private WithEvents ctlCBarControlSave As Office.CommandBarButton
Private WithEvents ctlCBarControlCategory As Office.CommandBarButton


Private m_lKey As Long




Friend Function Init(oInspector As Outlook.Inspector, ByVal lKey As Long) As
Boolean
Set m_oInspector = oInspector

Select Case True


Case (TypeOf oInspector.CurrentItem Is Outlook.ContactItem)
Set m_oContactItem = oInspector.CurrentItem
m_lKey = lKey
CreateButton oInspector
Init = True

Case (TypeOf oInspector.CurrentItem Is Outlook.MailItem)
Set m_oMailItem = oInspector.CurrentItem
m_lKey = lKey
MailCreateButton oInspector
Init = True
End Select
End Function




Private Sub MailCreateButton(Inspector As Outlook.Inspector)
Set colCB = Inspector.CommandBars
Dim cbEmail As Office.CommandBar
Dim ctlCBarButton As Office.CommandBarButton
Dim ctlCBarCombo As Office.CommandBarComboBox
Dim ctlCBarPopup As Office.CommandBarPopup
On Error Resume Next
Set cbEmail = Inspector.CommandBars("Email Toolbar")
If Err = 0 Then

cbEmail.Delete

End If
Set cbEmail = Inspector.CommandBars _
.Add(Name:="Email Toolbar", Position:=msoBarTop)

Set ctlCBarPopup = cbEmail.Controls.Add(Type:=msoControlPopup)

Set ctlCBarControlSave = ctlCBarPopup.Controls.Add(Type:=msoControlButton)
ctlCBarControlSave.Caption = "Save"

Set ctlCBarControlCategory =
ctlCBarPopup.Controls.Add(Type:=msoControlButton)
ctlCBarControlCategory.Caption = "Add Category"



With ctlCBarPopup
.Caption = "BBB Email Options"
End With


cbEmail.Visible = True
Set cbEmail = Nothing



End Sub

Private Sub CreateButton(Inspector As Outlook.Inspector)





Set colCB = Inspector.CommandBars
Dim cbTesting As Office.CommandBar
Dim ctlCBarButton As Office.CommandBarButton
Dim ctlCBarCombo As Office.CommandBarComboBox
Dim ctlCBarPopup As Office.CommandBarPopup
On Error Resume Next
Set cbTesting = Inspector.CommandBars("Toolbar")
If Err = 0 Then
cbTesting.Delete

End If
Set cbTesting = Inspector.CommandBars _
.Add(Name:="Toolbar", Position:=msoBarTop)

Set ctlCBarPopup = cbTesting.Controls.Add(Type:=msoControlPopup)

'Set ctlCBarControlF = ctlCBarPopup.Controls.Add(Type:=msoControlButton)
'ctlCBarControlF.Caption = "Fax"

Set ctlCBarControlL = ctlCBarPopup.Controls.Add(Type:=msoControlButton)
ctlCBarControlL.Caption = "Letter"

'Set ctlCBarControlM = ctlCBarPopup.Controls.Add(Type:=msoControlButton)
'ctlCBarControlM.Caption = "Memo"

Set ctlCBarControlT = ctlCBarPopup.Controls.Add(Type:=msoControlButton)
ctlCBarControlT.Caption = "Transmittal"

With ctlCBarPopup
.Caption = "Correspondence"
End With


cbTesting.Visible = True





End Sub


Friend Sub CloseInspector()
On Error Resume Next
Application.RemoveInspector m_lKey
Set YourButton = Nothing
Set m_oMailItem = Nothing
Set m_oInspector = Nothing
End Sub


Private Sub Class_Initialize()
' In this case this method isn´t necessary but helps to _
understand what´s going on.
' Before executing this method this object doesn´t exist. _
That is, the member (variables) are unkown, no events can _
be received etc.
End Sub


Private Sub Class_Terminate()
' In this case this method isn´t necessary but helps to _
understand what´s going on.
' This method is being executed if the object is being destroyed. _
That is, after that all member are unknown again.
End Sub


' Set breakpoint (F9) at the next line
Private Sub m_oInspector_Close()


On Error Resume Next
Set cbTesting = Application.ActiveInspector.CommandBars("Toolbar")
If Err = 0 Then
cbTesting.Delete

End If



Set cbEmail = Application.ActiveInspector.CommandBars("Email Toolbar")
If Err = 0 Then
cbEmail.Delete
End If
CloseInspector
End Sub


' Set breakpoint (F9) at the next line
Private Sub m_oMailItem_Close(Cancel As Boolean)
On Error Resume Next

' If m_oMailItem.Saved Then

Set cbEmail = Application.ActiveInspector.CommandBars("Email Toolbar")
If Err = 0 Then
cbEmail.Delete
End If
CloseInspector
' End If
End Sub


' Set breakpoint (F9) at the next line
Private Sub m_oMailItem_Send(Cancel As Boolean)
On Error Resume Next


Set cbEmail = Application.ActiveInspector.CommandBars("Email Toolbar")
If Err = 0 Then
cbEmail.Delete
End If
CloseInspector
End Sub
' Set breakpoint (F9) at the next line
Private Sub m_oContactItem_Close(Cancel As Boolean)



On Error Resume Next
Set cbTesting = Application.ActiveInspector.CommandBars("Toolbar")
If Err = 0 Then
cbTesting.Delete

End If


CloseInspector

End Sub





Private Sub ctlCBarControlSave_Click(ByVal Ctrl As Office.CommandBarButton, _
CancelDefault As Boolean _
)


frmEmail.Show vbModal
'vbModeless




End Sub


Private Sub ctlCBarControlCategory_Click(ByVal Ctrl As
Office.CommandBarButton, _
CancelDefault As Boolean _
)

frmCategory.Show


End Sub

ThisOutlook Session


Private Sub Application_Startup()
On Error Resume Next
Dim objNS As NameSpace

Set m_colInspectors = Application.Inspectors
Set m_coll = New VBA.Collection


Set objNS = Nothing
End Sub

' Set breakpoint (F9) at the next line
Private Sub m_colInspectors_NewInspector(ByVal Inspector As Outlook.Inspector)
' Check the Inspector´s CurrentItem type and decide _
whether to handle that type or not.
Select Case True
Case (TypeOf Inspector.CurrentItem Is Outlook.MailItem)
AddMailItemWrapper Inspector

Case (TypeOf Inspector.CurrentItem Is Outlook.ContactItem)
'CreateButton Inspector
AddMailItemWrapper Inspector

End Select

End Sub
Private Sub AddMailItemWrapper(oInspector As Outlook.Inspector)
Dim oChild As cInspector


' Create and init a new Inspector wrapper.
Set oChild = New cInspector
If oChild.Init(oInspector, m_lNextKey) Then
m_coll.Add oChild, CStr(m_lNextKey)
m_lNextKey = m_lNextKey + 1
End If
End Sub


Public Sub RemoveInspector(ByVal lKey As Long)
On Error Resume Next
m_coll.Remove CStr(lKey)
End Sub


Ads
  #2  
Old December 29th 06, 04:07 PM posted to microsoft.public.outlook.program_vba
Ken Slovak - [MVP - Outlook]
external usenet poster
 
Posts: 5,848
Default Multiplying Inspector Toolbar in Mail Item

Word does not honor the Temporary = True argument, so you must explicitly
delete your UI when a WordMail item closes. You should check for WordMail
(Inspector.IsWordMail) and take action based on that.

If you get the WordEditor object then WordEditor.Parent is the
Word.Application object. Any UI you add to Word goes into the current
Word.CustomizationContext and is displayed whether or not
Word.Window.EnvelopeVisible = True or not. That property tells you if a
WordMail window is active (True) or a document (False).

You can handle Word events in your code by declaring the Word.Application
object you get from WordMail WithEvents. Then the WindowActivate event would
let you test and see if the current Word window is a WordMail window or not
and act appropriately to hide or show your UI as needed.

--
Ken Slovak
[MVP - Outlook]
http://www.slovaktech.com
Author: Absolute Beginner's Guide to Microsoft Office Outlook 2003
Reminder Manager, Extended Reminders, Attachment Options
http://www.slovaktech.com/products.htm


"Irene" wrote in message
...
Outlook 2003.
Windows XP and Word as my email editor

Hi,


I found this code on the internet which I have been playing around with.
My
goal is to create two toolbars. One to show when you open a contact item
and
another to show when you open, create and mail item. The contact Toolbar
is
working perfect. It creates one when you open a contact item and deletes
it
when you close.

However the Mail item is keeping multiplying itself every time I create a
new mail item. And it shows up in Word.This only happens when I create an
new
item, not when I open an existing. Below is my code
-------------------------------------------------------------------------------------------
Class Module

Private WithEvents m_oInspector As Outlook.Inspector
Private WithEvents m_oMailItem As Outlook.MailItem
Private WithEvents m_oContactItem As Outlook.ContactItem


Private WithEvents ctlCBarControlF As Office.CommandBarButton
Private WithEvents ctlCBarControlM As Office.CommandBarButton
Private WithEvents ctlCBarControlT As Office.CommandBarButton
Private WithEvents ctlCBarControlL As Office.CommandBarButton

Private WithEvents ctlCBarControlSave As Office.CommandBarButton
Private WithEvents ctlCBarControlCategory As Office.CommandBarButton


Private m_lKey As Long




Friend Function Init(oInspector As Outlook.Inspector, ByVal lKey As Long)
As
Boolean
Set m_oInspector = oInspector

Select Case True


Case (TypeOf oInspector.CurrentItem Is Outlook.ContactItem)
Set m_oContactItem = oInspector.CurrentItem
m_lKey = lKey
CreateButton oInspector
Init = True

Case (TypeOf oInspector.CurrentItem Is Outlook.MailItem)
Set m_oMailItem = oInspector.CurrentItem
m_lKey = lKey
MailCreateButton oInspector
Init = True
End Select
End Function




Private Sub MailCreateButton(Inspector As Outlook.Inspector)
Set colCB = Inspector.CommandBars
Dim cbEmail As Office.CommandBar
Dim ctlCBarButton As Office.CommandBarButton
Dim ctlCBarCombo As Office.CommandBarComboBox
Dim ctlCBarPopup As Office.CommandBarPopup
On Error Resume Next
Set cbEmail = Inspector.CommandBars("Email Toolbar")
If Err = 0 Then

cbEmail.Delete

End If
Set cbEmail = Inspector.CommandBars _
.Add(Name:="Email Toolbar", Position:=msoBarTop)

Set ctlCBarPopup = cbEmail.Controls.Add(Type:=msoControlPopup)

Set ctlCBarControlSave =
ctlCBarPopup.Controls.Add(Type:=msoControlButton)
ctlCBarControlSave.Caption = "Save"

Set ctlCBarControlCategory =
ctlCBarPopup.Controls.Add(Type:=msoControlButton)
ctlCBarControlCategory.Caption = "Add Category"



With ctlCBarPopup
.Caption = "BBB Email Options"
End With


cbEmail.Visible = True
Set cbEmail = Nothing



End Sub

Private Sub CreateButton(Inspector As Outlook.Inspector)





Set colCB = Inspector.CommandBars
Dim cbTesting As Office.CommandBar
Dim ctlCBarButton As Office.CommandBarButton
Dim ctlCBarCombo As Office.CommandBarComboBox
Dim ctlCBarPopup As Office.CommandBarPopup
On Error Resume Next
Set cbTesting = Inspector.CommandBars("Toolbar")
If Err = 0 Then
cbTesting.Delete

End If
Set cbTesting = Inspector.CommandBars _
.Add(Name:="Toolbar", Position:=msoBarTop)

Set ctlCBarPopup = cbTesting.Controls.Add(Type:=msoControlPopup)

'Set ctlCBarControlF =
ctlCBarPopup.Controls.Add(Type:=msoControlButton)
'ctlCBarControlF.Caption = "Fax"

Set ctlCBarControlL = ctlCBarPopup.Controls.Add(Type:=msoControlButton)
ctlCBarControlL.Caption = "Letter"

'Set ctlCBarControlM =
ctlCBarPopup.Controls.Add(Type:=msoControlButton)
'ctlCBarControlM.Caption = "Memo"

Set ctlCBarControlT = ctlCBarPopup.Controls.Add(Type:=msoControlButton)
ctlCBarControlT.Caption = "Transmittal"

With ctlCBarPopup
.Caption = "Correspondence"
End With


cbTesting.Visible = True





End Sub


Friend Sub CloseInspector()
On Error Resume Next
Application.RemoveInspector m_lKey
Set YourButton = Nothing
Set m_oMailItem = Nothing
Set m_oInspector = Nothing
End Sub


Private Sub Class_Initialize()
' In this case this method isn´t necessary but helps to _
understand what´s going on.
' Before executing this method this object doesn´t exist. _
That is, the member (variables) are unkown, no events can _
be received etc.
End Sub


Private Sub Class_Terminate()
' In this case this method isn´t necessary but helps to _
understand what´s going on.
' This method is being executed if the object is being destroyed. _
That is, after that all member are unknown again.
End Sub


' Set breakpoint (F9) at the next line
Private Sub m_oInspector_Close()


On Error Resume Next
Set cbTesting = Application.ActiveInspector.CommandBars("Toolbar")
If Err = 0 Then
cbTesting.Delete

End If



Set cbEmail = Application.ActiveInspector.CommandBars("Email Toolbar")
If Err = 0 Then
cbEmail.Delete
End If
CloseInspector
End Sub


' Set breakpoint (F9) at the next line
Private Sub m_oMailItem_Close(Cancel As Boolean)
On Error Resume Next

' If m_oMailItem.Saved Then

Set cbEmail = Application.ActiveInspector.CommandBars("Email Toolbar")
If Err = 0 Then
cbEmail.Delete
End If
CloseInspector
' End If
End Sub


' Set breakpoint (F9) at the next line
Private Sub m_oMailItem_Send(Cancel As Boolean)
On Error Resume Next


Set cbEmail = Application.ActiveInspector.CommandBars("Email Toolbar")
If Err = 0 Then
cbEmail.Delete
End If
CloseInspector
End Sub
' Set breakpoint (F9) at the next line
Private Sub m_oContactItem_Close(Cancel As Boolean)



On Error Resume Next
Set cbTesting = Application.ActiveInspector.CommandBars("Toolbar")
If Err = 0 Then
cbTesting.Delete

End If


CloseInspector

End Sub





Private Sub ctlCBarControlSave_Click(ByVal Ctrl As
Office.CommandBarButton, _
CancelDefault As Boolean _
)


frmEmail.Show vbModal
'vbModeless




End Sub


Private Sub ctlCBarControlCategory_Click(ByVal Ctrl As
Office.CommandBarButton, _
CancelDefault As Boolean _
)

frmCategory.Show


End Sub

ThisOutlook Session


Private Sub Application_Startup()
On Error Resume Next
Dim objNS As NameSpace

Set m_colInspectors = Application.Inspectors
Set m_coll = New VBA.Collection


Set objNS = Nothing
End Sub

' Set breakpoint (F9) at the next line
Private Sub m_colInspectors_NewInspector(ByVal Inspector As
Outlook.Inspector)
' Check the Inspector´s CurrentItem type and decide _
whether to handle that type or not.
Select Case True
Case (TypeOf Inspector.CurrentItem Is Outlook.MailItem)
AddMailItemWrapper Inspector

Case (TypeOf Inspector.CurrentItem Is Outlook.ContactItem)
'CreateButton Inspector
AddMailItemWrapper Inspector

End Select

End Sub
Private Sub AddMailItemWrapper(oInspector As Outlook.Inspector)
Dim oChild As cInspector


' Create and init a new Inspector wrapper.
Set oChild = New cInspector
If oChild.Init(oInspector, m_lNextKey) Then
m_coll.Add oChild, CStr(m_lNextKey)
m_lNextKey = m_lNextKey + 1
End If
End Sub


Public Sub RemoveInspector(ByVal lKey As Long)
On Error Resume Next
m_coll.Remove CStr(lKey)
End Sub



 




Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Inspector can't save the item tonyl Add-ins for Outlook 3 October 13th 06 10:17 AM
Inspector and adding a custom toolbar Paul Heinisch Add-ins for Outlook 7 September 5th 06 06:00 PM
add toolbar in inspector contact item Irene Outlook and VBA 1 February 24th 06 09:23 PM
Help! Inspector.Close is fired before Inspector.Activate handler finishes Sergey Anchipolevsky Add-ins for Outlook 8 February 9th 06 09:51 AM
How to find out which is the current item shown in the inspector? Michael Reukauff Add-ins for Outlook 1 January 25th 06 02:33 PM


All times are GMT +1. The time now is 01:43 AM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2022, Jelsoft Enterprises Ltd.Search Engine Friendly URLs by vBSEO 2.4.0
Copyright 2004-2022 Outlook Banter.
The comments are property of their posters.