I'll answer this one. Don't make your UI permanent. That would leave it
there even if your addin isn't running or even if it's uninstalled. Always
add any UI you add as temporary.
You should be using different Explorer objects for each open Explorer in the
Explorers collection. You add an Explorer class wrapper to a collection when
a new Explorer is opened and remove it when it is closed. You do that in
Explorers.NewExplorer(). The wrapper class should declare any Explorer
events you intend to handle as well as your CommandBarButton events and
declarations for your UI and any folder events.
When you add an Explorer to your wrapper collection you then add the UI in
the first Explorer.Activate() event. For an initial Explorer you bypass
that. You hold a key value that's an index into the collection for each open
Explorer. You add that to a Tag value to get a unique Tag value for each
menu/toolbar/button. That way you can identify each one and get unique
clicks for each.
You can download a template project in VB6 that shows how to work with
wrapper classes like that from
http://www.slovaktech.com/outlook_2007_templates.htm, it is set up for
Outlook 2007 use with VB6.
--
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
"paresh" wrote in message
...
Hi, I have been facing a issue with dealing with my add-in toolbar. I want
to
make my toolbar permanent so that use can hide and reposition it
permanently(even after restarting Outlook). At the same time, I want to
support my add-in toolbar for all opened Outlook explorer.
I want to make sure that at any point of time there must be one and only
one
toolbar on any Outlook window. I have tried below methods but none worked:
1. Tried deleting toolbar on shutdown. This doesn't delete the toolbar
and
each restarting outlook adds new toolbar.
Private Sub AddinInstance_OnBeginShutdown(custom() As Variant)
MyCommandBar.Delete
End Sub
Private Sub AddinInstance_Terminate()
MyCommandBar.Delete
End Sub
2. I tried deleting toolbar on Explorer close event but didn't work.
Whenever I open Outlook folder by right clicking it and selecting "Open in
new window", it keep adding new toolbar but does't delete.
Private Sub myExpl_Close()
MyCommandBar.Delete
If out_appt.Explorers.Count 1 Then
Set myExpl = Nothing
Set myColExpl = Nothing
End If
End Sub
3. Tried checking existence of toolbar but this will not add toolbar when
I
right click on outlook folder and open in new window.
Set MyCommandBar = myExpl.CommandBars.Item(TOOLBARNAME)
If Not MyCommandBar Is Nothing Then
MsgBox "exists"
Exit Sub
End If
Could anyone please help me here. I think if I can do any of below then I
would all set he
1. Delete existing toolbar while closing explorer event
2. Check the existing of toolbar explorer wise. Though I am setting
myExpl to currently active explorer, my code always returns true for
"myExpl.CommandBars.Item(TOOLBARNAME)" whenever I open outlook folder in
new
window.
Thanks.
=== MY CODE ===
Option Explicit
Public out_appt As Outlook.Application
Public WithEvents MyButton As Office.CommandBarButton
Public MyCommandBar As Office.CommandBar
Public WithEvents myColExpl As Outlook.Explorers
Public WithEvents myExpl As Outlook.Explorer
Private Sub AddinInstance_OnConnection(ByVal Application As Object, _
ByVal ConnectMode As AddInDesignerObjects.ext_ConnectMode, _
ByVal AddInInst As Object, custom() As Variant)
Set out_appt = Application
End Sub
Private Sub AddinInstance_OnStartupComplete(custom() As Variant)
Set myColExpl = out_appt.Explorers
If out_appt.Explorers.Count 0 Then
Call CreateToolBar
End If
Exit Sub
End Sub
Private Sub myColExpl_NewExplorer(ByVal Explorer As Outlook.Explorer)
If myExpl Is Nothing Then
Set myExpl = Explorer
End If
If out_appt.Explorers.Count 0 Then
Call CreateToolBar
End If
End Sub
Private Sub myExpl_Close()
MyCommandBar.Delete
If out_appt.Explorers.Count 1 Then
Set myExpl = Nothing
Set myColExpl = Nothing
End If
End Sub
Private Sub MyButton_Click(ByVal Ctrl As Office.CommandBarButton,
CancelDefault As Boolean)
On Error Resume Next
MsgBox "button clicked"
End Sub
Private Sub CreateToolBar()
If out_appt.Explorers.Count = 0 Then
Exit Sub
End If
Set myExpl = out_appt.ActiveExplorer
Const TOOLBARNAME = "My Toolbar"
' Set MyCommandBar = myExpl.CommandBars.Item(TOOLBARNAME)
' If Not MyCommandBar Is Nothing Then
' MsgBox "exists"
' Exit Sub
' End If
'
Set MyCommandBar = myExpl.CommandBars.Add(TOOLBARNAME, msoBarTop,
False,
False)
Set MyButton = MyCommandBar.Controls.Add(msoControlButton, , "890", ,
False)
With MyButton
.Caption = "&Foo Button"
.Enabled = True
.OnAction = "!PermToolbarTesting.Connect"
.Tag = "890"
.FaceId = 362
.Style = 3
.Visible = True
End With
MyCommandBar.Visible = True
End Sub