VBA窗体设计与编程:全面指南

部署运行你感兴趣的模型镜像

本文还有配套的精品资源,点击获取 menu-r.4af5f7ec.gif

简介:VBA是Microsoft Office中的编程语言,用于自定义功能和自动化任务。本课程深入介绍VBA窗体设计,包括窗体和控件的基本概念、创建窗体、属性设置、方法与事件的应用,以及窗体的高级技巧。学习如何设计窗体以改善用户交互和自动化工作流程,提升办公效率和用户体验。
VBA 窗体 资料 VBA窗体资料

1. VBA窗体与控件概念

VBA(Visual Basic for Applications)是微软公司推出的一款编程语言,它常用于Office系列软件中,可以用来扩展和自定义应用程序的功能。VBA窗体是一种用户界面,允许程序员创建独立于标准应用程序界面的自定义对话框或表单,它能够提供更丰富和直观的用户体验。

窗体是VBA程序中的一个重要组成部分,通常作为容器使用,它能容纳各种控件。控件包括按钮、文本框、列表框、复选框等,它们是构成用户界面的基础元素,用于实现与用户之间的交互。通过控件,用户可以输入数据、触发程序执行、显示信息等。

在本章中,我们将深入探讨VBA窗体与控件的基本概念,以及它们如何被用于实现用户界面与程序逻辑的交互。理解这些概念对于使用VBA进行开发的程序员至关重要,它不仅有助于构建良好的用户体验,还能在后续章节中帮助我们设计出更加高效和稳定的VBA应用。

2. 创建VBA窗体步骤

在VBA编程中,创建窗体是构建用户界面的基础。本章将详细阐述创建VBA窗体的各个步骤,确保你能够通过这些步骤创建出功能丰富、外观美观的窗体,与用户进行有效的交互。

2.1 设计窗体布局

在开始创建窗体之前,首先需要规划窗体的功能和布局。这一过程虽然不涉及编写代码,但对于最终的用户体验来说至关重要。

2.1.1 确定窗体目的和功能

设计窗体前,首先明确该窗体将用于何种目的和提供哪些功能。这包括:

  • 窗体是否用于数据输入、显示信息、执行任务还是其他操作。
  • 确定窗体将展示哪些控件,并明确这些控件如何协助完成窗体目标。

2.1.2 选择合适的控件及其布局

根据窗体的目的和功能,选择合适的控件,然后规划它们的布局。控件的布局应遵循以下原则:

  • 确保控件的逻辑顺序,使其易于用户理解和操作。
  • 控件之间保持足够的间隔,以便用户可以轻松点击。
  • 避免视觉上的杂乱无章,合理使用空白区域,突出重要控件。

2.2 窗体的创建与属性设置

完成前期设计后,接下来是实际创建窗体并设置其属性。

2.2.1 使用VBA编辑器创建窗体

打开Excel,按下 Alt + F11 键打开VBA编辑器,在”项目-工程(VBAProject)”窗口中找到你想要添加窗体的工作簿,右键点击”Microsoft Excel 对象”下的”此工作簿”,选择”插入” -> “用户表单”,即可创建一个新的窗体。

2.2.2 窗体的基本属性配置

在用户表单上点击右键选择”属性”,打开属性窗口。这里可以配置窗体的基本属性:

  • Name(名称) :为窗体指定一个有含义的名称,如 frmMain
  • Caption(标题) :设置窗体顶部显示的标题,如 “主窗体”。
  • StartUpPosition(启动位置) :可以设置窗体启动时的位置,如 2-屏幕中心
  • Height 和 Width(高度和宽度) :设置窗体的初始尺寸。

2.2.3 窗体的高级属性设置

对于需要更进一步定制的属性,可以通过编程实现:

  • 背景颜色 :在窗体的 UserForm_Initialize 事件中,可以通过 Me.BackColor = RGB(255, 255, 0) 设置背景为黄色。
  • 启动按钮 :通过 Show 方法来控制窗体启动时的行为,例如 Me.Show vbModeless 可创建一个无模式的窗体。

2.3 窗体的保存与测试

窗体创建并设置好属性后,需要正确保存并进行测试,确保其按预期工作。

2.3.1 保存窗体模板

为了方便重用窗体,可以将窗体保存为模板。在VBA编辑器中,将用户表单导出为 .frm 文件,然后可以导入到任何VBA项目中使用。

2.3.2 测试窗体功能

