如何将多个VBAmacros组合到Excel的一个加载项文件中

我已经为Excel 2010编写了4到5个macros,现在我想将所有这些macros添加到function区的自定义选项卡中作为button。 但是我想把所有的macros都安装成一个完整的包(或者加载项)。 我已经通过Visual Studio的帮助创build了一个CustomUI包来成功安装了一个macros,但我不知道如何将其他macros添加到同一个加载项中。

这取决于你存储macros的位置。 例如,如果您的macros保存在一个模块(在加载项文件中),那么您将添加一个事件处理程序来调用CustomUI中指定的函数。 例如,我有两个macros,一个叫“PricingTaxable”,一个叫“PricingPerformance”。

模块中的事件处理程序:

Sub PricingTaxable_eventhandler(control As IRibbonControl) PricingTaxable End Sub Sub PricingPerformance_eventhandler(control As IRibbonControl) PricingPerformance End Sub 

和CustomUI XML代码(find事件处理程序和函数名称来知道该怎么做):

 <customUI xmlns="http://schemas.microsoft.com/office/2009/07/customui"> <ribbon> <tabs> <tab id="customTab" label="Pricing" insertAfterMso="TabHome"> <group id="customGroup1" label="Taxable Income"> <button id="customButton1" label="Taxable Income" size="large" onAction="PricingTaxable_eventhandler" imageMso="PivotTableLayoutReportLayout" /> </group> <group id="customGroup2" label="Performance Sheets"> <button id="customButton2" label="Performance" size="large" onAction="PricingPerformance_eventhandler" imageMso="ChartTrendline" /> </group> </tab> </tabs> </ribbon> </customUI> 

请参阅此处获取更多帮助: https : //erpcoder.wordpress.com/2012/05/30/how-to-create-a-custom-ribbon-addin-for-excel-2010/