View Full Version : Solved: Branch to specific line in another macro
vanhunk
09-12-2012, 01:37 AM
Is it possible to branch from one macro to a specific line in another macro, i.e. skip a couple of lines of the second macro? Thanks
BrianMH
09-12-2012, 01:43 AM
I don't think so. But you could put the first couple of lines of the macro into another macro and then you can call it either from the new macro or the one you are currently wanting to call it for. Breaking things up into seperate functions can be very useful.
Of course.
private sn
sub snb()
sn="something"
illustration
sn=""
end sub
sub illustration()
if sn<> "something" then
msgbox "you see ?"
end if
msgbox "this is where we jump to if called by macro 'snb'"
end sub
vanhunk
09-12-2012, 08:42 AM
Thanks snb, you always comes through for me. I knew you could do it.
Paul_Hossler
09-12-2012, 09:52 AM
You could pass an optional parameter to skip lines
Option Explicit
Sub Higher()
Call Lower(True)
Call Lower
End Sub
Sub Lower(Optional SkipSomeLines As Boolean = False)
If Not SkipSomeLines Then
MsgBox "Executing the first line"
MsgBox "Executing the second line"
End If
MsgBox "Executing the third line"
End Sub
Paul
vanhunk
09-13-2012, 12:17 AM
Thanks Paul, I like it.
Powered by vBulletin® Version 4.2.5 Copyright © 2024 vBulletin Solutions Inc. All rights reserved.