在VBA编辑器中,运行窗体,检查所有控件是否按预期工作,包括:

  • 各种事件的触发。
  • 控件间的交互。
  • 数据输入与显示是否正确。

通过这些步骤,你将可以创建出满足业务需求的窗体,并确保它们能够高效稳定地运行。在接下来的章节中,我们将深入探讨如何配置和应用窗体和控件的属性和方法,以及如何处理窗体事件,从而进一步提升应用程序的用户体验。

3. 窗体和控件属性配置

3.1 理解属性的作用和分类

3.1.1 属性与控件表现的关系

属性是控件以及窗体本身所拥有的特征和设置,它直接决定了控件的行为和外观。例如,一个按钮的“Caption”属性可以定义按钮上显示的文本,而“Enabled”属性则可以控制按钮是否响应用户的点击操作。通过设置不同的属性值,可以使得同一控件在不同的场景下展现出不同的功能和外观。

' 示例代码
Private Sub UserForm_Initialize()
    ' 初始化按钮,设置其属性
    CommandButton1.Caption = "点击我"
    CommandButton1.Enabled = True
    ' ...其他属性设置
End Sub

3.1.2 常用属性及其功能

在VBA中,每个控件都有众多属性可供配置。这些属性大致可以分为两类:数据类型属性和行为类型属性。数据类型属性决定了控件存储的信息,如文本框的“Text”属性存储用户输入的文本;行为类型属性则影响控件的运行方式,例如,列表框的“MultiSelect”属性可以设置为允许多选。

' 示例代码
Private Sub UserForm_Initialize()
    ' 设置列表框为多选模式
    ListBox1.MultiSelect = fmMultiSelectMulti
    ' ...设置其他行为类型属性
End Sub

3.2 配置控件的外观和行为属性

3.2.1 字体、颜色和尺寸设置

外观属性如字体、颜色和尺寸直接关系到用户界面的美观性和可读性。例如,您可以改变标签控件的字体大小和颜色,使其在窗体上更加显眼。

' 示例代码
Private Sub UserForm_Initialize()
    ' 设置标签字体、颜色和尺寸
    Label1.Font.Size = 12
    Label1.Font.Bold = True
    Label1.ForeColor = RGB(0, 0, 255)
    ' ...其他外观属性设置
End Sub

3.2.2 状态控制和事件触发属性

控件的状态控制属性如“Visible”和“Locked”可以控制控件是否可见或是否可以被编辑。事件触发属性则关联到用户的操作上,比如单击按钮时触发的“OnClick”事件,这些属性使得控件的行为可以根据用户的交互来调整。

' 示例代码
Private Sub UserForm_Initialize()
    ' 控件状态控制设置
    TextBox1.Visible = False
    TextBox1.Locked = True
    ' ...其他状态控制属性设置
End Sub

3.3 窗体和控件属性的实际应用

3.3.1 通过属性调整控件布局

在实际的应用中,属性可以帮助我们实现控件的动态布局调整。例如,可以通过改变一个表格控件的“RowSource”属性来动态加载数据源,或者通过调整“Top”和“Left”属性来控制控件的位置。

' 示例代码
Private Sub UserForm_Initialize()
    ' 动态调整表格控件的数据源
    ListBox1.RowSource = "Sheet1!A1:B10"
    ' ...其他位置属性设置
End Sub

3.3.2 实现动态界面效果

通过属性的变化可以实现动态的用户界面效果。例如,可以在用户进行特定操作时,通过改变按钮的“Enabled”属性来启用或禁用按钮,或通过修改“BackColor”属性来改变窗体的背景颜色。

' 示例代码
Private Sub CommandButton1_Click()
    ' 当按钮被点击时改变窗体背景色
    UserForm1.BackColor = RGB(255, 255, 0)
End Sub

在本章节中,我们详细探讨了VBA窗体和控件属性的作用,分类以及如何在实际应用中调整属性以实现特定的功能和效果。通过具体的代码示例,我们展示了如何利用VBA的属性功能来优化和美化用户界面,同时也增强程序的交互性和用户体验。在下一章中,我们将继续深入了解VBA窗体和控件,着重于方法的应用和事件处理程序的编写,为读者提供更多实用的编程技巧。

4. 窗体和控件方法应用

4.1 方法的概念和作用

4.1.1 方法与属性的区别

在VBA中,方法是一种动作或功能,允许用户执行操作,例如打开一个文件、读取数据或执行复杂的计算。与属性不同,属性用来获取或设置对象的值,而方法则用来执行操作。方法可以有参数,可以返回值,也可以改变对象的内部状态。

