H
he
Hello,
Outlook 2003,
IDE: MS VS 2005,
Prg.Language: VB.Net
I've created an Outlook Add-In with VS 2005 which adds a button to a custom
command bar in the mailitem inspector. I'm using the following code:
Dim WithEvents btnZeitStempel As CommandBarButton
Dim WithEvents myOLInspectors As Outlook.Inspectors
Public Sub OnConnection(.....)
applicationObject = application
addInInstance = addInInst
Dim oapps As Outlook.Application = CType(applicationObject,
Outlook.Application)
myOLInspectors = oapps.Inspectors
......' Call OnStartupComplete...... vs.
End Sub
Private Sub myOLInspectors_NewInspector(ByVal Inspector As
Microsoft.Office.Interop.Outlook.Inspector) Handles
myOLInspectors.NewInspector
Dim objMailItem As MailItem = CType(Inspector.CurrentItem, MailItem)
Select Case objMailItem.MessageClass
Case "IPM.Note"
if btnShowChecked = True
ShowZeitStempel(Inspector, True) 'Show Button
Else
ShowZeitStempel(Inspector, False) 'Delete only Button
End If
End Select
End Sub
Private Sub ShowZeitStempel(ByVal Inspector As
Microsoft.Office.Interop.Outlook.Inspector, ByVal show As Boolean)
Dim commandBar As CommandBar = Nothing
If show Then
If Toolbars.IsCommandBarExist(Inspector, "fat") = False Then
If commandBar Is Nothing Then
commandBar = Inspector.CommandBars.Add("fat",
MsoBarPosition.msoBarTop, False)
btnZeitStempel =
Toolbars.CreateCommandBarButton(commandBar)
commandBar.Visible = True
End If
Else
commandBar = Inspector.CommandBars("fat")
If Toolbars.IsCommandBarButtonExist(commandBar, "btn") Then
commandBar.Controls("btn").Delete()
btnZeitStempel =
Toolbars.CreateCommandBarButton(commandBar)
commandBar.Visible = True
Else
btnZeitStempel =
Toolbars.CreateCommandBarButton(commandBar, Inspector)
commandBar.Visible = True
End If
End If
Else '---->Delete Only Button and show only my "fat" CommandBar
......
..........
end if
End Sub
Private Sub btnZeitStempel_Click(ByVal Ctrl As
Microsoft.Office.Core.CommandBarButton, ByRef CancelDefault As Boolean)
Handles btnZeitStempel.Click
MsgBox("Button Clicked...")
End Sub
-----------------------
The command bar itself is created with flag 'temporary = false'.
Right after creation the button does work perfectly. The second or third
time I open up Outlook the button is still there but does not work at all, I
can click it without any code being executed, the button forgets the function
to call we previously assigned (see code above).
I've tried deleting and recreating the button on the command bar. When
opening an inspector all command bars (default and my custom bar) are present
and can be enumerated and accessed in my code, but on my custom command bar
there is no button available at this time (controls.count = 0). Therefore I
can't delete and recreate the button. When the inspector window finally is
displayed, my button is visible, though controls.count was 0 a few moments
ago. And it's not working when clicked.
Any ideas on how to create a command bar button that doesn't loses it's
functionality after closing Outlook?
Thanks, Regards
Outlook 2003,
IDE: MS VS 2005,
Prg.Language: VB.Net
I've created an Outlook Add-In with VS 2005 which adds a button to a custom
command bar in the mailitem inspector. I'm using the following code:
Dim WithEvents btnZeitStempel As CommandBarButton
Dim WithEvents myOLInspectors As Outlook.Inspectors
Public Sub OnConnection(.....)
applicationObject = application
addInInstance = addInInst
Dim oapps As Outlook.Application = CType(applicationObject,
Outlook.Application)
myOLInspectors = oapps.Inspectors
......' Call OnStartupComplete...... vs.
End Sub
Private Sub myOLInspectors_NewInspector(ByVal Inspector As
Microsoft.Office.Interop.Outlook.Inspector) Handles
myOLInspectors.NewInspector
Dim objMailItem As MailItem = CType(Inspector.CurrentItem, MailItem)
Select Case objMailItem.MessageClass
Case "IPM.Note"
if btnShowChecked = True
ShowZeitStempel(Inspector, True) 'Show Button
Else
ShowZeitStempel(Inspector, False) 'Delete only Button
End If
End Select
End Sub
Private Sub ShowZeitStempel(ByVal Inspector As
Microsoft.Office.Interop.Outlook.Inspector, ByVal show As Boolean)
Dim commandBar As CommandBar = Nothing
If show Then
If Toolbars.IsCommandBarExist(Inspector, "fat") = False Then
If commandBar Is Nothing Then
commandBar = Inspector.CommandBars.Add("fat",
MsoBarPosition.msoBarTop, False)
btnZeitStempel =
Toolbars.CreateCommandBarButton(commandBar)
commandBar.Visible = True
End If
Else
commandBar = Inspector.CommandBars("fat")
If Toolbars.IsCommandBarButtonExist(commandBar, "btn") Then
commandBar.Controls("btn").Delete()
btnZeitStempel =
Toolbars.CreateCommandBarButton(commandBar)
commandBar.Visible = True
Else
btnZeitStempel =
Toolbars.CreateCommandBarButton(commandBar, Inspector)
commandBar.Visible = True
End If
End If
Else '---->Delete Only Button and show only my "fat" CommandBar
......
..........
end if
End Sub
Private Sub btnZeitStempel_Click(ByVal Ctrl As
Microsoft.Office.Core.CommandBarButton, ByRef CancelDefault As Boolean)
Handles btnZeitStempel.Click
MsgBox("Button Clicked...")
End Sub
-----------------------
The command bar itself is created with flag 'temporary = false'.
Right after creation the button does work perfectly. The second or third
time I open up Outlook the button is still there but does not work at all, I
can click it without any code being executed, the button forgets the function
to call we previously assigned (see code above).
I've tried deleting and recreating the button on the command bar. When
opening an inspector all command bars (default and my custom bar) are present
and can be enumerated and accessed in my code, but on my custom command bar
there is no button available at this time (controls.count = 0). Therefore I
can't delete and recreate the button. When the inspector window finally is
displayed, my button is visible, though controls.count was 0 a few moments
ago. And it's not working when clicked.
Any ideas on how to create a command bar button that doesn't loses it's
functionality after closing Outlook?
Thanks, Regards