cookieboy66
04-08-2008, 11:05 PM
Hi
I'm trying to create a menu bar with a series of easy buttons to active templates stored on our server. I've copied some code from a KB item on this site but can't get it to run properly. It keeps coming up with a syntax error message. I tried declaring the myButton but it still came up with the same error. Can anyone help?
Also, where can I find a list of face ids?
Sub AddMenuBar()
'The Dim statements make the rest of the code easier to create.
Dim Mybar As CommandBar
Dim cmd As CommandBarPopup
Dim i As Integer
Dim A(23) As Variant
CustomizationContext = ActiveDocument.AttachedTemplate
On Error Resume Next
'This checks if the menu already exists. If it does, it does not create a new one.
'The ampersand (&) in the name of the menu underlines the letter that follows it to give it a keyboard command (Alt-m) as many menus have. CommandBars("Menu Bar").Controls("Te&mplates").Caption = "Te&mplates"
If Not Err.Number = 0 Then
'Note that the parts of the array are ("Title of menu option","Macro to Run", FaceID for toolbar button)
A(1) = Array("Print to PDF", "PDF", 92)
A(2) = Array("Insert Header/Footer", "Header_footer", 237)
A(3) = Array("Works Instruction", "Works_Instruction", 89)
A(4) = Array("Aerco quote", "Aerco_quote", 80)
A(5) = Array("AHU quote", "AHU_quote", 98)
A(6) = Array("Air cooled chiller quote", "Air_cooled_chiller_quote", 280)
A(7) = Array("Boiler quote", "Boiler_quote", 1363)
A(8) = Array("Cooling tower quote", "Cooling_Tower_quote", 2528)
A(9) = Array("Damper/louvre quote", "Damper_louvre_quote", 2526)
A(10) = Array("Diffuser quote", "Diffuser_quote", 159)
A(11) = Array("Duct quote", "Duct_quote", 6)
A(12) = Array("Expansion tank quote", "Expansion_tank_quote", 6)
A(13) = Array("Fan quote", "Fan_quote", 6)
A(14) = Array("FCU quote", "FCU_quote", 6)
A(15) = Array("Flue quote", "Flue_quote", 6)
A(16) = Array("Heat exchanger quote", "Heat_exchanger_quote", 6)
A(17) = Array("Humidifier quote", "Humidifier_quote", 6)
A(18) = Array("Plate heat exchanger quote", "Plate_heat_exch_quote", 6)
A(19) = Array("Silencer quote", "Silencer_quote", 6)
A(20) = Array("Reheat coil quote", "Reheat_coil_quote", 6)
A(21) = Array("VAV quote", "VAV_quote", 6)
A(22) = Array("Vessel quote", "Vessel_quote", 6)
A(23) = Array("Water cooled chiller quote", "Water_cooled_chiller_quote", 6)
With CommandBars("Menu Bar").Controls
.Add(Type:=msoControlPopup, Before:=11).Caption = "Te&mplates"
End With
For i = 1 To UBound(A)
With CommandBars("Menu Bar").Controls("Te&mplates").Controls
Set myButton =.Add(Type=msoControlButton)
With myButton
.Caption = A(i)(0)
.OnAction = A(i)(1)
.FaceId = A(i)(2)
End With
End With
Next i
Else
End If
End Sub
I'm trying to create a menu bar with a series of easy buttons to active templates stored on our server. I've copied some code from a KB item on this site but can't get it to run properly. It keeps coming up with a syntax error message. I tried declaring the myButton but it still came up with the same error. Can anyone help?
Also, where can I find a list of face ids?
Sub AddMenuBar()
'The Dim statements make the rest of the code easier to create.
Dim Mybar As CommandBar
Dim cmd As CommandBarPopup
Dim i As Integer
Dim A(23) As Variant
CustomizationContext = ActiveDocument.AttachedTemplate
On Error Resume Next
'This checks if the menu already exists. If it does, it does not create a new one.
'The ampersand (&) in the name of the menu underlines the letter that follows it to give it a keyboard command (Alt-m) as many menus have. CommandBars("Menu Bar").Controls("Te&mplates").Caption = "Te&mplates"
If Not Err.Number = 0 Then
'Note that the parts of the array are ("Title of menu option","Macro to Run", FaceID for toolbar button)
A(1) = Array("Print to PDF", "PDF", 92)
A(2) = Array("Insert Header/Footer", "Header_footer", 237)
A(3) = Array("Works Instruction", "Works_Instruction", 89)
A(4) = Array("Aerco quote", "Aerco_quote", 80)
A(5) = Array("AHU quote", "AHU_quote", 98)
A(6) = Array("Air cooled chiller quote", "Air_cooled_chiller_quote", 280)
A(7) = Array("Boiler quote", "Boiler_quote", 1363)
A(8) = Array("Cooling tower quote", "Cooling_Tower_quote", 2528)
A(9) = Array("Damper/louvre quote", "Damper_louvre_quote", 2526)
A(10) = Array("Diffuser quote", "Diffuser_quote", 159)
A(11) = Array("Duct quote", "Duct_quote", 6)
A(12) = Array("Expansion tank quote", "Expansion_tank_quote", 6)
A(13) = Array("Fan quote", "Fan_quote", 6)
A(14) = Array("FCU quote", "FCU_quote", 6)
A(15) = Array("Flue quote", "Flue_quote", 6)
A(16) = Array("Heat exchanger quote", "Heat_exchanger_quote", 6)
A(17) = Array("Humidifier quote", "Humidifier_quote", 6)
A(18) = Array("Plate heat exchanger quote", "Plate_heat_exch_quote", 6)
A(19) = Array("Silencer quote", "Silencer_quote", 6)
A(20) = Array("Reheat coil quote", "Reheat_coil_quote", 6)
A(21) = Array("VAV quote", "VAV_quote", 6)
A(22) = Array("Vessel quote", "Vessel_quote", 6)
A(23) = Array("Water cooled chiller quote", "Water_cooled_chiller_quote", 6)
With CommandBars("Menu Bar").Controls
.Add(Type:=msoControlPopup, Before:=11).Caption = "Te&mplates"
End With
For i = 1 To UBound(A)
With CommandBars("Menu Bar").Controls("Te&mplates").Controls
Set myButton =.Add(Type=msoControlButton)
With myButton
.Caption = A(i)(0)
.OnAction = A(i)(1)
.FaceId = A(i)(2)
End With
End With
Next i
Else
End If
End Sub