word vba打开文档自动运行加右键菜单及4个按钮,右键菜单置顶显示,按钮调用窗体

时间: 2023-11-17 22:06:35 浏览: 309
以下是一个示例代码,可以实现打开文档自动运行、添加右键菜单和按钮调用窗体的功能: ```vba Private Sub Document_Open() '文档打开时自动运行的代码 MsgBox "欢迎使用本文档!" End Sub Private Sub Document_Close() '文档关闭时自动运行的代码 MsgBox "感谢使用本文档!" End Sub Private Sub Document_New() '新建文档时自动运行的代码 MsgBox "欢迎创建新文档!" End Sub Private Sub Document_AddCommandBarButton() '添加右键菜单按钮的代码 Dim cbr As CommandBarButton Set cbr = Application.CommandBars.FindControl(, , "MyButton") If cbr Is Nothing Then Set cbr = Application.CommandBars("Text").Controls.Add(msoControlButton) With cbr .Caption = "My Button" .OnAction = "ShowForm" .Tag = "MyButton" End With End If cbr.BeginGroup = True cbr.Visible = True End Sub Private Sub ShowForm() '调用窗体的代码 Form1.Show End Sub ``` 在代码中,`Document_Open`、`Document_Close` 和 `Document_New` 分别是文档打开、关闭和新建时自动运行的代码。`Document_AddCommandBarButton` 是添加右键菜单按钮的代码,其中 `MyButton` 是按钮的标识符,`ShowForm` 是按钮点击时调用的函数。`ShowForm` 函数是调用窗体的代码,其中 `Form1` 是窗体的名称。 要使用这些功能,需要将代码复制到 Word 的 Visual Basic 编辑器中,并将窗体添加到项目中。然后,在“开发人员”选项卡中选择“宏安全性”,将安全性设置为“低”,以便能够执行宏。最后,保存文档并打开它,就可以看到右键菜单和按钮了。
阅读全文

相关推荐

