Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 07-27-2025, 07:09 PM
ayomama ayomama is offline OnAction function with two string parameters Windows 10 OnAction function with two string parameters Office 2021
Novice
OnAction function with two string parameters
 
Join Date: Jul 2025
Posts: 5
ayomama is on a distinguished road
Default OnAction function with two string parameters

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
Word adds the controls under a new "Add-ins" ribbon tab as expected.

The OnAction property of the button is set to :
Code:
'ReplaceTextWithMergeField "@PCIVIL", "PatientTitre"'
Here is ReplaceTextWithMergeField's signature:

Code:
Public Sub ReplaceTextWithMergeField(ByVal macroOrText As String, ByVal mergeFieldNameNew As String)
It is located in a module that does NOT have the statement Option Private Module.


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()
What am I doing wrong?
Thanks

Last edited by ayomama; 07-27-2025 at 10:18 PM.
Reply With Quote
  #2  
Old 07-29-2025, 04:31 AM
ayomama ayomama is offline OnAction function with two string parameters Windows 10 OnAction function with two string parameters Office 2021
Novice
OnAction function with two string parameters
 
Join Date: Jul 2025
Posts: 5
ayomama is on a distinguished road
Default

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.
Reply With Quote
Reply

Tags
onaction parameters



Similar Threads
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
OnAction function with two string parameters How to get the Right function to return a string that has UPPERCASE letters only adj Word VBA 9 08-30-2014 09:21 PM
OnAction function with two string parameters .OnAction only works in document with the code donbexcel Word VBA 1 11-02-2011 05:25 AM
OnAction function with two string parameters Macro or Function to know wether a string is included in a text Eduardo Word VBA 5 06-15-2009 01:55 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 03:13 PM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2025, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2025 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft