ageBoxIcon.Error) End Try End Sub // C# private void InitMenuBarItems(string Caption) { try { MainMenuBar = ThisApplication.CommandBars["Worksheet Menu Bar"]; MenuBarItem = MainMenuBar.Controls.Add( Office.MsoControlType.msoControlPopup, Type.Missing, Type.Missing, Type.Missing, true); MenuBarItem.Caption = Caption; } catch (Exception ex) { MessageBox.Show(ex.Message, ex.Source, MessageBoxButtons.OK, MessageBoxIcon.Error); } } 3.增加下列代码到已存在的ThisWorkbook_Open程序,这段代码调用你刚才建立的InitMenuBarItems程序。 ' Visual Basic InitMenuBarItems("&Custom Code") // C# InitMenuBarItems("&Custom Code"); 4.选择文件菜单上的保存所有文件来保存整个方案。 5.按F5运行项目,装入Excel和你的工作簿。 6.在Excel中,查看页码:[1] [2] [3] [4] [5] [6] [7] [8] [9] 第4页、共9页 |