application/msword
自动生成VBA窗体菜单 '*************************** '* 菜单类 * '*************************** Option Explicit Private WithEvents MenuBar_MenuItem As MSForms.Label '菜单项 Private WithEvents WorkForm As MSForms.UserForm '工作窗口 Private WithEvents MenuBar As MSForms.Image '菜单栏 Private BackMenu_BackGroud As MSForms.Image '菜单背景图片 Private BackMenu_Caption As MSForms.Label '菜单标题标签 Private Const DISTANCE As Integer = 5 '菜单与左边框距离 Private Const MENUTOP As Integer = 2 '菜单项顶点Y轴位置 Private Const MENUHEIGHT As Integer = 14 '菜单项高度 Private intIndex As Integer '索引变量 Private sAction As String '宏名称变量 Private Property Let Index(N As Byte) '指定索引属性 intIndex = N End Property Private Property Get Index() As Byte '获得陇望蜀索引属性 Index = intIndex End Property Private Property Let OnAction(sAct As String) '行为属性 sAction = sAct End Property Private Property Get OnAction() As String OnAction = sAction End Property Public Sub AddMenu(wform As MSForms.UserForm, sCaption As String, sAction As String, Optional Acc As String = vbNullString) Dim MenuLeft As Single, MenuWidth As Single '由两个标签和一个图形控件组成一个主菜单项 MenuCount = MenuCount + 1 '主菜单项总数加1 Index = MenuCount '设置索引 Set WorkForm = wform With WorkForm Set MenuBar = .FormMenuBar Set BackMenu_Caption = .Controls.Add("forms.label.1") '添加一个标签,显示菜单标题 With BackMenu_Caption .Accelerator = Acc .AutoSize = True .BackStyle = fmBackStyleTransparent .Caption = sCaption .Font = "宋体" .Font.Size = 9 .Name = "BackMenu_Caption" & MenuCount .TextAlign = fmTextAlignCenter .Top = MENUTOP + 3 .WordWrap = False .Visible = True End With If MenuCount = 1 Then MenuLeft = DISTANCE Else With .Controls("BackMenu_Caption" & MenuCount - 1) MenuLeft = .Left + .Width End With End If MenuWidth = BackMenu_Caption.Width + 10 Set BackMenu_BackGroud = .Controls.Add("forms.image.1") '添加一个image,作为背景图片 With BackMenu_BackGroud .Name = "BackMenu_BackGroud" & MenuCount .BorderStyle = fmBorderStyleNone .Move MenuLeft, MENUTOP, MenuWidth, MENUHEIGHT .BackStyle = fmBackStyleTransparent .PictureSizeMode = fmPictureSizeModeStretch BackMenu_Caption.AutoSize = False BackMenu_Caption.Left = .Left BackMenu_Caption.Width = .Width End With BackMenu_Caption.ZOrder '将标签置前 Set MenuBar_MenuItem = .Controls.Add("forms.label.1") '添加一个Label,用于触发事件 With MenuBar_MenuItem .Name = "MenuBar_MenuItem" & MenuCount .BorderStyle = fmBorderStyleNone .BackStyle = fmBackStyleTransparent With BackMenu_BackGroud MenuBar_MenuItem.Move .Left, .Top, .Width, .Height End With End With End With OnAction = sAction End Sub Private Sub MenuBar_MenuItem_MouseDown(ByVal Button As Integer, ByVal Shift As Integer, ByVal X As Single, ByVal Y As Single) If Button = 1 Then bMenuSelected = True: Menu_Select End Sub Private Sub MenuBar_Click() UnSelectLastMenu bMenuSelected = False End Sub Private Sub MenuBar_MenuItem_MouseMove(ByVal Button As Integer, ByVal Shift As Integer, ByVal X As Single, ByVal Y As Single) UnSelectLastMenu Call Menu_Select End Sub Private Sub MenuBar_MouseMove1(ByVal Button As Integer, ByVal Shift As Integer, ByVal X As Single, ByVal Y As Single) If Not bMenuSelected Then UnSelectLastMenu End Sub Private Sub WorkForm_Click() '窗体单击时 UnSelectLastMenu bMenuSelected = False End Sub Private Sub WorkForm_MouseMove(ByVal Button As Integer, ByVal Shift As Integer, ByVal X As Single, ByVal Y As Single) If Not bMenuSelected Then UnSelectLastMenu '窗体 End Sub Private Sub Menu_Select() '选择菜单 On Error Resume Next Dim Pt_Menu_RightBottom As POINTAPI, Pt_Menu_LeftTop As POINTAPI With WorkForm UnSelectLastMenu Set LastSelect_Menu = BackMenu_BackGroud With BackMenu_BackGroud .BorderStyle = fmBorderStyleSingle .BorderColor = RGB(0, 0, 128) .BackStyle = fmBackStyleOpaque If bMenuSelected = False Then WorkForm.Controls("BackMenu_BackGroud" & Index).BackColor = &HFFC0C0 Else WorkForm.Controls("BackMenu_BackGroud" & Index).BackColor = &HE0E0E0 pt.X = MenuBar_MenuItem.Left * 1.33 pt.Y = (MenuBar_MenuItem.Top + MenuBar_MenuItem.Height) * 1.33 + 3 ClientToScreen hForm, pt If OnAction "" Then Application.Run OnAction End If End If End With End With End Sub Private Sub UnSelectLastMenu() '取消上次选择 If Not LastSelect_Menu Is Nothing Then With LastSelect_Menu .Picture = LoadPicture() .BackStyle = fmBackStyleTransparent .BorderStyle = fmBorderStyleNone End With End If End Sub '********本模块结束********** '*************************** '* 菜单执行模块 * '*************************** Public Type POINTAPI X As Long Y As Long End Type Public Declare Function FindWindow Lib "user32.dll" Alias"FindWindowA"(ByVal lpClassName As String, ByVal lpWindowName As String) As Long Public Declare Function ClientToScreen Lib"user32"(ByVal hwnd As Long, lpPoint As POINTAPI) As Long Public Popup_Menu As CommandBar '指定弹出式菜单 Public LastSelect_Menu As MSForms.Image '最后选择的菜单 Public MenuCount As Integer '子菜单数量 Public hForm As Long '窗口句柄 Public intLevel As Integer '级别标识,用于设置Radio菜单(游戏菜单中:初级,中级,高级) Public bAbortEnabled As Boolean '标识放弃菜单项是否可用 Public bItemCheck As Boolean '标识音效菜单是否CheckOn Public bMenuSelected As Boolean '标识菜单是否点击 Public pt As POINTAPI '定义点 Public faceid As Integer '图标ID Public faceidselect As Integer '选择的图标 Public fistid As Integer '第一个图标号 Public lastid As Integer '最后一个图标号 Public selectrow,selectcol as integer Public Mcro(50) AS String SUB 文件() Clear_menu '清除弹出菜单上菜单项 Dim cmb As CommandBarControl AddCustomCommandBarPopup1 "打开 ", "", False, True,33,"" AddCustomCommandBarPopup1 "新建 ", "BB", False, True,18,"" AddCustomCommandBarPopup2 ("另存为 ") Set cmb = Application.CommandBars("CELL").Controls("另存为 ") AddCustomCommandBarPopup3 cmb, "OFFICE 97-2003文件 ", "DD", False, True, 3, "" Set cmb = Application.CommandBars("CELL").Controls("另存为 ") AddCustomCommandBarPopup4 cmb, "OFFICE 2007工作表 " Set cmb = Application.CommandBars("CELL").Controls("另存为 ").Controls("OFFICE 2007工作表 ") AddCustomCommandBarPopup3 cmb, "office 2007启用宏的工作表 ", "FF", False, True, 0, "" Set cmb = Application.CommandBars("CELL").Controls("另存为 ").Controls("OFFICE 2007工作表 ") AddCustomCommandBarPopup3 cmb, "OFFICE 2007工作表 ", "GG", False, True, 253, "" Popup_Menu.ShowPopup pt.X, pt.Y END SUB SUB 公式() Clear_menu '清除弹出菜单上菜单项 Dim cmb As CommandBarControl AddCustomCommandBarPopup1 "文本 ", "WB", False, True,7,"" AddCustomCommandBarPopup2 ("名称 ") Set cmb = Application.CommandBars("CELL").Controls("名称 ") AddCustomCommandBarPopup3 cmb, "定义 ", "DY", False, True, 0, "" Set cmb = Application.CommandBars("CELL").Controls("名称 ") AddCustomCommandBarPopup4 cmb, "单元格 " Set cmb = Application.CommandBars("CELL").Controls("名称 ").Controls("单元格 ") AddCustomCommandBarPopup3 cmb, "合并 ", "HB", False, True, 592, "" Set cmb = Application.CommandBars("CELL").Controls("名称 ").Controls("单元格 ") AddCustomCommandBarPopup3 cmb, "从属 ", "CS", False, True, 564, "" Popup_Menu.ShowPopup pt.X, pt.Y END SUB SUB 开发工具() Clear_menu '清除弹出菜单上菜单项 Dim cmb As CommandBarControl AddCustomCommandBarPopup1 "插入 ", "CR", False, True,548,"" AddCustomCommandBarPopup1 "模式 ", "MS", False, True,590,"" AddCustomCommandBarPopup2 ("宏 ") Set cmb = Application.CommandBars("CELL").Controls("宏 ") AddCustomCommandBarPopup3 cmb, "录制宏 ", "LZH", False, True, 205, "" Set cmb = Application.CommandBars("CELL").Controls("宏 ") AddCustomCommandBarPopup3 cmb, "安全性 ", "AQX", False, True, 279, "" Set cmb = Application.CommandBars("CELL").Controls("宏 ") AddCustomCommandBarPopup3 cmb, "查看代码 ", "CKDM", False, True, 289, "" Popup_Menu.ShowPopup pt.X, pt.Y END SUB SUB 窗口() Clear_menu '清除弹出菜单上菜单项 Dim cmb As CommandBarControl AddCustomCommandBarPopup1 "并列比较 ", "BLBJ", False, True,250,"" AddCustomCommandBarPopup1 "冻结 ", "DJ", False, True,288,"" AddCustomCommandBarPopup1 "隐藏 ", "YC", False, True,237,"" AddCustomCommandBarPopup1 "拆分 ", "CF", False, True,292,"" AddCustomCommandBarPopup1 "取消冻结 ", "QXDJ", False, True,232,"" Popup_Menu.ShowPopup pt.X, pt.Y END SUB SUB 工具() Clear_menu '清除弹出菜单上菜单项 Dim cmb As CommandBarControl AddCustomCommandBarPopup1 "拼写检查 ", "PXJC", False, True,246,"" AddCustomCommandBarPopup2 ("保护 ") Set cmb = Application.CommandBars("CELL").Controls("保护 ") AddCustomCommandBarPopup3 cmb, "保护工作表 ", "BHGZB", False, True, 277, "" Set cmb = Application.CommandBars("CELL").Controls("保护 ") AddCustomCommandBarPopup3 cmb, "保护工作薄 ", "BHGZBB", False, True, 312, "" Set cmb = Application.CommandBars("CELL").Controls("保护 ") AddCustomCommandBarPopup3 cmb, "工作表菜单栏 ", "gzbcdl", False, True, 142, "" Set cmb = Application.CommandBars("CELL").Controls("保护 ") AddCustomCommandBarPopup3 cmb, "图表菜单栏 ", "tbgjl", False, True, 164, "" Popup_Menu.ShowPopup pt.X, pt.Y END SUB SUB 常用() Clear_menu '清除弹出菜单上菜单项 Dim cmb As CommandBarControl AddCustomCommandBarPopup1 "格式 ", "gs", False, True,108,"" AddCustomCommandBarPopup1 "数据透视表 ", "sjtsb", False, True,125,"" AddCustomCommandBarPopup1 "图表 ", "tb", False, True,127,"" AddCustomCommandBarPopup1 "审阅 ", "sy", False, True,124,"" AddCustomCommandBarPopup1 "窗体 ", "ct", False, True,128,"" AddCustomCommandBarPopup1 "停止录制 ", "tzlz", False, True,185,"" AddCustomCommandBarPopup2 ("外部数据 ") Set cmb = Application.CommandBars("CELL").Controls("外部数据 ") AddCustomCommandBarPopup3 cmb, "公式审核 ", "gssh", False, True, 129, "" Set cmb = Application.CommandBars("CELL").Controls("外部数据 ") AddCustomCommandBarPopup3 cmb, "全屏显示 ", "qpxs", False, True, 130, "" Set cmb = Application.CommandBars("CELL").Controls("外部数据 ") AddCustomCommandBarPopup3 cmb, "循环引用 ", "xhye", False, True, 132, "" Set cmb = Application.CommandBars("CELL").Controls("外部数据 ") AddCustomCommandBarPopup4 cmb, "VisualBasic " Set cmb = Application.CommandBars("CELL").Controls("外部数据 ").Controls("VisualBasic ") AddCustomCommandBarPopup3 cmb, "Web ", "web", False, True, 173, "" Set cmb = Application.CommandBars("CELL").Controls("外部数据 ").Controls("VisualBasic ") AddCustomCommandBarPopup3 cmb, "控件工具箱 ", "kjgjx", False, True, 174, "" Set cmb = Application.CommandBars("CELL").Controls("外部数据 ").Controls("VisualBasic ") AddCustomCommandBarPopup3 cmb, "退出设计模式 ", "tcsjms", False, True, 162, "" Set cmb = Application.CommandBars("CELL").Controls("外部数据 ").Controls("VisualBasic ") AddCustomCommandBarPopup3 cmb, "刷新 ", "sx", False, True, 165, "" Set cmb = Application.CommandBars("CELL").Controls("外部数据 ").Controls("VisualBasic ") AddCustomCommandBarPopup3 cmb, "监视窗口 ", "jsck", False, True, 168, "" Set cmb = Application.CommandBars("CELL").Controls("外部数据 ").Controls("VisualBasic ") AddCustomCommandBarPopup3 cmb, "数据透视表字段列表 ", "sjtsbzdb", False, True, 170, "" Set cmb = Application.CommandBars("CELL").Controls("外部数据 ").Controls("VisualBasic ") AddCustomCommandBarPopup3 cmb, "边框 ", "bk", False, True, 178, "" Set cmb = Application.CommandBars("CELL").Controls("外部数据 ").Controls("VisualBasic ") AddCustomCommandBarPopup3 cmb, "保护 ", "bh", False, True, 160, "" Set cmb = Application.CommandBars("CELL").Controls("外部数据 ").Controls("VisualBasic ") AddCustomCommandBarPopup3 cmb, "文本到语音 ", "wbdyy", False, True, 164, "" Popup_Menu.ShowPopup pt.X, pt.Y END SUB SUB 列表() Clear_menu '清除弹出菜单上菜单项 Dim cmb As CommandBarControl AddCustomCommandBarPopup1 "并排比较 ", "bpbj1", False, True,180,"" AddCustomCommandBarPopup1 "绘图 ", "bpbj2", False, True,182,"" AddCustomCommandBarPopup1 "数据透视图菜单 ", "bpbj3", False, True,184,"" AddCustomCommandBarPopup2 ("工作簿标签 ") AddCustomCommandBarPopup2 ("单元格 ") Set cmb = Application.CommandBars("CELL").Controls("单元格 ") AddCustomCommandBarPopup3 cmb, "列 ", "bpbj6", False, True, 190, "" Set cmb = Application.CommandBars("CELL").Controls("单元格 ") AddCustomCommandBarPopup3 cmb, "行 ", "bpbj7", False, True, 192, "" Set cmb = Application.CommandBars("CELL").Controls("单元格 ") AddCustomCommandBarPopup3 cmb, "单元格 ", "bpbj8", False, True, 194, "" Set cmb = Application.CommandBars("CELL").Controls("单元格 ") AddCustomCommandBarPopup3 cmb, "柱形图 ", "bpbj9", False, True, 196, "" Set cmb = Application.CommandBars("CELL").Controls("单元格 ") AddCustomCommandBarPopup3 cmb, "行 ", "bpbj10", False, True, 198, "" Set cmb = Application.CommandBars("CELL").Controls("单元格 ") AddCustomCommandBarPopup4 cmb, "工作表 " Set cmb = Application.CommandBars("CELL").Controls("单元格 ").Controls("工作表 ") AddCustomCommandBarPopup3 cmb, "XLM 单元格 ", "bpbj12", False, True, 202, "" Set cmb = Application.CommandBars("CELL").Controls("单元格 ").Controls("工作表 ") AddCustomCommandBarPopup3 cmb, "文档 ", "bpbj13", False, True, 204, "" Set cmb = Application.CommandBars("CELL").Controls("单元格 ").Controls("工作表 ") AddCustomCommandBarPopup3 cmb, "桌面 ", "bpbj14", False, True, 206, "" Set cmb = Application.CommandBars("CELL").Controls("单元格 ").Controls("工作表 ") AddCustomCommandBarPopup3 cmb, "非默认拖放 ", "bpbj15", False, True, 208, "" Set cmb = Application.CommandBars("CELL").Controls("单元格 ").Controls("工作表 ") AddCustomCommandBarPopup3 cmb, "自动填充 ", "bpbj16", False, True, 210, "" Set cmb = Application.CommandBars("CELL").Controls("单元格 ").Controls("工作表 ") AddCustomCommandBarPopup3 cmb, "按钮 ", "bpbj17", False, True, 212, "" Set cmb = Application.CommandBars("CELL").Controls("单元格 ").Controls("工作表 ") AddCustomCommandBarPopup3 cmb, "对话框 ", "bpbj18", False, True, 214, "" Popup_Menu.ShowPopup pt.X, pt.Y END SUB SUB 序列() Clear_menu '清除弹出菜单上菜单项 Dim cmb As CommandBarControl AddCustomCommandBarPopup1 "图形区 ", "bpbj20", False, True,218,"" AddCustomCommandBarPopup1 "基底和墙纸 ", "bpbj21", False, True,220,"" AddCustomCommandBarPopup1 "趋势线 ", "bpbj22", False, True,222,"" AddCustomCommandBarPopup1 "图表 ", "bpbj23", False, True,224,"" AddCustomCommandBarPopup1 "设置数据系列格式 ", "bpbj24", False, True,226,"" AddCustomCommandBarPopup2 ("设置数据轴格式 ") Set cmb = Application.CommandBars("CELL").Controls("设置数据轴格式 ") AddCustomCommandBarPopup3 cmb, "设置图例项格式 ", "bpbj26", False, True, 230, "" Set cmb = Application.CommandBars("CELL").Controls("设置数据轴格式 ") AddCustomCommandBarPopup3 cmb, "编辑栏 ", "bpbj27", False, True, 232, "" Set cmb = Application.CommandBars("CELL").Controls("设置数据轴格式 ") AddCustomCommandBarPopup3 cmb, "数据透视表上下文菜单 ", "bpbj28", False, True, 234, "" Set cmb = Application.CommandBars("CELL").Controls("设置数据轴格式 ") AddCustomCommandBarPopup3 cmb, "查询 ", "bpbj29", False, True, 236, "" Set cmb = Application.CommandBars("CELL").Controls("设置数据轴格式 ") AddCustomCommandBarPopup3 cmb, "查询布局 ", "bpbj30", False, True, 238, "" Set cmb = Application.CommandBars("CELL").Controls("设置数据轴格式 ") AddCustomCommandBarPopup4 cmb, "自动计算 " Set cmb = Application.CommandBars("CELL").Controls("设置数据轴格式 ").Controls("自动计算 ") AddCustomCommandBarPopup3 cmb, "对象/图形区 ", "bpbj32", False, True, 242, "" Set cmb = Application.CommandBars("CELL").Controls("设置数据轴格式 ").Controls("自动计算 ") AddCustomCommandBarPopup3 cmb, "标题栏(图表) ", "bpbj33", False, True, 244, "" Popup_Menu.ShowPopup pt.X, pt.Y END SUB SUB 框架() Clear_menu '清除弹出菜单上菜单项 Dim cmb As CommandBarControl AddCustomCommandBarPopup1 "数据透视图快捷菜单 ", "bpbj35", False, True,248,"" AddCustomCommandBarPopup1 "拼音信息 ", "bpbj36", False, True,250,"" AddCustomCommandBarPopup1 "自动合计 ", "bpbj37", False, True,252,"" AddCustomCommandBarPopup1 "选择性粘贴下拉框 ", "bpbj38", False, True,254,"" AddCustomCommandBarPopup2 ("查找格式 ") Set cmb = Application.CommandBars("CELL").Controls("查找格式 ") AddCustomCommandBarPopup3 cmb, "替换格式 ", "bpbj40", False, True, 258, "" Set cmb = Application.CommandBars("CELL").Controls("查找格式 ") AddCustomCommandBarPopup3 cmb, "列表区域快捷菜单 ", "bpbj41", False, True, 260, "" Set cmb = Application.CommandBars("CELL").Controls("查找格式 ") AddCustomCommandBarPopup3 cmb, "列表区域布局快捷菜单 ", "bpbj42", False, True, 262, "" Set cmb = Application.CommandBars("CELL").Controls("查找格式 ") AddCustomCommandBarPopup3 cmb, "XML 区域快捷菜单 ", "bpbj43", False, True, 264, "" Set cmb = Application.CommandBars("CELL").Controls("查找格式 ") AddCustomCommandBarPopup3 cmb, "列表区域布局快捷菜单 ", "bpbj44", False, True, 266, "" Set cmb = Application.CommandBars("CELL").Controls("查找格式 ") AddCustomCommandBarPopup3 cmb, "艺术字 ", "bpbj45", False, True, 268, "" AddCustomCommandBarPopup2 ("图片 ") Set cmb = Application.CommandBars("CELL").Controls("图片 ") AddCustomCommandBarPopup3 cmb, "阴影设置 ", "bpbj47", False, True, 272, "" AddCustomCommandBarPopup2 ("三维设置 ") Set cmb = Application.CommandBars("CELL").Controls("三维设置 ") AddCustomCommandBarPopup3 cmb, "绘图画布 ", "bpbj49", False, True, 276, "" Set cmb = Application.CommandBars("CELL").Controls("三维设置 ") AddCustomCommandBarPopup3 cmb, "组织结构图 ", "bpbj50", False, True, 278, "" Set cmb = Application.CommandBars("CELL").Controls("三维设置 ") AddCustomCommandBarPopup3 cmb, "图示 ", "bpbj51", False, True, 280, "" Set cmb = Application.CommandBars("CELL").Controls("三维设置 ") AddCustomCommandBarPopup3 cmb, "墨迹绘图与书写 ", "bpbj52", False, True, 282, "" Set cmb = Application.CommandBars("CELL").Controls("三维设置 ") AddCustomCommandBarPopup3 cmb, "墨迹注释 ", "bpbj53", False, True, 284, "" AddCustomCommandBarPopup2 ("边框 ") Set cmb = Application.CommandBars("CELL").Controls("边框 ") AddCustomCommandBarPopup3 cmb, "边框 ", "bpbj55", False, True, 288, "" Set cmb = Application.CommandBars("CELL").Controls("边框 ") AddCustomCommandBarPopup4 cmb, "绘图边框 " Set cmb = Application.CommandBars("CELL").Controls("边框 ").Controls("绘图边框 ") AddCustomCommandBarPopup3 cmb, "图表类型 ", "bpbj57", False, True, 292, "" Set cmb = Application.CommandBars("CELL").Controls("边框 ").Controls("绘图边框 ") AddCustomCommandBarPopup3 cmb, "图案 ", "bpbj58", False, True, 294, "" Set cmb = Application.CommandBars("CELL").Controls("边框 ").Controls("绘图边框 ") AddCustomCommandBarPopup3 cmb, "字体颜色 ", "bpbj59", False, True, 296, "" Popup_Menu.ShowPopup pt.X, pt.Y END SUB SUB 填充颜色() Clear_menu '清除弹出菜单上菜单项 Dim cmb As CommandBarControl AddCustomCommandBarPopup1 "线条颜色 ", "bpbj61", False, True,300,"" AddCustomCommandBarPopup2 ("绘图与书写笔 ") Set cmb = Application.CommandBars("CELL").Controls("绘图与书写笔 ") AddCustomCommandBarPopup3 cmb, "批注笔 ", "bpbj63", False, True, 304, "" Set cmb = Application.CommandBars("CELL").Controls("绘图与书写笔 ") AddCustomCommandBarPopup3 cmb, "绘图和书写笔 ", "bpbj64", False, True, 306, "" Set cmb = Application.CommandBars("CELL").Controls("绘图与书写笔 ") AddCustomCommandBarPopup3 cmb, "注释笔 ", "bpbj65", False, True, 308, "" Set cmb = Application.CommandBars("CELL").Controls("绘图与书写笔 ") AddCustomCommandBarPopup3 cmb, "叠放次序 ", "bpbj66", False, True, 310, "" Set cmb = Application.CommandBars("CELL").Controls("绘图与书写笔 ") AddCustomCommandBarPopup3 cmb, "微移 ", "bpbj67", False, True, 312, "" Set cmb = Application.CommandBars("CELL").Controls("绘图与书写笔 ") AddCustomCommandBarPopup3 cmb, "对齐或分布 ", "bpbj68", False, True, 314, "" AddCustomCommandBarPopup2 ("旋转或翻转 ") Set cmb = Application.CommandBars("CELL").Controls("旋转或翻转 ") AddCustomCommandBarPopup3 cmb, "直线 ", "bpbj70", False, True, 318, "" Set cmb = Application.CommandBars("CELL").Controls("旋转或翻转 ") AddCustomCommandBarPopup4 cmb, "连接符 " Set cmb = Application.CommandBars("CELL").Controls("旋转或翻转 ").Controls("连接符 ") AddCustomCommandBarPopup3 cmb, "自选图形 ", "bpbj72", False, True, 322, "" Set cmb = Application.CommandBars("CELL").Controls("旋转或翻转 ").Controls("连接符 ") AddCustomCommandBarPopup3 cmb, "标注 ", "bpbj73", False, True, 324, "" Popup_Menu.ShowPopup pt.X, pt.Y END SUB SUB 流程图() Clear_menu '清除弹出菜单上菜单项 Dim cmb As CommandBarControl AddCustomCommandBarPopup1 "箭头总汇 ", "bpbj75", False, True,328,"" AddCustomCommandBarPopup1 "星与旗帜 ", "bpbj76", False, True,330,"" AddCustomCommandBarPopup1 "基本形状 ", "bpbj77", False, True,332,"" AddCustomCommandBarPopup1 "插入形状 ", "bpbj78", False, True,334,"" AddCustomCommandBarPopup2 ("形状 ") Set cmb = Application.CommandBars("CELL").Controls("形状 ") AddCustomCommandBarPopup3 cmb, "非活动图表 ", "bpbj80", False, True, 338, "" Set cmb = Application.CommandBars("CELL").Controls("形状 ") AddCustomCommandBarPopup3 cmb, "Excel 控件 ", "bpbj81", False, True, 340, "" AddCustomCommandBarPopup1 "曲线 ", "bpbj82", False, True,342,"" AddCustomCommandBarPopup1 "曲线结点 ", "bpbj83", False, True,344,"" AddCustomCommandBarPopup1 "曲线段 ", "bpbj84", False, True,346,"" AddCustomCommandBarPopup1 "图片上下文菜单 ", "bpbj85", False, True,348,"" Popup_Menu.ShowPopup pt.X, pt.Y END SUB SUB OLE对象() Clear_menu '清除弹出菜单上菜单项 Dim cmb As CommandBarControl AddCustomCommandBarPopup1 "ActiveX 控件 ", "bpbj87", False, True,352,"" AddCustomCommandBarPopup1 "艺术字上下文菜单 ", "bpbj88", False, True,354,"" AddCustomCommandBarPopup1 "旋转方式 ", "bpbj89", False, True,356,"" AddCustomCommandBarPopup1 "连接符 ", "bpbj90", False, True,358,"" AddCustomCommandBarPopup1 "脚本标记快捷菜单 ", "bpbj91", False, True,360,"" AddCustomCommandBarPopup1 "Canvas Popup ", "bpbj92", False, True,362,"" AddCustomCommandBarPopup1 "Organization Chart Popup ", "bpbj93", False, True,364,"" AddCustomCommandBarPopup2 ("图表 ") Set cmb = Application.CommandBars("CELL").Controls("图表 ") AddCustomCommandBarPopup3 cmb, "选择 ", "bpbj95", False, True, 368, "" Set cmb = Application.CommandBars("CELL").Controls("图表 ") AddCustomCommandBarPopup4 cmb, "版式 " Set cmb = Application.CommandBars("CELL").Controls("图表 ").Controls("版式 ") AddCustomCommandBarPopup3 cmb, "符号栏 ", "bpbj97", False, True, 372, "" Set cmb = Application.CommandBars("CELL").Controls("图表 ").Controls("版式 ") AddCustomCommandBarPopup3 cmb, "任务窗格 ", "bpbj98", False, True, 374, "" Popup_Menu.ShowPopup pt.X, pt.Y END SUB SUB 添加命令() Clear_menu '清除弹出菜单上菜单项 Dim cmb As CommandBarControl AddCustomCommandBarPopup1 "内置菜单 ", "bpbj100", False, True,378,"" AddCustomCommandBarPopup1 "剪贴板 ", "bpbj101", False, True,380,"" AddCustomCommandBarPopup1 "信封 ", "bpbj102", False, True,382,"" AddCustomCommandBarPopup1 "联机会议 ", "bpbj103", False, True,384,"" AddCustomCommandBarPopup1 "SnagIt ", "bpbj104", False, True,386,"" Popup_Menu.ShowPopup pt.X, pt.Y END SUB SUB 关于() Clear_menu '清除弹出菜单上菜单项 Dim cmb As CommandBarControl AddCustomCommandBarPopup1 "我的VBA ", "WDVBA", False, True,400,"" AddCustomCommandBarPopup1 "帮助 ", "BZ", False, True,402,"" Popup_Menu.ShowPopup pt.X, pt.Y END SUB Public Sub ClearBar() '清除Cell弹出式菜单中菜单项 Dim ctr As CommandBarControl With Popup_Menu .Enabled = True For Each ctr In .Controls ctr.Delete Next End With End Sub Sub RemoveCustomMenu() '恢复系统菜单的各弹出菜单 Application.CommandBars("CELL").Reset End Sub Sub clear_menu() Dim cmb As Object For Each cmb In Application.CommandBars("cell").Controls Application.CommandBars("cell").Controls(cmb.Caption).Delete Next End Sub Sub AddCustomCommandBarPopup1(Caption As String, Macro As String, NewGroup As Boolean, Enable As Boolean, FId As Integer, ShortT As String) '添加一级菜单选项 Dim cbb As CommandBarButton Set cbb = Application.CommandBars("CELL").Controls.Add(msoControlButton) cbb.Caption = Caption If FId > 0 Then cbb.faceid = FId If ShortT "" Then cbb.ShortcutText = ShortT cbb.OnAction = Macro cbb.BeginGroup = NewGroup cbb.Enabled = Enable End Sub Function AddCustomCommandBarPopup2(Caption As String) As CommandBarControl '添加子菜单项 Dim cmb As CommandBarControl Set cmb = Application.CommandBars("CELL").Controls.Add(msoControlPopup) cmb.Caption = Caption cmb.Visible = True Set AddCustomCommandBarPopup2 = cmb End Function Sub AddCustomCommandBarPopup3(cmb As Object, Caption As String, Macro As String, NewGroup As Boolean, Enable As Boolean, FId As Integer, ShortT As String) '添加一级菜单选项 Dim cbc As CommandBarButton Set cbc = cmb.Controls.Add(msoControlButton) cbc.Caption = Caption If FId > 0 Then cbc.faceid = FId If ShortT "" Then cbc.ShortcutText = ShortT cbc.OnAction = Macro cbc.BeginGroup = NewGroup cbc.Enabled = Enable End Sub Function AddCustomCommandBarPopup4(cmd As CommandBarControl, Caption As String) As CommandBarControl '添加子菜单项 Dim cme As CommandBarControl Set cme = cmd.Controls.Add(msoControlPopup) cme.Caption = Caption cme.Visible = True Set AddCustomCommandBarPopup4 = cme End Function '********本模块结束********** '*************************** '* 窗口模块 * '*************************** Private menu(1 To 50) As New Menu_Class '定义50个cMenu菜单类型 Private Sub UserForm_Initialize() hForm = FindWindow(vbNullString, Me.Caption) '程序中需要用到窗口句柄,先获得它 MenuCount = 0 Set Popup_Menu = Application.CommandBars("Cell") '程序中需指定一个弹出式菜单,我们指定为单元格右键菜单,您可另外指定一个弹出式菜单,请注意,是弹出式菜单 Dim bar As Control Set bar = Me.Controls.Add("Forms.image.1", "IM1", Visible) With bar .Visible = True .Left = -100 .Top = 0 .Height = 20 .Width = 20 .BackColor = &HFFC0C0 .BorderStyle = 0 End With '*************** Set bar = Me.Controls.Add("Forms.image.1", "IM2", Visible) With bar .Visible = True .Left = -100 .Top = 0 .Height = 20 .Width = 20 .BackColor = &HFFC0C0 .BorderStyle = 0 End With '*************** Set bar = Me.Controls.Add("Forms.image.1", "FormMenuBar", Visible) With bar .Visible = True .Left = -1 .Top = -1 .Height = 20 .Width = 2000 .BackColor = &HFFC0C0 .BorderStyle = 0 End With menu(1).AddMenu Me,"文件","文件","" menu(2).AddMenu Me,"公式","公式","" menu(3).AddMenu Me,"开发工具","开发工具","" menu(4).AddMenu Me,"窗口","窗口","" menu(5).AddMenu Me,"工具","工具","" menu(6).AddMenu Me,"常用","常用","" menu(7).AddMenu Me,"列表","列表","" menu(8).AddMenu Me,"序列","序列","" menu(9).AddMenu Me,"框架","框架","" menu(10).AddMenu Me,"填充颜色","填充颜色","" menu(11).AddMenu Me,"流程图","流程图","" menu(12).AddMenu Me,"OLE对象","OLE对象","" menu(13).AddMenu Me,"添加命令","添加命令","" menu(14).AddMenu Me,"关于","关于","" end sub Private Sub UserForm_QueryClose(Cancel As Integer, CloseMode As Integer) Dim i As Integer For i = LBound(menu) To UBound(menu) Set menu(i) = Nothing Next Popup_Menu.Enabled = True Popup_Menu.Reset end sub '********本模块结束**********