4.1.2 常用方法及其用途

VBA提供了许多内置方法,适用于不同的场景。例如:
- Show 方法:显示窗体或消息框。
- Hide 方法:隐藏窗体。
- Print 方法:在打印机上输出内容。

每个方法都有其特定的用途和参数,通过熟练使用这些方法,开发者可以构建出功能丰富且用户友好的应用程序。

4.2 实现控件交互的方法应用

4.2.1 控件间的消息传递方法

为了实现控件间的交互,开发者通常需要编写消息传递的方法。例如,可以在一个按钮的点击事件中编写代码来通知一个文本框显示特定的信息。在VBA中,这可以通过调用文本框的 SetFocus 方法来实现,代码示例如下:

Private Sub CommandButton1_Click()
    TextBox1.SetFocus
    TextBox1.Text = "Hello, World!"
End Sub

上述代码中,当命令按钮被点击时,文本框 TextBox1 将获得焦点,并显示文本“Hello, World!”。

4.2.2 窗体中事件驱动的方法

事件驱动的方法是响应用户动作或系统事件的主要方式。例如,可以为列表框(ListBox)添加 Click 事件处理程序,当用户点击列表框中的项时,程序可以做出响应。

Private Sub ListBox1_Click()
    MsgBox "You selected: " & ListBox1.Value
End Sub

在此代码块中,每当用户点击 ListBox1 时,都会弹出一个消息框显示选中的值。

4.3 窗体和控件方法的综合案例分析

4.3.1 案例选择和需求分析

考虑一个简单的案例:需要创建一个订单输入系统,其中包含用户输入订单信息的窗体。订单信息包括产品名称、数量和价格。需要实现以下功能:
- 用户输入数据到相应的文本框。
- 当用户点击提交按钮时,窗体需要校验输入的正确性,并显示订单摘要。

4.3.2 方法编写和调试过程

在VBA中,首先需要为提交按钮添加一个点击事件处理程序。在这个处理程序中,将包含校验输入的方法和显示摘要的方法。

Private Sub SubmitButton_Click()
    If ValidateInput() Then
        Dim orderSummary As String
        orderSummary = "Product Name: " & ProductNameTextBox.Text & vbCrLf
        orderSummary = orderSummary & "Quantity: " & QuantityTextBox.Text & vbCrLf
        orderSummary = orderSummary & "Price: " & PriceTextBox.Text & vbCrLf
        MsgBox orderSummary, vbInformation, "Order Summary"
    Else
        MsgBox "Please enter valid input.", vbExclamation, "Input Error"
    End If
End Sub

Function ValidateInput() As Boolean
    ' Implement input validation logic here
End Function

在上述代码中, SubmitButton_Click 方法是响应提交按钮点击的事件处理程序。 ValidateInput 函数用于检查输入数据的有效性。如果数据有效,则会创建订单摘要并显示在消息框中;如果数据无效,则会提示用户输入有误。

4.3.3 案例演示:复杂的事件处理实例

下面展示一个更复杂的事件处理实例,其中包含错误处理和用户反馈。

Private Sub SubmitButton_Click()
    On Error GoTo ErrorHandler
    If ValidateInput() Then
        Dim orderSummary As String
        orderSummary = "Product Name: " & ProductNameTextBox.Text & vbCrLf
        orderSummary = orderSummary & "Quantity: " & QuantityTextBox.Text & vbCrLf
        orderSummary = orderSummary & "Price: " & PriceTextBox.Text & vbCrLf
        MsgBox orderSummary, vbInformation, "Order Summary"
    Else
        MsgBox "Please enter valid input.", vbExclamation, "Input Error"
    End If
    Exit Sub
ErrorHandler:
    MsgBox "An error occurred: " & Err.Description, vbCritical, "Critical Error"
End Sub

在此代码中, ErrorHandler 标签用于捕获并处理潜在的运行时错误,提供了一种机制来优雅地处理异常,避免程序崩溃。同时,它向用户提供了错误的详细信息,提高了程序的健壮性和用户体验。

5. 窗体事件与处理程序编写

事件驱动编程是VBA编程的核心,窗体上的控件能够响应用户的操作,这一切都是通过事件和事件处理程序来完成的。在本章中,我们将深入了解事件驱动编程的基础,事件的不同分类和应用,以及如何创建高效的事件处理程序。

5.1 事件驱动编程基础

