How to combine multiple VBA macros into one add-in file for Excel

落花浮王杯 提交于 2019-12-08 06:22:20

问题


I have written some 4 to 5 macros for Excel 2010, now I want to add all of these macros into a Custom Tab in the Ribbon as buttons. But I want to install all the macros as one complete package (or add-in). I have successfully installed one macro by creating a CustomUI package with the help of Visual Studio, but I don't know how to add other macros to the same add-in.


回答1:


It depends on where you've stored your macro. For instance if your macro is saved in a module (within the Add-in file), then you would add an event handler to call the function as specified in the CustomUI. For example I have two macros, one called 'PricingTaxable' and one called 'PricingPerformance'.

Events handlers in module:

Sub PricingTaxable_eventhandler(control As IRibbonControl)
    PricingTaxable
End Sub

Sub PricingPerformance_eventhandler(control As IRibbonControl)
    PricingPerformance
End Sub

And the CustomUI XML code (find the event handler and function names to know what to do):

<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>

Refer here for more help: https://erpcoder.wordpress.com/2012/05/30/how-to-create-a-custom-ribbon-addin-for-excel-2010/



来源:https://stackoverflow.com/questions/31384135/how-to-combine-multiple-vba-macros-into-one-add-in-file-for-excel

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!