VBA - Word 2007 - Subscript out of range (error 9) - vba

I don't know what's causing this.
I've created a template with a lot of macro code in it. And I've used the Custom UI EDitor for Office 2007 applications to create a custom Tab in the Ribbon interface. In this tab I've got this button which is supposed to open a userform. The XML code for the button is this:
<customUI xmlns="http://schemas.microsoft.com/office/2006/01/customui">
<ribbon startFromScratch="false">
<tabs>
<tab id="CustomForm" label="CustomForm">
<group id="customuserdata" label="Custom Userdata">
<button id="openForm" label="Open userform" imageMso="OpenForm" size="large" onAction="openForm" />
</group>
</tab>
</tabs>
</ribbon>
</customUI>
And in the same Template I've got a Public Sub named openForm and it this I just run myForm.Show. It's in this sub that the error occurs "Run-Time error '9'. SubScript out of range". What could cause this?
The exact code of the Sub I'm trying to call is this:
Public Sub openForm(control As IRibbonControl)
FormAltData.Show ' This is where the debugger stops at'
End Sub

The error was caused by an Array I believe. I tried to access an array before it was even declared ^^ My bad :)

Related

"The macro cannot be found or has been disabled because of your security settings." PPAM addin causing this error from Ribbon but not from Code

I have some VBA PPT macros along with custom ribbon interface. Whose macros work fine from code but when made into ppam addin and added to PPT addins, some commands throw this error msg, however the macro works well, just want to stop this annoying msgs. The subs and functions are all Public and it still shows the same error. Please help
Public Sub frmFeedNotes_show()
frmFeedNotes.Show
End Sub
<!--RibbonX Visual Designer 1.94 for Microsoft PowerPoint 16.0. XML Code produced on 2017-10-06-->
<customUI xmlns="http://schemas.microsoft.com/office/2009/07/customui" >
<ribbon >
<tabs >
<tab
id="zenTools"
label="Zen Tools"
visible="true">
<group
id="FileProp"
label="File Properties"
visible="true">
<menu id="mnuExport"
label="Export Slides"
showImage="true"
imageMso="ExportToVCardFile" size="large">
<button id="btnFeedNotes"
label="Feed Notes*"
imageMso="FootnotesEndnotesShow"
onAction="frmFeedNotes_show" />
<button id="btnNotesCSV"
label="Notes as CSV"
imageMso="CommaSign"
onAction="ExportNotes" />
</menu>
</group >
</tab >
</tabs >
</ribbon >
</customUI >
Need to insert module name for onAction e.g. Module1
<button id="btnNotesCSV"
label="Notes as CSV"
imageMso="CommaSign"
onAction="Module1.ExportNotes" />
The ribbon Button also will pass a parameter to the sub, so expect it to receive a parameter. Add a parameter for the macro as follow
Public Sub frmFeedNotes_show(ByVal control As IRibbonControl)
frmFeedNotes.Show
End Sub

How to run a macro from button in custom ribbon ?

I created a custom ribbon using Custom UI Editor For Microsoft Office
<customUI xmlns="http://schemas.microsoft.com/office/2006/01/customui">
<ribbon>
<tabs>
<tab idMso="TabHome" >
<group id="customGroup1" label="My Group" insertAfterMso="GroupEditingExcel">
<button id="customButton1" label="Click Me" size="large" onAction="test()" imageMso="HappyFace" />
</group>
</tab>
</tabs>
</ribbon>
</customUI>
I saved excel 2007 file as Excel Macro-Enabled workbook
Here is my macro. It works fine when it run manually
Sub test()
For i = 1 To 10
For j = 1 To i
Cells(i, j) = j
Next
Next
End Sub
But When I press the smiling face button in my custom ribbon it gives following error message.
cannot run the macro 'test()' the macro may not be available in this
workbook or all macro may be disabled.
How can I fix this issue ? Any suggestions ?
Thank you
You should not include the brackets. So change this:
onAction="test()"
to:
onAction="test"
Also, make sure the routine name is unique and does not exist in any other workbook you might have open in Excel, otherwise you risk the wrong routine being called.

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

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

MS Word and RibbonX error (Wrong number of arguments ...)

I am trying to add an extra tab to the Word ribbon and have a couple buttons to invoke my own macros. I did the same thing with Excel and it worked fine. For some reason I can't get it to work in Word. I am using the Custom UI Editor. Here's the ribbon code.
<customUI xmlns="http://schemas.microsoft.com/office/2009/07/customui">
<ribbon startFromScratch="false">
<tabs>
<tab id="customTab" label="Pavel">
<group id="customGroup" label="Formatting">
<button id="customButton" label="Custom Button" imageMso="HappyFace" size="large" onAction="Callback" />
</group>
</tab>
</tabs>
</ribbon>
</customUI>
Just a very simple tab, with one button that calls the macro Callback().
I added a module to the Word file with the following code.
Sub Callback()
MsgBox ("Test")
End Sub
The macro runs fine on its one (hitting the play button in the editor) but when invoked via the button on the tab I get the following error:
Edit: It seems to do something with 1) public access to the module and 2) apparently the macro should be taking some argument similar to "control as ribboncontrol" or something like that. If you know where to find the documentation for this, please let me know.
A Ribbon button expects a Sub which takes a parameter:
Sub Callback(button As IRibbonControl)
MsgBox ("Test")
End Sub
http://msdn.microsoft.com/en-us/magazine/cc163469.aspx

VBA error 'Wrong number of arguments or invalid property assignments' when running macro via custom button

I have a macro that I call via a tab/group/button added by the Custom UI Editor -
<customUI xmlns="http://schemas.microsoft.com/office/2006/01/customui">
<ribbon startFromScratch="false">
<tabs>
<tab id="tabCustomActions" label="Custom ActionsXXX" insertAfterMso="TabDeveloper">
<group id="GroupTLA" label="TLA Actions">
<button id="buttonFormatTLA" label="Format as TLA" image="TLALogo" size="large" onAction="start_tla" />
</group>
</tab>
</tabs>
</ribbon>
</customUI>
The button shows up just fine, with my custom logo, but when ever I click the button I get the follow error -
VBA is not opened following this error, as it usually is, and no code within VBA is indicated as the problem if I open the developer console and then try and click the button.
Strangely though, if I try and run the macro manually, it works fine with no errors. Does anybody have any ideas how to solve this?
Here is my full code in a Pastebin, should you wish to view it. Thanks.
You have the wrong call signature for the start_tla callback in your VBA code.
If you open up your file in Custom UI Editor, there is a button called Generate Callbacks to the right in the menu. If you press it, it will give you the correct callbacks for your VBA code to match the ribbon xml in your file:
'Callback for buttonFormatTLA onAction
Sub start_tla(control As IRibbonControl)
'Your code goes here
End Sub
According to the Pastebin link, your sub looks like this, without the control As IRibbonControl parameter:
Public Sub start_tla()
It is old thread, but maybe it will help someone.
If you make 'control' argument optional, you can run either from Ribbon button or directly from VBA or Form button.
Sub start_tla(Optional control As IRibbonControl)
'Your code goes here
End Sub