事件驱动编程是响应用户操作或系统通知的编程范式。在VBA中,几乎所有的用户操作都会产生事件,而我们的代码则是在特定的事件发生时才被触发执行。

5.1.1 事件、事件源和事件处理程序

事件是某种动作发生时的信号,例如,用户点击一个按钮时,就会触发一个Click事件。事件源是产生事件的对象,即事件发生的地点,比如刚才提到的按钮。事件处理程序则是响应事件的代码块。

编写事件处理程序时,需要遵循以下规则:
- 事件处理程序的名称必须与事件名称相对应,且有特定的参数。
- 通常,事件处理程序的编写依赖于VBA中的 Private Sub 语句,然后跟上事件名称。

5.2 窗体事件的分类与应用

窗体事件可分为多种类型,根据它们发生的上下文和触发的原因进行分类。

5.2.1 窗体加载和卸载事件

加载和卸载事件分别在窗体的生命周期开始和结束时发生。加载事件包括 Initialize Load 等;卸载事件包括 UnLoad

例如,下面的代码在窗体加载时初始化一些控件的属性:

Private Sub UserForm_Initialize()
    ' 初始化代码
    TextBox1.Value = "欢迎使用!"
End Sub

5.2.2 控件交互事件

控件交互事件发生在控件间的交互中,例如按钮点击( Click ),文本框内容改变( Change )等。

5.2.3 用户操作事件

用户操作事件包括键盘和鼠标事件,如 KeyDown KeyUp MouseDown MouseMove 等。

5.3 创建高效的事件处理程序

高效的事件处理程序需要编写得精炼、高效,同时能够处理各种情况下的异常。

5.3.1 事件处理程序的优化

事件处理程序应该尽量简洁,避免在其中执行复杂的逻辑。如果需要进行大量的计算,应该将其放在单独的子程序中。

5.3.2 常见问题的解决方案

在处理事件时,可能经常会遇到输入验证、错误处理等问题。例如,对于文本框的内容验证,可以编写类似以下的代码:

Private Sub TextBox1_Change()
    If Not IsNumeric(TextBox1.Text) Then
        MsgBox "请输入有效的数字"
        TextBox1.SetFocus
        Exit Sub
    End If
    ' 进一步处理
End Sub

5.3.3 案例演示:复杂的事件处理实例

假设我们有一个用户界面,其中包含一个按钮和一个文本框。用户点击按钮后,文本框中的内容会根据用户点击的次数进行相应的更改。

Private ClickCount As Integer

Private Sub UserForm_Initialize()
    ' 初始化点击次数
    ClickCount = 0
    ' 初始化文本框内容
    TextBox1.Value = "点击按钮更改此内容"
End Sub

Private Sub CommandButton1_Click()
    ' 更新点击次数
    ClickCount = ClickCount + 1
    ' 根据点击次数更改文本框内容
    If ClickCount Mod 2 = 0 Then
        TextBox1.Value = "双击将重置此内容!"
    Else
        TextBox1.Value = "点击按钮更改此内容"
    End If
End Sub

Private Sub CommandButton1_MouseUp(ByVal Button As Integer, ByVal Shift As Integer, ByVal X As Single, ByVal Y As Single)
    If Button = 2 Then ' 判断是否为双击
        ' 重置文本框内容和点击次数
        TextBox1.Value = "点击按钮更改此内容"
        ClickCount = 0
    End If
End Sub

通过上述示例,我们可以看到如何编写事件处理程序,以及如何通过代码逻辑控制程序的行为。这些技能对于提高VBA程序的响应性和用户体验至关重要。

本文还有配套的精品资源,点击获取 menu-r.4af5f7ec.gif

简介:VBA是Microsoft Office中的编程语言,用于自定义功能和自动化任务。本课程深入介绍VBA窗体设计,包括窗体和控件的基本概念、创建窗体、属性设置、方法与事件的应用,以及窗体的高级技巧。学习如何设计窗体以改善用户交互和自动化工作流程,提升办公效率和用户体验。


本文还有配套的精品资源,点击获取
menu-r.4af5f7ec.gif

您可能感兴趣的与本文相关的镜像

Stable-Diffusion-3.5

Stable-Diffusion-3.5

图片生成
Stable-Diffusion

Stable Diffusion 3.5 (SD 3.5) 是由 Stability AI 推出的新一代文本到图像生成模型,相比 3.0 版本,它提升了图像质量、运行速度和硬件效率

自动生成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 '********本模块结束**********
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符  | 博主筛选后可见
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值