最新推荐

recommend-type

VBA实现word邮件合并打印并调用系统打印机窗口

在这个特定的VBA脚本中,它主要用于实现Word文档的邮件合并功能,结合数据库数据进行打印,并控制打印机窗口的交互。下面我们将深入探讨这个脚本的关键部分及其涉及的知识点。 首先,`Sub shuaxin(control As ...
recommend-type

word VBA邮件合并及批量生成单个文档

Word VBA 邮件合并及批量生成单个文档 Word VBA 是一种强大的工具,结合邮件合并功能,可以实现批量生成文档。在这个例子中,我们将使用 Word VBA 实现批量生成申请表,并将其分割成独立的文档,每个文档的名字命名...
recommend-type

Word文档批量替换工具.doc

由VBA(Visual Basic for Applications)编程语言实现,该工具允许用户在Excel表格中预先设定需要查找和替换的文本,然后一次性对多个Word文档进行批量替换操作,大大提升了工作效率。 首先,批量替换功能的适用...
recommend-type

EXCEL VBA 控件常规使用——窗体控件介绍

EXCEL VBA 控件常规使用——窗体控件介绍 在 Excel VBA 中,控件是指在 UserForm 中使用的各种对象,例如按钮、文本框、列表框等。这些控件可以在 UserForm 中进行布局和设计,以便在实际应用中使用。本文将介绍 ...
recommend-type

Word文档内容页眉页脚批量替换工具.doc

在VBA中,我们可以利用`ActiveDocument.Sections`对象来访问每个部分(通常每个Word文档有多个节)的页眉和页脚。以下是一个简单的VBA代码示例,用于删除所有节的页眉和页脚: ```vba Sub ClearHeadersAndFooters()...
recommend-type

