Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 13
Default call macro with variable

How can I call a macro when the name is a variable


MacroName = "example"
While i <= 14
MacroName = MacroName & i
Call MacroName (path)
i = i + 1
Loop

Cheers



  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 789
Default call macro with variable

Hi
You don't use brackets.
Call MacroName

or if it has parameters

Call MacroName variable1, variable2, etc

regards
Paul

On Apr 2, 10:01*am, Whit wrote:
How can I call a macro when the name is a variable

* * MacroName = "example"
* * While i <= 14
* * * * MacroName = MacroName & i
* * * * Call MacroName (path)
* * * * i = i + 1
* * Loop

Cheers


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 13
Default call macro with variable

I get a compile error...

" wrote:

Hi
You don't use brackets.
Call MacroName

or if it has parameters

Call MacroName variable1, variable2, etc

regards
Paul

On Apr 2, 10:01 am, Whit wrote:
How can I call a macro when the name is a variable

MacroName = "example"
While i <= 14
MacroName = MacroName & i
Call MacroName (path)
i = i + 1
Loop

Cheers



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 789
Default call macro with variable

Hi
didn't test this before. Looks like you simply cannot call a variable
name macro.
I'd suggest you create one macro with a variable parameter

Sub myMacro (i as integer)
'code depending on i
end sub

Then in the loop do
Call myMacro i

regards
Paul
On Apr 2, 10:16*am, Whit wrote:
I get a compile error...



" wrote:
Hi
You don't use brackets.
* * * * Call MacroName


or if it has parameters


* * * * Call MacroName variable1, variable2, etc


regards
Paul


On Apr 2, 10:01 am, Whit wrote:
How can I call a macro when the name is a variable


* * MacroName = "example"
* * While i <= 14
* * * * MacroName = MacroName & i
* * * * Call MacroName (path)
* * * * i = i + 1
* * Loop


Cheers- Hide quoted text -


- Show quoted text -


  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 141
Default call macro with variable

Hi,

To my understanding there is no way to call a sub from a name
variable. Rather than passing a parameter to a sub with different
'sections' though, wouldn't it be easier to move the 'if' back into
the first sub?

sub Macro1()
Dim NextSub
do some things
NextSub = whatever you choose

Select Case NextSub
Case "Macro2"
Call Macro2
Case "Macro3"
Call Macro3
etc. etc.
End Select
End Sub

Hard to say withouu seeing you code.

Cheers,
Ivan.

On Apr 2, 10:21*pm, wrote:
Hi
didn't test this before. Looks like you simply cannot call a variable
name macro.
I'd suggest you create one macro with a variable parameter

Sub myMacro (i as integer)
* * 'code depending on i
end sub

Then in the loop do
Call myMacro i

regards
Paul
On Apr 2, 10:16*am, Whit wrote:



I get a compile error...


" wrote:
Hi
You don't use brackets.
* * * * Call MacroName


or if it has parameters


* * * * Call MacroName variable1, variable2, etc


regards
Paul


On Apr 2, 10:01 am, Whit wrote:
How can I call a macro when the name is a variable


* * MacroName = "example"
* * While i <= 14
* * * * MacroName = MacroName & i
* * * * Call MacroName (path)
* * * * i = i + 1
* * Loop


Cheers- Hide quoted text -


- Show quoted text -- Hide quoted text -


- Show quoted text -




  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default call macro with variable

You could use application.run

Option Explicit
Sub testme1(mystr As String)
MsgBox mystr & " from 1"
End Sub
Sub testme2(mystr As String)
MsgBox mystr & " from 2"
End Sub
Sub testme3(mystr As String)
MsgBox mystr & " from 3"
End Sub
Sub testme4(mystr As String)
MsgBox mystr & " from 4"
End Sub
Sub aaa()
Dim iCtr As Long
For iCtr = 1 To 4
Application.Run "testme" & iCtr, "hi there"
Next iCtr
End Sub



Whit wrote:

How can I call a macro when the name is a variable

MacroName = "example"
While i <= 14
MacroName = MacroName & i
Call MacroName (path)
i = i + 1
Loop

Cheers


--

Dave Peterson
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
Call VBScript from VBA, pass variable, return result to macro? Ed Excel Programming 26 July 11th 06 07:07 PM
Define worksheet as variable, then call in macro bugman Excel Programming 2 November 22nd 05 05:13 PM
Call procedure using variable donbowyer Excel Programming 2 October 28th 05 09:21 AM
can I call a procedure using a variable Santiago Gomez Excel Programming 8 December 24th 03 09:08 PM
Using variable to call worksheets Calypsoblur Excel Programming 3 November 8th 03 10:47 PM


All times are GMT +1. The time now is 08:09 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"