CommandBarControl objects

B

Bob Chisholm

I'm attempting to add an item to the Tools menu in Word97 running in
Windows ME. The purpose is to provide the user a means to invoke a
special process (via VBA) on demand. The code I've tried is:

Private Sub Document_Open()
Dim lPos As Long
Dim objToolsMenu As CommandBar
Dim objToolsItem As CommandBarControl
Set objToolsMenu = Application.CommandBars("Tools")
lPos = objToolsMenu.Controls.Count
Set objToolsItem = objToolsMenu.Controls.Add(msoControlPopup, 1, ,
lPos + 1, True)
objToolsItem.Caption = "&Get Label Data"
objToolsItem.BeginGroup = True
objToolsItem.OnAction = "_Document2!GetLabelData"
End Sub

This code places the desired item on the Tools menu at the desired
location. My problem is that the "True" value for the "Temporary"
parameter in the objToolsMenu.Controls.Add ignored. After the Word
aapplication is closed, and then reinvoked with any document, the added
item in the Tools menu remains. If several documents are opened in
separate invocations of Word (with the choice of enabling macros), the
added item appears an additional time in the Tools menu for each.

How can I clear the Tools menu of these unwanted Permanent added items?
How can I get added items to be truly Temporary? Is the use of
msoControlPopup as the value of the "Type" parameter improper? I
confess having adapted the above code from successful Excel programming
wherein the "Type" parameter was msoControlButton, but this value was
unrecognized by Word.

Your expertise earnestly sought.

Bob
 
B

Bob Chisholm

Correction: The msoControlButton value in the last paragraph below is
recognized by Word. But the permanence of the added item remains.
 
P

Perry

How can I clear the Tools menu of these unwanted Permanent added items?
How can I get added items to be truly Temporary? Is the use of
msoControlPopup as the value of the "Type" parameter improper? I confess
having adapted the above code from successful Excel programming wherein the
"Type" parameter was msoControlButton, but this value was unrecognized by
Word.

The two enumerated constants msoControlPopup and msoControlButton are part
of
Office type MsoControlType, so they are accessible to Word as well.
From Word's VBE Immediate window:
? msoControlPopup
10
? msoControlButton
1

To be able to identify Word's behaviour y've reporting,
where is the code -in which commandbars are manipulated- residing?
In which template project is your code residing?

Addtly, here are a couple of articles worth reading
http://word.mvps.org/faqs/customization/WhatTemplatesStore.htm
http://msdn.microsoft.com/library/d...us/vbawd10/html/woproCustomizationContext.asp

Note:
because of the wordwrap:
2 URLs listed above...
first from "http:" thru to ".htm"
scnd from "http:" thru to ".asp"

Krgrds,
Perry

"Bob Chisholm" <[email protected]> schreef in bericht
Correction: The msoControlButton value in the last paragraph below is
recognized by Word. But the permanence of the added item remains.
Bob Chisholm wrote:
I'm attempting to add an item to the Tools menu in Word97 running in Windows
ME. The purpose is to provide the user a means to invoke a special process
(via VBA) on demand. The code I've tried is:
Private Sub Document_Open()
Dim lPos As Long
Dim objToolsMenu As CommandBar
Dim objToolsItem As CommandBarControl
Set objToolsMenu = Application.CommandBars("Tools")
lPos = objToolsMenu.Controls.Count
Set objToolsItem = objToolsMenu.Controls.Add(msoControlPopup, 1, , lPos
+ 1, True)
objToolsItem.Caption = "&Get Label Data"
objToolsItem.BeginGroup = True
objToolsItem.OnAction = "_Document2!GetLabelData"
End Sub
This code places the desired item on the Tools menu at the desired location.
My problem is that the "True" value for the "Temporary" parameter in the
objToolsMenu.Controls.Add ignored. After the Word aapplication is closed,
and then reinvoked with any document, the added item in the Tools menu
remains. If several documents are opened in separate invocations of Word
(with the choice of enabling macros), the added item appears an additional
time in the Tools menu for each.
How can I clear the Tools menu of these unwanted Permanent added items? How
can I get added items to be truly Temporary? Is the use of msoControlPopup
as the value of the "Type" parameter improper? I confess having adapted the
above code from successful Excel programming wherein the "Type" parameter
was msoControlButton, but this value was unrecognized by Word.
Your expertise earnestly sought.
Bob
 
F

fendwick

Well, Bob: we seem to have each other's problems: I wish my toolbar
would stay, and you want yours to go!

I can provide a solution to the multiple controls, at least...

I've programmed my document in VBA in this way:

Code
-------------------

:
:

Dim cbar As CommandBar, cb As CommandBar

' Add a floating toolbar
' First make sure it does not already exist!
Set cbar = Nothing: Set cb = Nothing
cnt = wddoc.CommandBars.Count
For i = cnt To 1 step -1
Set cb = wddoc.CommandBars.Item(i)
If cb.Name = BARNAME Then
Set cbar = cb
Set cb = Nothing
Exit For
End If
Next

If cbar is Nothing Then
Set cbar = wddoc.CommandBars.Add(Name:="CNACbar", Position:=msoBarFloating, _
temporary:=True)
End If
:
:

-------------------


This makes sure you aren't adding copies of objects that already exist
I do the same for CommandBarControls.

Now why 'temporary:=true' doesn't seem to work for you, I wish
knew...!

Hope that helps!

f
 

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