Inspector Button

S

Steven

My com addin adds a button to the inspector window, how do
i code so that when the add in is removed by the user, the
button is too.
 
K

Ken Slovak - [MVP - Outlook]

Always declare any buttons you create as temporary and when the Inspector
closes the button shouldn't be there the next time something is opened if
your code that creates the button isn't running.
 
S

Steven

Thank you, Sue Mosher said the same. But the problem now
is that my temporary buttons are disappearing for no
reason (An intermittent bug).
See
http://www.outlookcode.com/threads.aspx?
forumid=4&messageid=4660
For more details.
Any advice on this matter would be greatly appreciated
 
K

Ken Slovak - [MVP - Outlook]

I've never seen an Inspector button not appear if things are properly coded,
assuming that Word isn't being used as the email editor. That's a whole
different thing. There's no information in that thread you pointed to so I
don't know why that would happen or how.
 
M

Mark S.

Ken,

Do you have any more information re: "That's a whole
different thing." (when Word is the default email editor)

I can't seem to get my CommandButton click event to fire
when Word is the default editor. The event works fine
when Outlook is the default email editor.

Thanks...
 
K

Ken Slovak - [MVP - Outlook]

WordMail may or may not provide a NewInspector event for you depending on
the Outlook version. In general you can expect NewInspector for Outlook 2002
and later and not for Outlook 2000. So there's no way at all to tell if an
item has been opened if you don't get NewInspector.

The email template used by Word can also vary depending on the Office
version and in general you would have to handle adding a button and
responding to its events using Word code, not Outlook code. So that would
require a Word auto-open macro in the email template or a Word addin. And of
course in that case the code there isn't part of the Outlook code.

I've had some luck in using NewInspector for Outlook 2002 and later and
adding buttons in my Outlook code when WordMail is being used, but even then
there are problems. For example, reading the State of the button is not
reliable and I've resorted to storing the current button state and changing
that Boolean as my code responds to the Click event when I'm using buttons
with a persistent click state. Another gotcha is the reference to the
button, it sometimes seems to get lost in the ozone and I've had to keep
refreshing the reference even though the Click event does fire.
 
S

Sue Mosher [MVP-Outlook]

Auto macros on Word templates don't fire when they're used with WordMail,
IIRC.
 
M

Mark S.

Thank you for the reply... I am using Office 2003. The
following are some code snippets:

' declared within class module
Private WithEvents OutlookInspectors As Outlook.Inspectors
Private WithEvents CBButton As CommandBarButton

Code I use in the NewInspector event:

On Error Resume Next
'+
' Get reference to toolbar if it exists ignoring errors.
'-
CB = Inspector.CommandBars("MyAddInBar")
If (CB Is Nothing) And (Not Inspector.CurrentItem.Sent)
Then
CB = Inspector.CommandBars.Add("MyAddInBar",
MsoBarPosition.msoBarTop, False, True)
CB.Visible = True

CBC = CB.Controls.Add
(MsoControlType.msoControlButton, , , , True)
CBC.Style = MsoButtonStyle.msoButtonIcon
CBC.OnAction = "<!" & ProgID & ">" 'MyAddin.Connect
CBC.Tag = "MyAddin"
CBC.FaceId = 2114
CBC.TooltipText = "My tool tip text"

CBButton = CBC

CBC = Nothing
End If
CB = Nothing

'Below is my click event procedure

Private Sub CBButton_Click(ByVal Ctrl As
Microsoft.Office.Core.CommandBarButton, ByRef
CancelDefault As Boolean) Handles CBButton.Click
Msgbox("button clicked")
End Sub

This code successfully installs the commandbar and button
in a new Inspector regardless of the email editor. The
only problem is that the click event is not fired when
Word is the email editor. What I get is the
message "Macro could not be found..." I know it is
looking for a macro in the containing application
(Wordmail), but shouldn't CBButton_Click be fired in the
Outlook addin?

Again, the click event is fired when using Outlook
default email editor.
 
S

Steven

No word is not the email editor. it seems to go wrong
after my function has been called. but my function could
be called any number of times before it just decides to
go wrong. All my function does is rename the email. I am
really struggling with this as my delete code is in the
disconnect and is not being called and is not causing
this. my button still seems to exist as a button IE
typename =commandBarButton, but I cannot set its
properties like visible = true as that causes an object
required error.
 
K

Ken Slovak - [MVP - Outlook]

Again, there was no usable information in that thread you pointed to on
outlookcode and you haven't shown any of your code here so I have no way to
answer you. All I can say is I've never seen what you describe in a properly
coded application. We don't even know what version of Outlook you are using
or what build of Outlook.
 
K

Ken Slovak - [MVP - Outlook]

Well, I haven't added any toolbars to a WordMail item, I just add a button
to the Standard toolbar. I do hope that your code isn't the actual code if
you are using VB 6 or VBA code. You would need Set before any object
assignment.

I call a procedure something like this to create the button in my Inspector
wrapper class in the InitButton method I added to the class and call when I
add the class to the Inspector wrapper collection.

Private Sub CreateButtons(objInspector As Outlook.Inspector, _
blnNew As Boolean)

Dim cbStd As Office.CommandBar
Dim strToolbar As String
Dim strToolTip As String
Dim strMessage As String
Dim strEntryID As String
Dim strVCID As String
Dim strKBID As String
Dim strName As String
Dim blnEnabled As Boolean
Dim strKey As String

On Error Resume Next

basOutlook.GetClipboard
If blnNew Then
Clipboard.SetData LoadResPicture(101, 0)
Else
Clipboard.SetData LoadResPicture(102, 0)
End If

strKey = CStr(m_lngID)

'Adding a button to the Standard toolbar for any Inspector
strToolbar = "Standard"
Set cbStd = objInspector.CommandBars(strToolbar)

'Do button
m_strTag = "MyButton" & strKey 'has to be unique
strMessage = "MyButton"
strToolbar = "My Button"

Set cbbMyButton = cbStd.FindControl(Tag:=m_strTag)

If Not (cbbMyButton Is Nothing) Then
MyButton.Delete
Set MyButton = Nothing
End If

If MyButton Is Nothing Then
Err.Clear
Set MyButton = cbStd.Controls.Add(Type:=msoControlButton, _
Parameter:=m_strTag, Temporary:=True)

With MyButton
.DescriptionText = strToolTip
.BeginGroup = True
.Caption = strMessage
.PasteFace 'add icon
.Tag = m_strTag
.ToolTipText = strToolTip
.Style = msoButtonIconAndCaption
'the following syntax is critical
.OnAction = "!<" & gstrProgID & ">"
.Visible = True
.Enabled = True

If m_ButtonState Then
.State = msoButtonDown
Else
.State = msoButtonUp
End If
End With
End If

Clipboard.Clear
basOutlook.RestoreClipboard

Set cbStd = Nothing
End Sub

Then my Click event handler is just a straightforward event handler.
 
M

Mark S.

Thanks! I know it takes some effort to intelligently
post an example ....

"I do hope that your code isn't the actual code if
you are using VB 6 or VBA code."

Also, I should have mentioned I was using Visual
Studio .Net as the development environment.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top