custom button does not appear if MS Word is Editor

  • Thread starter Thread starter Shiv Kotagal
  • Start date Start date
S

Shiv Kotagal

Hi,
I have a COM AddIn which creates a custom button on
inspectors holding MailItems. I used the wrapper class as
shown in the ItemCB example and it works well if MS Word
is not the Editor. If MS Word is the Editor the View-
Toolbars-> list seems to be altogether different and the
custom button is nowhere to be seen.

Please help ! deadline approaching :-( Any help will be
really appreciated.

Thanks,
Shiv Kotagal
 
Buttons added to a WordMail container must be added using code in Word.
 
Thanks Ken,
I tried doing this, but am not able to proceed. here is what i did.

1. created a designer module to connect to Word on
startup and create a global say, WordApplication which is a
Word.Application object.

2. in the newInpector event in outlook, if the editor is word, i did the
following.

Sub newINspector()
Dim mydoc as Word.document
If inspector.editortype = olEditorWord
Set mydoc = WordApplication.ActiveDocument 'this fails
Set myCommandBar = mydoc.commandbars
'
'
code to add a commandbarbutton
End If

End sub

with the above code when I open a rich text document with Word as the
editor, it tells me that mydoc cannot be initialized since no document is
open.
can you please give me a clue to proceed or direct me to some code which i
can refer to. Thanks !!

regards,
Shiv
 
The way I get the current document in the Word editor is different, see if
this helps:

Dim mydoc As Word.Document

If Inspector.IsWordMail Then
Set mydoc = Inspector.WordEditor
'whatever
 
Hi Ken, running with similar kind of problem.

I did as you mention, but could not get it working. Will appeciate
your help.

Private objCB As Office.CommandBar
Private WithEvents objCBButton As Office.CommandBarButton

Private Sub colInsp_NewInspector()
Dim mydoc As Word.Document
If Inspector.IsWordMail Then
Set mydoc = Inspector.WordEditor
Set objCB = mydoc.CommandBars("Standard")
Set objCBButton = CreateAddInCommandBarButton(strProgID, objCB,
"SMS", "SMS
Extension", "Send SMS Message", 0, True,
msoButtonIconAndCaption)
End Sub

Now CreateAddInCommandBarButton this bit of code I got it from the
"Com Addin for Outloom Template" form the www.Slipstick.com website.

It works fine when i use plain Text but not when using word as emial
editor.
Anyway, i will put the code here.

In this function when using word as editor, i still get ctlBtnAddIn as
Nothing
after the following line of code, where as when using plain Text i
have that object

Set ctlBtnAddIn = objCommandBar.Controls.Add(Type:=msoControlButton,
Parameter:=strTag)


Public Function CreateAddInCommandBarButton _
(strProgID As String, objCommandBar As CommandBar, _
strCaption As String, strTag As String, strTip As String, _
intFaceID As Integer, blnBeginGroup As Boolean, intStyle As
Integer) _
As Office.CommandBarButton

Dim ctlBtnAddIn As CommandBarButton
Dim objPicture As stdole.IPictureDisp
Dim objMask As stdole.IPictureDisp
Dim str As String


str = App.Path + "\MESSAGEmanager.bmp"
On Error Resume Next
' Test to determine if button exists on command bar.
Set ctlBtnAddIn = objCommandBar.FindControl(Tag:=strTag)
If ctlBtnAddIn Is Nothing Then
' Add new button.
Set ctlBtnAddIn =
objCommandBar.Controls.Add(Type:=msoControlButton,
Parameter:=strTag)
Set objPicture = LoadPicture(str)
Set objMask = LoadPicture(str)
With ctlBtnAddIn
.Caption = strCaption
.Tag = strTag
'for image comment these three lines
If intStyle <> msoButtonIconAndCaption Then
.FaceId = intFaceID
End If

.Style = intStyle
.Picture = objPicture
.Mask = objMask
.ToolTipText = strTip
.BeginGroup = blnBeginGroup
' Set the OnAction property with ProgID of Add-In
.OnAction = "<!" & strProgID _
& ">"
End With
End If

' Return reference to new commandbar button.
Set CreateAddInCommandBarButton = ctlBtnAddIn

End Function
 
Buttons in WordMail must be created using Word code and not Outlook code.
You'd have to put the code in an autorun macro in Word's normal.dot template
and in that code check to see if the document was an email so the button
wasn't there for normal documents.




Mita Garg said:
Hi Ken, running with similar kind of problem.

I did as you mention, but could not get it working. Will appeciate
your help.
<snip>
 
Hi Ken,

Thanks for your reply. Would you mind posting a sample, because I have
no idea how to do that. and If a create the button in a macro, how
will my Addin respond to the button click event. How am i going to
distribute( or deploy) that macro on the client machine.
 
Your Word code would have to handle the click events and somehow pass
anything that's needed to the Outlook addin. Some people have created dual
addins that have designers for both Outlook and Word and do things that way.

I don't do that type of coding and really never have bothered with buttons
on WordMail Inspectors so I can't give you more detail or any sample code.
You can try Googling to see if there are any posts that show sample code for
it or even maybe try a Word newsgroup.
 
Back
Top