بعد باید در همون Form_Load تابع CreateRibbon رو قرار بدیم
نکته باید id های کنترل ها رو به صورت const نوسته و در یک مدل قرار بدید
مثال
ublic Const IDR_CNTR_INPLACE = 6
Public Const IDD_ABOUTBOX = 100
Public Const IDP_OLE_INIT_FAILED = 100
Public Const IDP_FAILED_TO_CREATE = 102
Public Const IDR_MAINFRAME = 128
Public Const IDR_SMALLICONS = 128
و حالا این تابع CreateRibbon رو به این شکل مینویسیم
Private Sub CreateRibbon()
End Sub
بعد در همین جا
اول ریبون رو تعریف میکنیم
Dim RibbonBar As RibbonBar
Set RibbonBar = CommandBars.AddRibbonBar("The Ribbon")
RibbonBar.EnableDocking xtpFlagStretched
وبعد متغییر ها کنترل ها رو
Dim ControlFile As CommandBarPopup, ControlTheme As CommandBarPopup, ControlAbout As CommandBarControl, ControlPrint As CommandBarPopup
Dim PopupBar As CommandBar
و بعد ست کردن متغییر ( این برای منوی اصلیه ، همون منوی فایل در آفیس که روش کلیک میکنید یه منو باز میشه برای فایل جدید و save و ...)
Set ControlFile = RibbonBar.AddSystemButton()
و بعد اطلاعات منوی اصلی
ControlFile.IconId = ID_SYSTEM_ICON
ControlFile.Caption = "&AbbasSediqi"
ControlFile.Style = xtpButtonIconAndCaption
و بعد کنترل های منوی اصلی
With ControlFile.CommandBar.Controls
.Add xtpControlButton, ID_FILE_NEW, "&New"
.Add xtpControlButton, ID_FILE_OPEN, "&Open..."
.Add xtpControlButton, ID_FILE_SAVE, "&Save"
.Add xtpControlButton, ID_FILE_SAVE_AS, "Save &As..."
Set ControlPrint = .Add(xtpControlSplitButtonPopup, ID_FILE_PRINT, "&Print")
ControlPrint.BeginGroup = True
Set PopupBar = CommandBars.CreateCommandBar("CXTPRibbonSystemPopu pBarPage")
Set ControlPrint.CommandBar = PopupBar
Set Control = PopupBar.Controls.Add(xtpControlLabel, 0, "Preview and print the document")
Control.Width = 296
Control.DefaultItem = True
Control.Style = xtpButtonCaption
PopupBar.DefaultButtonStyle = xtpButtonCaptionAndDescription
PopupBar.SetIconSize 32, 32
PopupBar.ShowGripper = False
PopupBar.Controls.Add xtpControlButton, ID_FILE_PRINT, "Print Pre&view"
PopupBar.Controls.Add xtpControlButton, ID_FILE_PRINT_SETUP, "Pr&int Setup..."
PopupBar.Controls.Add xtpControlButton, ID_FILE_PRINT_PREVIEW, "Print Pre&view"
.Add xtpControlButton, ID_FILE_PREPARE, "Pr&epare"
.Add xtpControlButton, ID_FILE_SEND, "Sen&d"
.Add xtpControlButton, ID_FILE_PREPARE, "P&ublish"
.Add xtpControlButton, ID_FILE_CLOSE, "Close"
Set Control = CommandBars.CreateCommandBarControl("CXTPRibbonCon trolSystemPopupBarListCaption")
Control.Caption = "Recent Documents"
Control.BeginGroup = True
.AddControl Control
Set Control = CommandBars.CreateCommandBarControl("CXTPRibbonCon trolSystemPopupBarListItem")
Control.Caption = "Form_Form1.frm"
.AddControl Control
Set Control = CommandBars.CreateCommandBarControl("CXTPRibbonCon trolSystemPopupBarButton")
Control.Caption = "Opt&ions"
Control.Id = ID_FILE_OPTIONS
.AddControl Control
Set Control = CommandBars.CreateCommandBarControl("CXTPRibbonCon trolSystemPopupBarButton")
Control.Caption = "E&xit Sample"
Control.Id = ID_APP_EXIT
.AddControl Control
ControlFile.CommandBar.SetIconSize 32, 32
End With
و در کل به این شکل میشه
Private Sub CreateRibbon()
Dim RibbonBar As RibbonBar
Set RibbonBar = CommandBars.AddRibbonBar("The Ribbon")
RibbonBar.EnableDocking xtpFlagStretched
Dim ControlFile As CommandBarPopup, ControlTheme As CommandBarPopup, ControlAbout As CommandBarControl, ControlPrint As CommandBarPopup
Dim PopupBar As CommandBar
Set ControlFile = RibbonBar.AddSystemButton()
ControlFile.IconId = ID_SYSTEM_ICON
ControlFile.Caption = "&AbbasSediqi"
ControlFile.Style = xtpButtonIconAndCaption
With ControlFile.CommandBar.Controls
.Add xtpControlButton, ID_FILE_NEW, "&New"
.Add xtpControlButton, ID_FILE_OPEN, "&Open..."
.Add xtpControlButton, ID_FILE_SAVE, "&Save"
.Add xtpControlButton, ID_FILE_SAVE_AS, "Save &As..."
Set ControlPrint = .Add(xtpControlSplitButtonPopup, ID_FILE_PRINT, "&Print")
ControlPrint.BeginGroup = True
Set PopupBar = CommandBars.CreateCommandBar("CXTPRibbonSystemPopu pBarPage")
Set ControlPrint.CommandBar = PopupBar
Set Control = PopupBar.Controls.Add(xtpControlLabel, 0, "Preview and print the document")
Control.Width = 296
Control.DefaultItem = True
Control.Style = xtpButtonCaption
PopupBar.DefaultButtonStyle = xtpButtonCaptionAndDescription
PopupBar.SetIconSize 32, 32
PopupBar.ShowGripper = False
PopupBar.Controls.Add xtpControlButton, ID_FILE_PRINT, "Print Pre&view"
PopupBar.Controls.Add xtpControlButton, ID_FILE_PRINT_SETUP, "Pr&int Setup..."
PopupBar.Controls.Add xtpControlButton, ID_FILE_PRINT_PREVIEW, "Print Pre&view"
.Add xtpControlButton, ID_FILE_PREPARE, "Pr&epare"
.Add xtpControlButton, ID_FILE_SEND, "Sen&d"
.Add xtpControlButton, ID_FILE_PREPARE, "P&ublish"
.Add xtpControlButton, ID_FILE_CLOSE, "Close"
Set Control = CommandBars.CreateCommandBarControl("CXTPRibbonCon trolSystemPopupBarListCaption")
Control.Caption = "Recent Documents"
Control.BeginGroup = True
.AddControl Control
Set Control = CommandBars.CreateCommandBarControl("CXTPRibbonCon trolSystemPopupBarListItem")
Control.Caption = "Form_Form1.frm"
.AddControl Control
Set Control = CommandBars.CreateCommandBarControl("CXTPRibbonCon trolSystemPopupBarButton")
Control.Caption = "Opt&ions"
Control.Id = ID_FILE_OPTIONS
.AddControl Control
Set Control = CommandBars.CreateCommandBarControl("CXTPRibbonCon trolSystemPopupBarButton")
Control.Caption = "E&xit Sample"
Control.Id = ID_APP_EXIT
.AddControl Control
ControlFile.CommandBar.SetIconSize 32, 32
End With
End Sub