PDA

View Full Version : Callng a sub from another sub



Elvisman
09-01-2010, 12:49 AM
Hello,

for preventing unnecessary repetition in a Sub I would like to make a method (or Sub I don't know how to call it but you know what I mean) outside of the sub that can be recalled from the first Sub. So for that I have two questions:
1. What code could I use for activating another Sub within the first Sub?
2. Is it better to make the 'other' Sub public?

I'm hoping someone could help me again with this one. Because of this forum now I'm almost ready writing an application for Tray Selection..

Regards

Jeroen

Jan Karel Pieterse
09-01-2010, 02:25 AM
Hi Jeroen,

This demonstrates how that works (I also show how to pass a value as an argument to macro2):

Sub Macro1()
Dim i as Long
For i=1 to 10
Macro2 i
Next
End Sub

Private Sub Macro2(i As Long)
'This macro gets called by Macro1 (ten times)
MsgBox "I've been run " & i & " time(s)!"
End Sub

p45cal
09-01-2010, 02:25 AM
1. Just he name of the sub
2. Depends if you want it to be available outside its own module.