N
Nigel
I am trying to ceate a custom toolbar for a word document. I had used some
code for excel which creates and deletes the toolbar as the form is opened
and closed,
Questions are as follows
1. How do I get the code to run when the document is opened or closed
2. How do I assign the macros to the buttons ( I can do it in excel but not
in word)
If I step thru the code it wll create the toolbar and hide the existing bars
BUt the caption doesn't change
'===========================================
Sub Auto_Close()
Call RemoveMenubar
End Sub
'===========================================
Sub RemoveMenubar()
On Error Resume Next
Application.CommandBars(ToolBarName).Delete
On Error GoTo 0
Application.CommandBars("Standard").Visible = True
Application.CommandBars("Formatting").Visible = True
Application.CommandBars("Control Toolbox").Visible = True
Application.CommandBars("Forms").Visible = True
End Sub
'===========================================
Sub CreateMenubar()
Dim iCtr As Long
Dim MacNames As Variant
Dim CapNamess As Variant
Dim TipText As Variant
Call RemoveMenubar
MacNames = Array("CommandButton21", "CommandButton11", "Showtoolbars",
"CommandButton3_Click")
CapNamess = Array("Reset Fields in Form", "Print Registration", "Show
Toolbars", "Save Changes")
With Application.CommandBars.Add
.Name = ToolBarName
.Left = 200
.Top = 200
.Protection = msoBarNoProtection
.Visible = True
.Position = msoBarTop
For iCtr = LBound(MacNames) To UBound(MacNames)
With .Controls.Add(Type:=msoControlButton)
.OnAction = MacNames(iCtr)
.Caption = CapNamess(iCtr)
.Style = msoButtonIconAndCaption
.FaceId = 71 + iCtr
End With
Next iCtr
End With
End Sub
Sub showtoolbars()
'
' Showtoolbar Macro
' Macro recorded 1/9/2007 by Nigel Bennett
If Application.CommandBars("Standard").Visible = True Then
GoTo group2
Else
Application.CommandBars("Standard").Visible = True
Application.CommandBars("Formatting").Visible = True
Application.CommandBars("Control Toolbox").Visible = True
Application.CommandBars("Focus").Visible = True
With Application.CommandBars.ActionControl
.Caption = "Hide Toolbars"
End With
Exit Sub
End If
'
group2:
'
Application.CommandBars("Standard").Visible = False
Application.CommandBars("Formatting").Visible = False
Application.CommandBars("Control Toolbox").Visible = False
Application.CommandBars("Focus").Visible = False
With Application.CommandBars.ActionControl
.Caption = "Hide Toolbars"
End With
End Sub
code for excel which creates and deletes the toolbar as the form is opened
and closed,
Questions are as follows
1. How do I get the code to run when the document is opened or closed
2. How do I assign the macros to the buttons ( I can do it in excel but not
in word)
If I step thru the code it wll create the toolbar and hide the existing bars
BUt the caption doesn't change
'===========================================
Sub Auto_Close()
Call RemoveMenubar
End Sub
'===========================================
Sub RemoveMenubar()
On Error Resume Next
Application.CommandBars(ToolBarName).Delete
On Error GoTo 0
Application.CommandBars("Standard").Visible = True
Application.CommandBars("Formatting").Visible = True
Application.CommandBars("Control Toolbox").Visible = True
Application.CommandBars("Forms").Visible = True
End Sub
'===========================================
Sub CreateMenubar()
Dim iCtr As Long
Dim MacNames As Variant
Dim CapNamess As Variant
Dim TipText As Variant
Call RemoveMenubar
MacNames = Array("CommandButton21", "CommandButton11", "Showtoolbars",
"CommandButton3_Click")
CapNamess = Array("Reset Fields in Form", "Print Registration", "Show
Toolbars", "Save Changes")
With Application.CommandBars.Add
.Name = ToolBarName
.Left = 200
.Top = 200
.Protection = msoBarNoProtection
.Visible = True
.Position = msoBarTop
For iCtr = LBound(MacNames) To UBound(MacNames)
With .Controls.Add(Type:=msoControlButton)
.OnAction = MacNames(iCtr)
.Caption = CapNamess(iCtr)
.Style = msoButtonIconAndCaption
.FaceId = 71 + iCtr
End With
Next iCtr
End With
End Sub
Sub showtoolbars()
'
' Showtoolbar Macro
' Macro recorded 1/9/2007 by Nigel Bennett
If Application.CommandBars("Standard").Visible = True Then
GoTo group2
Else
Application.CommandBars("Standard").Visible = True
Application.CommandBars("Formatting").Visible = True
Application.CommandBars("Control Toolbox").Visible = True
Application.CommandBars("Focus").Visible = True
With Application.CommandBars.ActionControl
.Caption = "Hide Toolbars"
End With
Exit Sub
End If
'
group2:
'
Application.CommandBars("Standard").Visible = False
Application.CommandBars("Formatting").Visible = False
Application.CommandBars("Control Toolbox").Visible = False
Application.CommandBars("Focus").Visible = False
With Application.CommandBars.ActionControl
.Caption = "Hide Toolbars"
End With
End Sub