P
paresh
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 here:
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
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 here:
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