Основы офисного программирования и язык VBA


Пример 11.1


Option Explicit

Public Sub CreateCustomMenu() Dim CstmBar As CommandBar Dim CstmPopUp1 As CommandBarPopup, CstmPopUp2 As CommandBarPopup Dim CstmCtrl As CommandBarControl Dim Exist As Boolean 'Выключаем все панели For Each CstmBar In CommandBars CstmBar.Enabled = False Next CstmBar

'Создаем, включаем и делаем видимой собственную панель Exist = False For Each CstmBar In CommandBars If CstmBar.Name = "Головное меню" Then Exist = True Exit For End If Next CstmBar If Not Exist Then Set CstmBar = CommandBars.Add(Name:="Головное меню", _ Position:=msoBarTop, MenuBar:=True, Temporary:=False) End If CstmBar.Enabled = True CstmBar.Visible = True

'Добавляем меню на панель Exist = False For Each CstmCtrl In CstmBar.Controls If CstmCtrl.Caption = "&Ввод документов" Then Exist = True Exit For End If Next CstmCtrl If Not Exist Then Set CstmCtrl = CstmBar.Controls _ .Add(Type:=msoControlPopup, Before:=1) CstmCtrl.Caption = "&Ввод документов" 'Добавляем две команды подменю Set CstmPopUp1 = CstmCtrl.Controls.Add(Type:=msoControlPopup) CstmPopUp1.Caption = " о движении товаров"

Set CstmPopUp2 = CstmCtrl.Controls.Add(Type:=msoControlPopup) CstmPopUp2.Caption = " финансовых"

'Добавляем команду в каждое подменю Set CstmCtrl = CstmPopUp1.Controls.Add(Type:=msoControlButton) CstmCtrl.Caption = "Накладная" CstmCtrl.OnAction = "Module1.Invoice"

Set CstmCtrl = CstmPopUp2.Controls.Add(Type:=msoControlButton) CstmCtrl.Caption = "Счет" CstmCtrl.OnAction = "Module1.Account" End If

End Sub

Пример 11.1.

Закрыть окно






Начало  Назад  Вперед



Книжный магазин