Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Referencing a Macro within a Macro

Status
Not open for further replies.

Eytch

Programmer
Jan 29, 2003
60
US
I have created a macro and wish to give the user the option of executing it again with a new set of data or exit the program. How do I get the macro to reexecute itself from within the macro. Is there something like a Goto command or a procedure call option to get the macro to reexecute with a new set of data to be analyzed? Any suggestions regarding the easiest way to go about this?

Thanks,
Tripoli
 
Just re-call the macro after you have received the data from the user.

Call MacroName



Peace! [peace]

Mike

Never say Never!!!
Nothing is impossible!!!
 
Haven't tested this

Sub data()

start:

'your code here

If MsgBox("Another data set?", vbQuestion + vbYesNo, "") = vbNo Then Exit Sub Else GoTo start


End Sub

 
The method of "recalling" the same function/sub within itself is called "recursion", some people prefer that over using looping iterations, and some people, for certain reasons, aren't used to using them and arent comfortable with them...so yes you can use a goto statement as Chattin put it or instead of puttin "goto start" put call macroname or simply macroname again and any parameters you may need to pass, the only difference I see between both methods is that when you use recursion, you execute the additional instruction of reading in the macro name-or title, and in the goto statement the compiler doesnt read in the name of the goto label, so its with whatever your more cofortable with
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top