打开Excel文件时显示用户窗体

To help users enter data in a workbook, you can create an Excel UserForm, with text boxes and combo boxes. Then, with a quick bit of code, you can show UserForm when Excel file opens, so the form is easy to find and use.

为了帮助用户在工作簿中输入数据,可以创建带有文本框和组合框的Excel UserForm 。 然后,通过一些简短的代码,您可以在Excel文件打开时显示UserForm,以便轻松查找和使用该表单。

零件库存数据输入表 (Parts Inventory Data Entry Form)

Here is the parts inventory data entry form from the sample file.

这是样本文件中的零件库存数据输入表单。

Show UserForm When Excel File Opens

In the original UserForm sample file, there was a button on the worksheet, and users could click it to open the UserForm.

在原始的UserForm示例文件中,工作表上有一个按钮,用户可以单击它打开UserForm。

userformstart01

自动打开用户窗体 (Open the UserForm Automatically)

In some workbooks, you might want people to get right to work, and see the UserForm immediately.

在某些工作簿中,您可能希望人们开始工作,并立即查看UserForm。

So, instead of putting a button on the worksheet, for people to click, you can show the UserForm automatically, when the file opens.

因此,当人们打开文件时,无需在工作表上放置按钮即可让人们单击,而是可以自动显示UserForm。

自动打开表单的代码 (Code to Open the Form Automatically)

To make the UserForm open automatically, you’ll add a bit of code to the workbook’s code module, in the Workbook_Open procedure.

要使UserForm自动打开,您需要在Workbook_Open过程中向工作簿的代码模块中添加一些代码。

To add the code:

要添加代码:

  • In the UserForm workbook, press Alt + F11, to open the Visual Basic Editor.

    在UserForm工作簿中,按Alt + F11,以打开Visual Basic编辑器。
  • At the left, in the Project Explorer, find the UserForm workbook, and double-click on its ThisWorkbook module (in the Microsoft Excel Objects folder).

    在左侧的Project Explorer中,找到UserForm工作簿,然后双击它的ThisWorkbook模块(在Microsoft Excel Objects文件夹中)。
userformstart02
  • At the top left of the main code window, from the Object drop down, select Workbook

    在主代码窗口的左上方,从“对象”下拉列表中,选择“工作簿”
userformstart03
  • At the top right, from the Procedure drop down, select Open

    在右上角的“过程”下拉列表中,选择“打开”
  • The Workbook_Open procedure will be automatically created, with the cursor positioned between the first and last lines of code.

    将自动创建Workbook_Open过程,并将光标置于代码的第一行和最后一行之间。
userformstart04
    • frmParts.Show

      frmParts.Show

userformstart05

测试工作簿_打开代码 (Test the Workbook_Open Code)

To test the Workbook_Open code, follow these steps:

要测试Workbook_Open代码,请按照下列步骤操作:

  • Save and close the UserForm workbook.

    保存并关闭UserForm工作簿。
  • Open the workbook, and enable macros, if prompted.

    打开工作簿,并在出现提示时启用宏。
  • The UserForm will open automatically.

    UserForm将自动打开。

______

______

翻译自: https://contexturesblog.com/archives/2011/06/03/show-userform-when-excel-file-opens/

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值