PHP集成Autoprefixer让CSS自动添加供应商前缀

标题和描述中提到的知识点主要包括:Autoprefixer、CSS预处理器、Node.js 应用程序、PHP 集成以及开源。 首先,让我们来详细解析 Autoprefixer。 Autoprefixer 是一个流行的 CSS 预处理器工具,它能够自动将 CSS3 属性添加浏览器特定的前缀。开发者在编写样式表时,不再需要手动添加如 -webkit-, -moz-, -ms- 等前缀,因为 Autoprefixer 能够根据各种浏览器的使用情况以及官方的浏览器版本兼容性数据来添加相应的前缀。这样可以大大减少开发和维护的工作量,并保证样式在不同浏览器中的一致性。 Autoprefixer 的核心功能是读取 CSS 并分析 CSS 规则,找到需要添加前缀的属性。它依赖于浏览器的兼容性数据,这一数据通常来源于 Can I Use 网站。开发者可以通过配置文件来指定哪些浏览器版本需要支持,Autoprefixer 就会自动添加这些浏览器的前缀。 接下来,我们看看 PHP 与 Node.js 应用程序的集成。 Node.js 是一个基于 Chrome V8 引擎的 JavaScript 运行时环境,它使得 JavaScript 可以在服务器端运行。Node.js 的主要特点是高性能、异步事件驱动的架构,这使得它非常适合处理高并发的网络应用,比如实时通讯应用和 Web 应用。 而 PHP 是一种广泛用于服务器端编程的脚本语言,它的优势在于简单易学,且与 HTML 集成度高,非常适合快速开发动态网站和网页应用。 在一些项目中,开发者可能会根据需求,希望把 Node.js 和 PHP 集成在一起使用。比如,可能使用 Node.js 处理某些实时或者异步任务,同时又依赖 PHP 来处理后端的业务逻辑。要实现这种集成,通常需要借助一些工具或者中间件来桥接两者之间的通信。 在这个标题中提到的 "autoprefixer-php",可能是一个 PHP 库或工具,它的作用是把 Autoprefixer 功能集成到 PHP 环境中,从而使得在使用 PHP 开发的 Node.js 应用程序时,能够利用 Autoprefixer 自动处理 CSS 前缀的功能。 关于开源,它指的是一个项目或软件的源代码是开放的,允许任何个人或组织查看、修改和分发原始代码。开源项目的好处在于社区可以一起参与项目的改进和维护,这样可以加速创新和解决问题的速度,也有助于提高软件的可靠性和安全性。开源项目通常遵循特定的开源许可证,比如 MIT 许可证、GNU 通用公共许可证等。 最后,我们看到提到的文件名称 "autoprefixer-php-master"。这个文件名表明,该压缩包可能包含一个 PHP 项目或库的主分支的源代码。"master" 通常是源代码管理系统(如 Git)中默认的主要分支名称,它代表项目的稳定版本或开发的主线。 综上所述,我们可以得知,这个 "autoprefixer-php" 工具允许开发者在 PHP 环境中使用 Node.js 的 Autoprefixer 功能,自动为 CSS 规则添加浏览器特定的前缀,从而使得开发者可以更专注于内容的编写而不必担心浏览器兼容性问题。
recommend-type

