WanderingSoul
New Member
- Joined
- Oct 31, 2024
- Messages
- 4
- Office Version
- 2021
- Platform
- Windows
I have a problem passing parameters to ‘macros’ in Excell. My version is from Microsoft Office Professional Plus 2021 (Microsoft® Excel® 2021 MSO (Version 2409 Build 16.0.18025.20160) 64-bit)
I want to use a simple Form button to call a VBA Sub which takes three parameters, from looking through the web it should work, but it doesn’t!
I can call a macro with no parameters or one parameter but if I try and pass more than one parameter I get the error message of “Cannot run the macro "'TwoParms(45, 75)'", The macro may not be available in this workbook or all macros may be disabled.”
TwoParms is my test macro.
To eliminate potential problems and keep things as simple as possible I have a created a new workbook with a single sheet (Sheet1) The VBA module was created using a simple record macro, then I added
Sub NoParms()
MsgBox ("No Parameters")
End Sub
Sub OneParm(parm1)
MsgBox ("OneParm: " & parm1)
End Sub
Sub TwoParms(parm1, parm2)
MsgBox ("TwoParms: " & parm1 & " | " & parm2)
End Sub
To the module, Debug/Compile produces no errors or warnings.
Calling NoParms() and OneParm(parm) work, calling TwoParms(parm1, parm2) does not.
I know I could pass a range of 3 cells, or perhaps use ActiveX controls, but I can see no reason why I should have to. As far as I can research this should work using a simple Form button.
Should this work and if so, what am I missing?
I want to use a simple Form button to call a VBA Sub which takes three parameters, from looking through the web it should work, but it doesn’t!
I can call a macro with no parameters or one parameter but if I try and pass more than one parameter I get the error message of “Cannot run the macro "'TwoParms(45, 75)'", The macro may not be available in this workbook or all macros may be disabled.”
TwoParms is my test macro.
To eliminate potential problems and keep things as simple as possible I have a created a new workbook with a single sheet (Sheet1) The VBA module was created using a simple record macro, then I added
Sub NoParms()
MsgBox ("No Parameters")
End Sub
Sub OneParm(parm1)
MsgBox ("OneParm: " & parm1)
End Sub
Sub TwoParms(parm1, parm2)
MsgBox ("TwoParms: " & parm1 & " | " & parm2)
End Sub
To the module, Debug/Compile produces no errors or warnings.
Calling NoParms() and OneParm(parm) work, calling TwoParms(parm1, parm2) does not.
I know I could pass a range of 3 cells, or perhaps use ActiveX controls, but I can see no reason why I should have to. As far as I can research this should work using a simple Form button.
Should this work and if so, what am I missing?