如何在 Access 2003 中创建用于 VBA 代码编辑的自定义工具栏和控件
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/15328415/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to create a customized toolbar and controls for use with VBA code editing in Access 2003
提问by Denis Starbank
I want to create a custom menu in Ms Access 2003 to automate some processing of VBA code. It's easy to create a custom toolbar and controls for use with forms, reports, etc; and I can create a toolbar visible and usable on the VBA side. But I've not succeeded, neither by interaction nor by vba, in populating the toolbar with custom (macro) controls, which is what I need to do. Searching for help always leads to instructions as to how to customise toolbars for the database, but NOT for the code. Advice would be much appreciated.
我想在 Ms Access 2003 中创建一个自定义菜单来自动处理 VBA 代码。创建用于表单、报表等的自定义工具栏和控件很容易;我可以创建一个在 VBA 端可见和可用的工具栏。但是,无论是通过交互还是通过 vba,我都没有成功地使用自定义(宏)控件填充工具栏,而这正是我需要做的。搜索帮助总是会导致有关如何为数据库而不是代码自定义工具栏的说明。建议将不胜感激。
回答by Trebor
From the MS website: http://msdn.microsoft.com/en-us/library/office/aa210698(v=office.11).aspx
从 MS 网站:http: //msdn.microsoft.com/en-us/library/office/aa210698(v=office.11).aspx
'Create a commandbar
Dim cmb As CommandBar
Set cmb = Application.CommandBars.Add("MyCommandBar")
cmb.Visible = True
'Add a command button
Dim cbc As CommandBarControl
Set cbc = cmb.Controls.Add(msoControlButton)
cbc.Caption = "Button1"
cbc.Style = msoButtonCaption
'Add code to execute when button is pressed
CommandBars("MyCommandBar").Controls("Button1").OnAction = "=MsgBox(""Wow!"")"
You could specify a macro in place of the "MsgBox".
您可以指定一个宏来代替“MsgBox”。