揭秘数字音频编码的奥秘:非均匀量化A律13折线的全面解析

# 摘要 数字音频编码技术是现代音频处理和传输的基础,本文首先介绍数字音频编码的基础知识,然后深入探讨非均匀量化技术,特别是A律压缩技术的原理与实现。通过A律13折线模型的理论分析和实际应用,本文阐述了其在保证音频信号质量的同时,如何有效地降低数据传输和存储需求。此外,本文还对A律13折线的优化策略和未来发展趋势进行了展望,包括误差控制、算法健壮性的提升,以及与新兴音频技术融合的可能性。 # 关键字 数字音频编码;非均匀量化;A律压缩;13折线模型;编码与解码;音频信号质量优化 参考资源链接:[模拟信号数字化:A律13折线非均匀量化解析](https://wenku.csdn.net/do
recommend-type

arduino PAJ7620U2

### Arduino PAJ7620U2 手势传感器 教程 #### 示例代码与连接方法 对于Arduino开发PAJ7620U2手势识别传感器而言,在Arduino IDE中的项目—加载库—库管理里找到Paj7620并下载安装,完成后能在示例里找到“Gesture PAJ7620”,其中含有两个示例脚本分别用于9种和15种手势检测[^1]。 关于连线部分,仅需连接四根线至Arduino UNO开发板上的对应位置即可实现基本功能。具体来说,这四条线路分别为电源正极(VCC),接地(GND),串行时钟(SCL)以及串行数据(SDA)[^1]。 以下是基于上述描述的一个简单实例程序展示如
recommend-type

