Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 345
Default Run verb, macro with arguments

Hi All,
As part of the menu functionality in my addin I have a worksheet
with macro names, and argument values, (or none) for each macro.
..onaction contains the macro which gathers the data from the
worksheet.

Prior to the paragraph below is a sub that builds the
sArgAy string array and the ArgQty variable.

The code below is working and I don't think I'll have any
macros with more than 4 arguments, but I'm wondering if
there's a better way to code it without all the If..Else
syntax.

RunMac: 'Execute macros with arguments values
If ArgQty = 0 Then
Run MacName
ElseIf ArgQty = 1 Then
Run MacName, sArgAy(1)
ElseIf ArgQty = 2 Then
Run MacName, sArgAy(1), sArgAy(2)
ElseIf ArgQty = 3 Then
Run MacName, sArgAy(1), sArgAy(2), sArgAy(3)
ElseIf ArgQty = 4 Then
Run MacName, sArgAy(1), sArgAy(2), sArgAy(3), sArgAy(4)
End If
Return

I thought about var = array(xxx, xxx,xxx) but I still could not
figure out how to vary the qty of arguments.

I tried:
stringvar = "value1,value2"
run macname, stringvar

the above gets argument not optional when macname needs 2 arguments.

The Mso help shows application.Run(Macro, Arg1, Arg2, etc,)
but it presents the same 'problem'.

Is there a better way ?
Thanks.
--
Neal Z
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,290
Default Run verb, macro with arguments


Neal,
You can use Optional arguments in the MacName sub and it will execute
using what ever arguments are supplied...

Sub UniversalCall()
MacName "Huey", "Dewey", "Louie", "Donald"
MacName , , "Louie"
MacName
End Sub
'--
Sub MacName(Optional ByRef sArgAy1 As String, Optional ByRef sArgAy2 As String, _
Optional ByRef sArgAy3 As String, Optional ByRef sArgAy4 As String)
MsgBox sArgAy3
End Sub
-
The other way is to use a "Parameter Array" in the MacName sub.
See "Understanding Parameter Arrays" in help.
--
Jim Cone
San Francisco, USA
http://www.realezsites.com/bus/primitivesoftware
(Excel Add-ins / Excel Programming)




"Neal Zimm"
wrote in message
Hi All,
As part of the menu functionality in my addin I have a worksheet
with macro names, and argument values, (or none) for each macro.
..onaction contains the macro which gathers the data from the
worksheet.

Prior to the paragraph below is a sub that builds the
sArgAy string array and the ArgQty variable.

The code below is working and I don't think I'll have any
macros with more than 4 arguments, but I'm wondering if
there's a better way to code it without all the If..Else
syntax.

RunMac: 'Execute macros with arguments values
If ArgQty = 0 Then
Run MacName
ElseIf ArgQty = 1 Then
Run MacName, sArgAy(1)
ElseIf ArgQty = 2 Then
Run MacName, sArgAy(1), sArgAy(2)
ElseIf ArgQty = 3 Then
Run MacName, sArgAy(1), sArgAy(2), sArgAy(3)
ElseIf ArgQty = 4 Then
Run MacName, sArgAy(1), sArgAy(2), sArgAy(3), sArgAy(4)
End If
Return

I thought about var = array(xxx, xxx,xxx) but I still could not
figure out how to vary the qty of arguments.

I tried:
stringvar = "value1,value2"
run macname, stringvar

the above gets argument not optional when macname needs 2 arguments.

The Mso help shows application.Run(Macro, Arg1, Arg2, etc,)
but it presents the same 'problem'.

Is there a better way ?
Thanks.
--
Neal Z
  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 345
Default Run verb, macro with arguments

Jim, Thanks
Am learning VBA as I go along.
Never knew about optional arguments.
Am going to Help now Param arrays.
Best,

--
Neal Z


"Jim Cone" wrote:


Neal,
You can use Optional arguments in the MacName sub and it will execute
using what ever arguments are supplied...

Sub UniversalCall()
MacName "Huey", "Dewey", "Louie", "Donald"
MacName , , "Louie"
MacName
End Sub
'--
Sub MacName(Optional ByRef sArgAy1 As String, Optional ByRef sArgAy2 As String, _
Optional ByRef sArgAy3 As String, Optional ByRef sArgAy4 As String)
MsgBox sArgAy3
End Sub
-
The other way is to use a "Parameter Array" in the MacName sub.
See "Understanding Parameter Arrays" in help.
--
Jim Cone
San Francisco, USA
http://www.realezsites.com/bus/primitivesoftware
(Excel Add-ins / Excel Programming)




"Neal Zimm"
wrote in message
Hi All,
As part of the menu functionality in my addin I have a worksheet
with macro names, and argument values, (or none) for each macro.
..onaction contains the macro which gathers the data from the
worksheet.

Prior to the paragraph below is a sub that builds the
sArgAy string array and the ArgQty variable.

The code below is working and I don't think I'll have any
macros with more than 4 arguments, but I'm wondering if
there's a better way to code it without all the If..Else
syntax.

RunMac: 'Execute macros with arguments values
If ArgQty = 0 Then
Run MacName
ElseIf ArgQty = 1 Then
Run MacName, sArgAy(1)
ElseIf ArgQty = 2 Then
Run MacName, sArgAy(1), sArgAy(2)
ElseIf ArgQty = 3 Then
Run MacName, sArgAy(1), sArgAy(2), sArgAy(3)
ElseIf ArgQty = 4 Then
Run MacName, sArgAy(1), sArgAy(2), sArgAy(3), sArgAy(4)
End If
Return

I thought about var = array(xxx, xxx,xxx) but I still could not
figure out how to vary the qty of arguments.

I tried:
stringvar = "value1,value2"
run macname, stringvar

the above gets argument not optional when macname needs 2 arguments.

The Mso help shows application.Run(Macro, Arg1, Arg2, etc,)
but it presents the same 'problem'.

Is there a better way ?
Thanks.
--
Neal Z

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Macro - onAction arguments version83 Excel Worksheet Functions 2 April 10th 10 09:59 PM
adding custom verb to OLE object that changes its appearance Przemyslaw Dzierzak Excel Programming 1 May 18th 07 10:35 AM
The opposite of .Verb in OLE Object [email protected] Excel Programming 1 July 21st 05 02:18 PM
passing arguments from an excel macro to a word macro KWE39 Excel Discussion (Misc queries) 1 July 7th 05 03:56 PM
Run macro in another workbook with arguments Jos Vens Excel Programming 2 February 22nd 04 09:32 AM


All times are GMT +1. The time now is 10:16 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"