Remove "TEXT" from CommandBar

S

Summer

This is what I am using to remove but in this instance it is not suitable -
it does not remove it? I use this in 2003/2007 - any help would be
appreciated to get "Style" TEXT removed from CommandBar would be
appreciated!



'If you want to remove the item from the menu, you can do it like this:

Sub RemoveDoStyles()

Dim cb As CommandBar

Dim ctl As CommandBarControl

CustomizationContext = NormalTemplate

Set cb = CommandBars("Text")



For Each ctl In cb.Controls

If ctl.Tag = "Style" Then

ctl.Delete

End If

Next

End Sub



This is the macro that puts the "Style" TEXT on the CommandBar?



Sub DoStyles()

Dim StyleCount As Integer

Dim J As Integer

Dim x As CommandBar, z As CommandBarComboBox

On Error Resume Next

StyleCount = ActiveDocument.Styles.count

Set x = CommandBars.Add("AllMyStyles", msoBarPopup)

Set z = x.Controls.Add(msoControlComboBox)

z.Caption = "Active Styles:"

For J = 1 To StyleCount

If ActiveDocument.Styles(J).InUse Then

z.AddItem ActiveDocument.Styles(J)

End If

Next J

z.Text = Selection.Style

x.ShowPopup

Selection.Style = z.List(z.ListIndex)

CommandBars("AllMyStyles").Delete

End Sub
 
T

Tony Jollans

The code that you say add the style to the commandbar actually creates a
commandbar (called AllMyStyles), displays it for a selection and then
deletes it; it doesn't do anything to the "Text" commandbar. Your code will
delete a certain control if it exists - I gather it doesn't remove what you
want it to but I don't know what you do want. Could you elaborate a little?
 
S

Summer

Sorry Tony, realised I forgot to add the how I got it on the menu

so having done the below (Add Menu) more than once (accidentally) I now need
to find a way to remove the "Style" of the Menu.



This code is designed to add a pop-up combo box on the screen--the type you
see used with Context menus. Thus, you should add it to your Context menus,
rather than calling it directly from the toolbar or in another fashion. The
following code is designed to be used a single time. It adds the appropriate
menu choice to your Context menus, and points the menu choice to the
DoStyles macro just presented. You can add the following macro, run it once,
and then delete it:

Sub AddMenuItem()

Dim x As CommandBar, y As CommandBarControl, z As CommandBarButton

For Each x In Application.CommandBars

If x.Type = msoBarTypePopup Then

For Each y In x.Controls

If InStr(1, y.Caption, "Font") Then

Set z = x.Controls.Add(Before:=y.Index + 1)

With z

.Caption = "Style"

.OnAction = "DoStyles"

End With

Exit For

End If

Next

End If

Next

End Sub

With this macro run, and the DoStyles macro in place, you should make sure
you save your Normal template by exiting Word. (This is where DoStyles is
saved, by default.) When you start Word again, you can use your new style
list in the following manner:

1. Right-click on a paragraph. This displays a Context menu.

2. Choose the Style option from the Context menu. This displays a
drop-down list of styles in use in your document. (Your DoStyles macro is
running at this point.)

3. Use the drop-down list to select a style to apply.
 
T

Tony Jollans

I'm still not sure I understand but if you have added duplicates to your
popup(s) - it would probably be as easy as anything to delete them all and
start again. Based on your creation code ...

Sub AddMenuItem()

Dim x As CommandBar, y As CommandBarControl, z As CommandBarButton

For Each x In Application.CommandBars

If x.Type = msoBarTypePopup Then

For Each y In x.Controls

If y.Caption = "Style" Then

If y.OnAction = "DoStyles" Then

y.Delete

End If

End If

Next

End If

Next

End Sub

Then rerun your creation code - once!!
 
S

Summer

What can I say, I got carried away testing a new Macro Template (what can I
say?) I forgot it was ONCE only.

Thank you Tony
 
T

Tony Jollans

Glad you're sorted now.

It might be worth changing the 'Add' procedure to guard against multiple
runs, If you put a Tag on the controls you add, you will be able to check
for them and not addd a second ..

Sub AddMenuItem()

Dim x As CommandBar, y As CommandBarControl, z As CommandBarButton

For Each x In Application.CommandBars

If x.Type = msoBarTypePopup Then

' Line below checks for your tag and moves on if found
If x.FindControl(Tag:="Something Unique") Is Nothing Then

For Each y In x.Controls

If InStr(1, y.Caption, "Font") Then

Set z = x.Controls.Add(Before:=y.Index + 1)

With z

' Line below sets a Tag on the added control
.Tag = "Something Unique"

.Caption = "Style"

.OnAction = "DoStyles"

End With

Exit For

End If

Next

' Line below just ends the If Findcontrol... above
End If

End If

Next

End Sub
 

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