+ Reply to Thread
Results 1 to 10 of 10

How to run a separate private procedure within the same module

  1. #1
    Forum Contributor
    Join Date
    12-20-2011
    Location
    United States, Ohio
    MS-Off Ver
    Excel 2010
    Posts
    295

    Question How to run a separate private procedure within the same module

    I'ver searched and cant find a solution.

    Is this allowed?

    Are you able to call a different PRIVATE procedure from within the same module?

    Ive tried:
    Please Login or Register  to view this content.
    Where "CheckBox1_Change" is the name of the procedure that I want to call and I get Run Time Error 1004.
    Last edited by clemsoncooz; 02-16-2012 at 04:46 PM.

  2. #2
    Forum Expert
    Join Date
    06-25-2009
    Location
    Sofia, Bulgaria, EU
    MS-Off Ver
    Excel 2003-2013
    Posts
    1,290

    Re: How to run a separate private procedure within the same module

    Hi you can call it like any other sub, e.g.

    Please Login or Register  to view this content.
    or

    Please Login or Register  to view this content.
    buran
    If you are pleased with a member's answer then use the Star icon to rate it.

  3. #3
    Forum Expert dominicb's Avatar
    Join Date
    01-25-2005
    Location
    Lancashire, England
    MS-Off Ver
    MS Office 2000, 2003, 2007 & 2016 365
    Posts
    4,867

    Re: How to run a separate private procedure within the same module

    Good evening clemsoncooz

    Sure. Just use the Call command, thus :
    Please Login or Register  to view this content.
    You could also just use the sub name, for example :
    Please Login or Register  to view this content.
    Either will work fine.

    HTH

    DominicB
    Please familiarise yourself with the rules before posting. You can find them here.

  4. #4
    Forum Contributor
    Join Date
    12-20-2011
    Location
    United States, Ohio
    MS-Off Ver
    Excel 2010
    Posts
    295

    Re: How to run a separate private procedure within the same module

    ohhh okay. Thanks!

    So is the Application.Run "" for private procedures located in OTHER Modules?

  5. #5
    Forum Expert dominicb's Avatar
    Join Date
    01-25-2005
    Location
    Lancashire, England
    MS-Off Ver
    MS Office 2000, 2003, 2007 & 2016 365
    Posts
    4,867

    Re: How to run a separate private procedure within the same module

    Hi clemsoncooz

    Not necessarily, other modules, but other modules in different workbooks.
    You would use the notation as below :
    Please Login or Register  to view this content.
    HTH

    DominicB

  6. #6
    Forum Contributor
    Join Date
    12-20-2011
    Location
    United States, Ohio
    MS-Off Ver
    Excel 2010
    Posts
    295

    Re: How to run a separate private procedure within the same module

    Thank You!

  7. #7
    Forum Expert
    Join Date
    06-25-2009
    Location
    Sofia, Bulgaria, EU
    MS-Off Ver
    Excel 2003-2013
    Posts
    1,290

    Re: How to run a separate private procedure within the same module

    I agree that Application.Run is for subs in other project/workbook. It can be used also to run subs from another application, e.g.

    Please Login or Register  to view this content.
    where wdApp is Word.Application variable and above code is executed from Excel macro.

    buran
    Last edited by buran; 02-16-2012 at 04:56 PM. Reason: remove incorrect statement

  8. #8
    Forum Contributor
    Join Date
    12-20-2011
    Location
    United States, Ohio
    MS-Off Ver
    Excel 2010
    Posts
    295

    Re: How to run a separate private procedure within the same module

    So is it not possible to run a PRIVATE Sub located within the SAME workbook - just in a different module?

    I thought "Private" just removes it from the available list of macro's that the user can run with "ALT+F8" (within excel screen - not VBA screen).

  9. #9
    Forum Expert
    Join Date
    06-25-2009
    Location
    Sofia, Bulgaria, EU
    MS-Off Ver
    Excel 2003-2013
    Posts
    1,290

    Re: How to run a separate private procedure within the same module

    My initial statement was incorrect, I edit my post. dominicb is right.

  10. #10
    Forum Expert
    Join Date
    06-25-2009
    Location
    Sofia, Bulgaria, EU
    MS-Off Ver
    Excel 2003-2013
    Posts
    1,290

    Re: How to run a separate private procedure within the same module

    clemsoncooz,
    private/public defines the scope of the sub. It's not only about user being able to run it with ALT+F8, but also from where you can run the sub in VBA.
    Look at the attached file. in Module 1 you have a private sub. in module 2 there are two subs that try to run the private sub from Module1. One is using call and the other application.run
    Actually the project does not even compile because call method does not "see" the private sub in the other module. However the application.run does the job. try to run each of the two with F5/F8 to see the difference.

    buran
    Attached Files Attached Files

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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