![]() |
#1
|
|||
|
|||
![]()
Hello everyone,
I have already added a dropdown menu and a button as an item of the dropdown menu to Word's ribbon using pre-ribbon era Code:
Application.CommandBars("Standard").Controls.Add The OnAction property of the button is set to : Code:
'ReplaceTextWithMergeField "@PCIVIL", "PatientTitre"' Code:
Public Sub ReplaceTextWithMergeField(ByVal macroOrText As String, ByVal mergeFieldNameNew As String) When I click the button I get this error message: ![]() When I assign this parameter-less function (found in the same module) to OnAction instead, it works fine: Code:
Public Sub Testing() Thanks Last edited by ayomama; 07-27-2025 at 10:18 PM. |
#2
|
|||
|
|||
![]()
Sharing my solution.
Based on comments from ms word - VBA Pass arguments with .onAction - Stack Overflow and Just a moment... The only consistent method to pass multiple parameters to a callback function is through the .Parameter property of the control. Step 1 - define the callback function without any parameters in its signature Step 2 - set the value of the .OnAction property of the button (or other control) to the name of the function Step 3 - set the value of the .Parameter of the button (or other control) to a concatenated string of parameters Step 4 - in the callback function, read CommandBars.ActionControl.Parameter to retrieve the concatenated parameters Step 5 - use Split() to retrieve the individual parameters Will try to add sample code to illustrate later. |
![]() |
Tags |
onaction parameters |
|
![]() |
||||
Thread | Thread Starter | Forum | Replies | Last Post |
Public function string problem | JamesWood | Word VBA | 3 | 05-27-2021 11:55 PM |
Calling a macro from a template using OnAction | sg11 | Word VBA | 2 | 04-30-2018 11:43 PM |
![]() |
adj | Word VBA | 9 | 08-30-2014 09:21 PM |
![]() |
donbexcel | Word VBA | 1 | 11-02-2011 05:25 AM |
![]() |
Eduardo | Word VBA | 5 | 06-15-2009 01:55 AM |