Can't Show/Hide CommandBar in WordMail

M

Mark Wilson

I've creaqted the following macro to show or hide a CommandBar.

Sub Toggle()
Dim x As Boolean
x = Application.CommandBars("Picture").Visible
MsgBox (x)
Application.CommandBars("Picture").Visible = Not x
End Sub

When I run it in Word XP or Word 2003 it toggles the state of the Picture
CommandBar.

If I use Outlook XP or Outlook 2003 and set the e-mail editor to be Word I
can run the macro when composing a new messge and the Commandbar either shows
or disappears.

However, when I run the macro when reading a message, the CommandBar either
stays visible or hidden. The state of the CommandBar in variable "x" toggles
from TRUE to FALSE or FALSE to TRUE each time the macro is run. However, the
CommandBar does not disappear from the screen.

How do I make this work when reading an e-mail message?
 
P

Peter Huang [MSFT]

Hi

Here is a KB for your reference.
Considerations When You Use Microsoft Word as the E-Mail Editor
When you are designing an Outlook CommandBar solution for mail items, it is
important that you understand that different CommandBars are used when
Microsoft Word is set as the e-mail editor. Some key points that you must
consider when you use Word as the e-mail editor are:
- CommandBars are part of Word, not Outlook.
- Different CommandBars are available based on the message editor and
format.
- Custom buttons may disappear when you change message editor or format.
- The special Envelope CommandBar is not designed to be customized.
- There is no Inspector object for the HTML and Plain Text formats with
Office 2000 if Word is set as the e-mail editor.


201095 OL: How to Use CommandBars in Outlook Solutions
http://support.microsoft.com/?id=201095

Here is the macro(running under outlook)

'Add reference to Word Typelib
Sub Test2()
Dim ip As Inspector
Dim wdApp As Word.Application
Dim wdDoc As Word.Document
Set ip = Application.ActiveInspector
If ip.EditorType = OlEditorType.olEditorWord And ip.IsWordMail = True Then
Set wdDoc = ip.WordEditor
Set wdApp = wdDoc.Application
wdApp.CommandBars("Picture").Visible = Not
wdApp.CommandBars("Picture").Visible
End If
End Sub

Best regards,

Peter Huang
Microsoft Online Partner Support

Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.
 
M

Mark Wilson

Thanks Peter.

I'm still having a problem.

I can create your macro in Outlook under ThisOutlookSession and set the
editor to Outlook. Then, when I step through the code, it jumps over the IF
statement as expected.

However, when I set the editor to Word and try to execute the macro, its
gone and only the Word macros are listed. If I create the macro in Word (so
that I can call it from Outlook/WordMail) it fails on the statement "Dim ip
As Inspector" with a compiler error.

My goal is to be able to figure out how to Show/Hide CommandBars when
reading an Outlook message with Word set to the e-mail editor. When I have
the logic sorted out I need to convert it to C++ as part of a COM Addin.

To get the code to compile and run under Word I added a reference to the
Outlook TypeLib and modified it as follows:

Sub Toggle2()
'Add reference to Outlook Typelib
Dim ip As Outlook.Inspector
Dim wdApp As Word.Application
Dim wdDoc As Word.Document
Dim x As Boolean
Set ip = Outlook.Application.ActiveInspector
If ip.EditorType = OlEditorType.olEditorWord And ip.IsWordMail = True Then
Set wdDoc = ip.WordEditor
Set wdApp = wdDoc.Application
x = wdApp.CommandBars("Picture").Visible
MsgBox (x)
wdApp.CommandBars("Picture").Visible = Not x
End If
End Sub

However it still has the same end result!

Word Document - CommandBar Show/Hide works
Outlook WordMail Compose - CommandBar Show/Hide works
Outlook WordMail Read - CommandBar does not change state on screen
but the Boolean variable "x" changes state.

Why does this work when composing a message but not reading a message?
 
P

Peter Huang [MSFT]

Hi

Based on my research, when you use Wordmail to read RTF messages, you are
getting DocObj-style notes which means that Outlook owns the frame, and
Word is in-place activated -- but Word owns the command bar integration.
Unfortunately, there is no command bar customization available in this
scenario which is across multiple processes.

So, unfortunately, we will not be able to display the toolbar when using
Wordmail to read RTF messages.

Best regards,

Peter Huang
Microsoft Online Partner Support

Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.
 
M

Mark Wilson

Hi Peter.

I think I've found a partial solution.

This macro works for Office XP and Office 2003. It changed the state of the
CommandBar with Word when processing a Document, With Outlook WordMail when
Composing a message and with Outlook WordMail when reading an RTF message:

Sub Toggle()
Dim cbars As CommandBars
Set cbars = Application.ActiveDocument.MailEnvelope.CommandBars
x = cbars.Item("Formatting").Visible
cbars.Item("Formatting").Visible = Not x
End Sub

However, since the MailEnvelope object doesn't exist in Office 2000, I don't
have a complete solution.

I see that there is an Office.CommandBars object and a
Word.Global.CommandBars object. I've not figured out how to manipulate them
yet. Is there any way that these can be used to change the state of the
CommandBar?
 
P

Peter Huang [MSFT]

Hi

The Word.Global.CommandBars is similar with Application.CommandBars. So
that in the VBA environment, the code below will work.
Sub Test()
CommandBars ("Picture")
End Sub
Office.CommandBars seems to tell us that the commandbars COM delaration is
in the Office namespace.(mso.dll)

Also thanks for your knowledge sharing in the community.

Best regards,

Peter Huang
Microsoft Online Partner Support

Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.
 

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