VBA 創建菜單
![](/Images/OutliningIndicators/ContractedBlock.gif)
![](/Images/OutliningIndicators/ExpandedBlockStart.gif)
Sub CreateEPOBar()
Dim newTool As CommandBar, MenuItem, SubMenuItem
Dim i As Integer
On Error Resume Next
CommandBars("EPO Toolbar").Delete
On Error GoTo 0
Set newTool = CommandBars.Add(Name:="EPO Toolbar", Position:=msoBarTop)
newTool.Visible = True
Set MenuItem = newTool.Controls.Add(Type:=msoControlButton)
With MenuItem
.Caption = "Initial EPO"
.TooltipText = "Clear all records"
.Style = msoButtonIconAndCaption
.FaceId = 18
.OnAction = "ClearSheet"
End With
Set MenuItem = newTool.Controls.Add(Type:=msoControlPopup)
With MenuItem
.BeginGroup = True
.Caption = "File upload"
.TooltipText = "File upload"
End With
Set SubMenuItem = MenuItem.Controls.Add(Type:=msoControlButton)
With SubMenuItem
.Caption = "Excel EPO file"
.TooltipText = "Upload Excel EPO File"
.Style = msoButtonIconAndCaption
.FaceId = 263
.OnAction = "UploadExcel"
End With
Set SubMenuItem = MenuItem.Controls.Add(Type:=msoControlButton)
With SubMenuItem
.Caption = "Web links file"
.TooltipText = "Upload EPO Web links File"
.Style = msoButtonIconAndCaption
.FaceId = 610
.OnAction = "UploadWeb"
End With
Set SubMenuItem = MenuItem.Controls.Add(Type:=msoControlButton)
With SubMenuItem
.Caption = "Lead Time file"
.TooltipText = "Upload Lead Time File"
.Style = msoButtonIconAndCaption
.FaceId = 126
.OnAction = "UploadLT"
End With
Set MenuItem = newTool.Controls.Add(Type:=msoControlEdit)
With MenuItem
.Caption = "Query price"
.BeginGroup = True
.Style = msoButtonIcon
.Width = 200
.TooltipText = "Key in Dell PN and press Enter"
.OnAction = "QueryPrice"
End With
Set MenuItem = newTool.Controls.Add(Type:=msoControlPopup)
With MenuItem
.BeginGroup = True
.Caption = "Help"
.TooltipText = "Help"
End With
Set SubMenuItem = MenuItem.Controls.Add(Type:=msoControlButton)
With SubMenuItem
.Caption = "Help"
.TooltipText = "Display help topics."
.FaceId = 49
.OnAction = "EPOHelp"
End With
Set SubMenuItem = MenuItem.Controls.Add(Type:=msoControlButton)
With SubMenuItem
.Caption = "Check for data version"
.TooltipText = "Check SAP, L/T data version."
.FaceId = 141
.OnAction = "CheckDataVersion"
End With
Set SubMenuItem = MenuItem.Controls.Add(Type:=msoControlButton)
With SubMenuItem
.Caption = "Check for Upgrade"
.TooltipText = "Check for product updates."
.FaceId = 141
.OnAction = "EPOUpgrade"
End With
End Sub
thisworkbook
Private Sub Workbook_Open()
Call CreateEPOBar
End Sub