excel vba - How to call a macro from a button and pass arguments -


i want add button excel worksheet should call macro can handle 1 agument (an integer value). sadly when creating button, cannot link macro has arguments. typing macro , argument not work.

is there simple solution pass argument macro when button pressed?

yes, can assign macro button (or other excel controls/menu actions) , pass constant or variable arguments it.

in 'assign macro' window (right-click on object , select 'assign macro'):

  • enclose macro name in single quotes e.g. pass 2 constants: 'button1_click("a string!", 7)'
  • select 'this workbook' 'macros in' field
  • if wish pass variable (like value of cell), enclose parameter in evaluate()

for example, pass value of sheet1!$a$1 button function, have following text in 'macro name:' field:

'button1_click(evaluate("sheet1!$a$1"))'

if don't enclose variable argument 'evaluate' function, excel returns error 'formula complex assigned object.'.

i have included image if allowed on first post.


Comments

Popular posts from this blog

shopping cart - Page redirect not working PHP -

php - How to modify a menu to show sub-menus -

python - Installing PyDev in eclipse is failed -