+ Reply to Thread
Results 1 to 4 of 4

Recall another Sub

Hybrid View

Elvisman Recall another Sub 09-01-2010, 03:44 AM
Alf Re: Recall another Sub 09-01-2010, 03:50 AM
ajaykgarg Re: Recall another Sub 09-01-2010, 04:18 AM
romperstomper Re: Recall another Sub 09-01-2010, 05:30 AM
  1. #1
    Registered User
    Join Date
    08-24-2010
    Location
    Nijmegen, Netherlands
    MS-Off Ver
    Excel 2007
    Posts
    10

    Recall another Sub

    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

  2. #2
    Forum Expert Alf's Avatar
    Join Date
    03-13-2004
    Location
    Gothenburg/Mullsjoe, Sweden
    MS-Off Ver
    Excel 2019 and not sure I like it
    Posts
    4,791

    Re: Recall another Sub

    Would this be of help?

    Sub RunAllMacros()
    Macro1
    Macro2
    End Sub

  3. #3
    Forum Contributor
    Join Date
    03-11-2010
    Location
    India
    MS-Off Ver
    2010
    Posts
    268

    Re: Recall another Sub

    1. What code could I use for activating another Sub within the first Sub?
    Call Sub2
    2. Is it better to make the 'other' Sub public?
    If the other sub is in same module, you do not need to make it public. Else, you will have to.

    hth
    Ajay

  4. #4
    Forum Expert romperstomper's Avatar
    Join Date
    08-13-2008
    Location
    England
    MS-Off Ver
    365, varying versions/builds
    Posts
    22,016

    Re: Recall another Sub

    As regards scope (qu. 2):
    If you make the sub Public (the default), it is visible to all other subs in your workbook and to the macros dialog (unless the sub takes arguments); if you make it private, it is visible only to routines in the same module, and not to the macros dialog. If you add:
    Option Private module
    to your module then the macros are not visible to the macros dialog, but the two rules above apply as regards visibility to other code in your workbook.
    Note: regardless of scope, all macros can be accessed from the macros dialog if you know the name of them (even if you can't successfully run them).
    The same basic rules apply to functions, but substitute the function wizard for the macros dialog.
    Everyone who confuses correlation and causation ends up dead.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1