VBA: Disconnect from called sub

peimar

New Member
Joined
Jan 4, 2019
Messages
2
Let's say that I have to two subs:

Code:
Sub subA()[INDENT]If (some condition)<some condition=""> is True Then</some>[/INDENT]
[INDENT=2]Call subB[/INDENT]
[INDENT]Else[/INDENT]
[INDENT=2]' Some code[/INDENT]
[INDENT]End If[/INDENT]
End Sub

Sub subB()[INDENT]'Some code[/INDENT]
End Sub

Is it somehow possible to disconnect subB from subA once called? So that once subA calls subB, subA is ended while only subB continues running while subA has discontinued.
 

Excel Facts

Excel Can Read to You
Customize Quick Access Toolbar. From All Commands, add Speak Cells or Speak Cells on Enter to QAT. Select cells. Press Speak Cells.
.
As your macro is written, once you go to Sub B, Sub A is ignored. Nothing else occurs relative to Sub A until everything
has been concluded in Sub B.

Code:
Sub subA()
If (some condition) is True Then
     Call subB
     'at this point, only those commands in Sub B are running. Nothing in Sub A
     'is done until Sub B concluded and the attention returns to Sub A.
     'When things return to Sub A, it will come back to this point (after the line
     ' Call subB) and proceed to process code lines the might follow.
Else
     ' Some code
End If
End Sub

Does this help or did you view this differently or mean something different ?
 
Upvote 0
I meant something different. As you say, once subB is processed, it returns back to subA and finishes there. Instead, once I get to subB, I do no longer want subB to be connected to subA. This way, when subB ends, nothing more happens.

I am not looking for a solution where you put 'End' in the end of subB or anything like that. I am only asking for a way where you for instance call subB within subA and simultaneously ends subA while subB continues, or anything similar. Hard to explain the reason or bigger context of why I need this, so sorry about that.
 
Upvote 0
As far as I know, what you're asking for is not possible.
 
Upvote 0
.
I agree with Fluff ... I do not believe that is possible.

The only thing you might do is along the lines of "end" .. except after the line Call subB, type Exit Sub.

It still means SubB has to finish its work and then return to SubA, but you will know that nothing more in SubA will get processed.
 
Upvote 0
.
One other thought ... just for the sake of discussion but most likely not a viable approach.

At the top of your SubB, you could include lines of code that would delete SubA from the workbook. Of course the downside
is SubA would no longer be available for future use without re-creating it.
 
Upvote 0
I can’t think why you want to do this. But how about using ontime to run subb, I think that meets you requirement
 
Upvote 0
As far as I know, what you're asking for is not possible.
I would think you could set up a global variable and set it in one sub and test for that setting in the other sub reacting (using End Sub) as needed.
 
Last edited:
Upvote 0

Forum statistics

Threads
1,223,954
Messages
6,175,600
Members
452,658
Latest member
GStorm

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top