excel浮动_浮动表单上的Excel宏按钮

excel浮动

In the olden days (Excel 2003 and earlier), there were toolbars, and you could "float" those, and position them anywhere over the worksheet. You could also create custom toolbars, and add a few commands and macros to those. They could be moved around the worksheet too.

在较早的日子(Excel 2003及更早版本)中,有工具栏,您可以“浮动”那些工具栏,并将其放置在工作表上的任何位置。 您还可以创建自定义工具栏,并向其中添加一些命令和宏。 它们也可以在工作表中移动。

In the newer versions of Excel, those floating toolbars aren't available, but you can create something similar, based on a UserForm. Build your own, or download my example, and customize it.

在较新版本的Excel中,这些浮动工具栏不可用,但是您可以基于UserForm创建类似的东西。 构建自己的示例,或下载我的示例并对其进行自定义。

轻松访问按钮 (Easy Access to Buttons)

In Excel 2007 and later, to make it easy for people to run macros, or move around in a workbook, you can add buttons in a frozen pane, at the top of the worksheet. Or, create a custom tab on the Ribbon, and put the commands there.

在Excel 2007和更高版本中,为了使人们能够轻松运行宏或在工作簿中移动,可以在工作表顶部的冻结窗格中添加按钮。 或者,在功能区上创建一个自定义选项卡,然后在其中放置命令。

However, that can be a long way to travel, if you're working on a big monitor, or doing a presentation.

但是,如果您正在使用大型显示器或进行演示,那可能是很长的路要走。

userformbuttons04

To position the macro buttons where you need them, you can create a floating form with macro buttons. Then, move it anywhere on the screen, so the buttons are close to the place that you need them. 

要将宏按钮放置在需要的位置,可以使用宏按钮创建一个浮动表单。 然后,将其移动到屏幕上的任意位置,以使按钮靠近您需要的位置。

Or, if you like to right-click, you can use Doug Glancy's free MenuRighter add-in, and put your favourite commands there.

或者,如果您想右键单击,则可以使用Doug Glancy的免费MenuRighter加载项 ,然后在其中放置您喜欢的命令。

创建一个用户表单 (Create a UserForm)

To create a floating form, you can insert a UserForm in the workbook, and have it open automatically when the file opens. There are instructions for creating a UserForm on my website, if you haven't built one before.

若要创建浮动表单,可以在工作簿中插入一个用户窗体,并在文件打开时自动将其打开。 如果您以前没有构建过UserForm ,则有在我的网站上创建UserForm的说明

To create a floating form:

创建浮动表格:

  • Insert a UserForm in the workbook

    在工作簿中插入一个用户窗体
  • Change the form’s ShowModal setting to False, so you’ll be able to use the worksheet while the form is open.

    将窗体的ShowModal设置更改为False,以便在窗体打开时可以使用工作表。
  • Then, add a few command buttons, and set those to run navigation macros, or other types of macros.

    然后,添加一些命令按钮,并将其设置为运行导航宏或其他类型的宏。

Here is a screen shot of the small and simple form that I built.

这是我构建的小型简单表单的屏幕截图。

userformbuttons01

自动打开表格 (Open the Form Automatically)

In the workbook module, use the Workbook_Open event to show the UserForm, so it appears as soon as the workbook opens.

在工作簿模块中,使用Workbook_Open事件显示UserForm,以便在工作簿打开后立即显示。

Here is the code that I added to the ThisWorkbook module in my example – the UserForm is named frmButtons.

这是我在示例中添加到ThisWorkbook模块中的代码– UserForm名为frmButtons。

Private Sub Workbook_Open()
  frmButtons.Show
End Sub

使用按钮 (Use the Buttons)

After the form opens automatically, it can be positioned anywhere on the screen, for easy access.

表单自动打开后,可以将其放置在屏幕上的任何位置,以便于访问。

I also added a Buttons sheet to the sample file, and you can click "Show the Buttons" on that sheet, to open the floating form again, if you've closed it.

我还向示例文件中添加了一个Buttons工作表,如果您已关闭它,则可以单击该工作表上的“ Show the Buttons”再次打开浮动窗体。

userformbuttons02

下载样本文件 (Download the Sample File)

To see how the UserForm works, you can download the sample file from my Contextures website. On the Excel Sample Files page, go to the UserForms and VBA section, and look for UF0032 - UserForm With Macro Buttons. The zipped file is in xlsm format, and you can enable macros when you open the file.

若要查看UserForm的工作原理,可以从我的Contextures网站下载示例文件。 在“ Excel示例文件”页面上,转到“用户窗体和VBA”部分,然后查找UF0032-带有宏按钮的用户窗体 。 压缩文件为xlsm格式,打开文件时可以启用宏。

To adapt the file for your workbook, change the captions of the buttons, and change the code on the command buttons, so they run your macros. You can add more buttons, or remove some of the existing ones.

若要使文件适合您的工作簿,请更改按钮的标题,并更改命令按钮上的代码,以便它们运行您的宏。 您可以添加更多按钮,或删除一些现有按钮。

翻译自: https://contexturesblog.com/archives/2016/01/14/excel-macro-buttons-on-floating-form/

excel浮动

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值