将宏分配给按钮 - 宏以启动用户表单 [英] Assign macros to buttons - macros to launch userforms

查看:67
本文介绍了将宏分配给按钮 - 宏以启动用户表单的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,

我一直在帮助我的朋友在VBA中设置一些简单的用户表单,以帮助他们管理小型企业。

I have been helping my friend set up some simple userforms in VBA to help them run their small business.

我创建了两个用户表单。每当从模板创建新文档时,一个("DetailsForm")会自动打开,并用于输入数据填充在文档中。其他宏("主题")用于
插入某些文本,因为我不希望它自动运行我通过单击功能区上的一个按钮将其设置为打开,该按钮分配给为该用户表单启动宏。启动宏的代码如下:

There are two userforms I have created. One ("DetailsForm") opens automatically whenever a new document is created from a template, and is used to enter data that populates in the document. The other macro ("Subjects") is used to insert certain text, and as I don't want it to run automatically I have set it to open by clicking a button on the ribbon which is assigned to a launch macro for that userform. Code for the launch macro is as follows:

Sub StartForm()
     Subjects.Show
End Sub

理想情况下,我希望"启动"功能区上的两个宏的按钮,以便如果用户还没有准备好填写" DetailsForm"宏立即打开文档,他们可以点击一个按钮稍后重新启动它。
我使用与上面相同的代码为每个用户表单创建了一个单独的启动模块。当从"宏"运行时在开发人员选项卡(或VB)中的菜单,启动宏工作正常并启动其各自的用户表单。但是,当在功能区上分配给
按钮时,两个按钮(当被点击时)启动"主题"按钮。宏,即我无法在功能区上创建按钮启动"DetailsForm"。模块。我已经尝试过几个方面,包括重新创建模块,重新创建按钮,
关闭它再打开,一切都无济于事。是否有一些理由为什么单独的按钮(应该对不同的模块做同样的事情)无法区分这两个模块?

Ideally I would like to have "launch" buttons for both macros on the ribbon, so that if the user isn't ready to fill out the the "DetailsForm" macro immediately on opening the document, they can click a button to re-launch it later. I have made a separate launch module for each userform using the same code as shown above. When run from the "macros" menu in the developer tab (or from VB), the launch macros work fine and launch their respective userforms. But, when assigned to buttons on the ribbon, both buttons (when clicked) launch the "Subjects" macro, i.e. I can't make a button on the ribbon launch the "DetailsForm" module. I have tried several things including recreating the module, and recreating the button, turning it off and on again, all to no avail. Is there some reason why separate buttons (that should do the same thing but for different modules) are unable to distinguish between the two modules?

推荐答案

I应该澄清,当我说"使用与上面所示相同的代码"时,我的意思是,我使用了相同的基本编码,但引用了相应的用户名称。他们不是都说"Subjects.Show",另一个说"DetailsForm.Show"。
^。^
I should clarify that when I say "using the same code as shown above" I mean, I have used the same basic coding but with the appropriate userform name referred to. They don't both say "Subjects.Show", the other says "DetailsForm.Show". ^.^


这篇关于将宏分配给按钮 - 宏以启动用户表单的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