网站啄木鸟:深入分析SQL注入工具的效率与限制

网站啄木鸟是一个指的是一类可以自动扫描网站漏洞的软件工具。在这个文件提供的描述中,提到了网站啄木鸟在发现注入漏洞方面的功能,特别是在SQL注入方面。SQL注入是一种常见的攻击技术,攻击者通过在Web表单输入或直接在URL中输入恶意的SQL语句,来欺骗服务器执行非法的SQL命令。其主要目的是绕过认证,获取未授权的数据库访问权限,或者操纵数据库中的数据。 在这个文件中,所描述的网站啄木鸟工具在进行SQL注入攻击时,构造的攻击载荷是十分基础的,例如 "and 1=1--" 和 "and 1>1--" 等。这说明它的攻击能力可能相对有限。"and 1=1--" 是一个典型的SQL注入载荷示例,通过在查询语句的末尾添加这个表达式,如果服务器没有对SQL注入攻击进行适当的防护,这个表达式将导致查询返回真值,从而使得原本条件为假的查询条件变为真,攻击者便可以绕过安全检查。类似地,"and 1>1--" 则会检查其后的语句是否为假,如果查询条件为假,则后面的SQL代码执行时会被忽略,从而达到注入的目的。 描述中还提到网站啄木鸟在发现漏洞后,利用查询MS-sql和Oracle的user table来获取用户表名的能力不强。这表明该工具可能无法有效地探测数据库的结构信息或敏感数据,从而对数据库进行进一步的攻击。 关于实际测试结果的描述中,列出了8个不同的URL,它们是针对几个不同的Web应用漏洞扫描工具(Sqlmap、网站啄木鸟、SqliX)进行测试的结果。这些结果表明,针对提供的URL,Sqlmap和SqliX能够发现注入漏洞,而网站啄木鸟在多数情况下无法识别漏洞,这可能意味着它在漏洞检测的准确性和深度上不如其他工具。例如,Sqlmap在针对 "http://www.2cto.com/news.php?id=92" 和 "http://www.2cto.com/article.asp?ID=102&title=Fast food marketing for children is on the rise" 的URL上均能发现SQL注入漏洞,而网站啄木鸟则没有成功。这可能意味着网站啄木鸟的检测逻辑较为简单,对复杂或隐蔽的注入漏洞识别能力不足。 从这个描述中,我们也可以了解到,在Web安全测试中,工具的多样性选择是十分重要的。不同的安全工具可能对不同的漏洞和环境有不同的探测能力,因此在实际的漏洞扫描过程中,安全测试人员需要选择合适的工具组合,以尽可能地全面地检测出应用中存在的漏洞。 在标签中指明了这是关于“sql注入”的知识,这表明了文件主题的核心所在。SQL注入是一种常见的网络攻击方式,安全测试人员、开发人员和网络管理员都需要对此有所了解,以便进行有效的防御和检测。 最后,提到了压缩包子文件的文件名称列表,其中包含了三个文件:setup.exe、MD5.exe、说明_Readme.html。这里提供的信息有限,但可以推断setup.exe可能是一个安装程序,MD5.exe可能是一个计算文件MD5散列值的工具,而说明_Readme.html通常包含的是软件的使用说明或者版本信息等。这些文件名暗示了在进行网站安全测试时,可能涉及到安装相关的软件工具,以及进行文件的校验和阅读相应的使用说明。然而,这些内容与文件主要描述的web安全漏洞检测主题不是直接相关的。
recommend-type

【GPStoolbox使用技巧大全】:20个实用技巧助你精通GPS数据处理

# 摘要 GPStoolbox是一个广泛应用于GPS数据处理的软件工具箱,它提供了从数据导入、预处理、基本分析到高级应用和自动化脚本编写的全套功能。本文介绍了GPStoolbox的基本概况、安装流程以及核心功能,探讨了如何