Call Private Sub

AMAS

Active Member
Joined
Apr 11, 2010
Messages
472
I am trying to call this private sub but its not working. Any thoughts.

This works:
Code:
Call FormatCells(cell, myList, myColor)

This doesn't work (doesn't compile):

Code:
Application.Run "FormatCells" (cell, myList, myColor)

This doesn't work (compiles but doesn't do anything):

Code:
Application.Run "FormatCells, cell, myList, myColor"

AMAS
 

Excel Facts

What do {} around a formula in the formula bar mean?
{Formula} means the formula was entered using Ctrl+Shift+Enter signifying an old-style array formula.
Hi,

'Call' works great with its a regular sub. I am trying to hide all my subs and make them Private Subs. 'Call' seems to only 'see' regular subs, but not private subs.

AMAS
 
Upvote 0
I am trying to call this private sub but its not working. Any thoughts.

This works:
Code:
Call FormatCells(cell, myList, myColor)

This doesn't work (doesn't compile):

Code:
Application.Run "FormatCells" (cell, myList, myColor)

This doesn't work (compiles but doesn't do anything):

Code:
Application.Run "FormatCells, cell, myList, myColor"

AMAS

Are you saying that the first one works if FormatCells() is Private?
 
Upvote 0
No. Call works as long as its Sub FormatCells() but not if its Private Sub FormatCells().

AMAS
 
Upvote 0
You can only call private subs or functions when you are doing it in the same module.

If by 'hide', you mean make sure they don't show up in the play macro listbox, you can use some other tricks:
1) Change Sub into Function, without changing anything else
2) Make the Sub to have a parameter, even if you don't use it
 
Upvote 0
Code:
Application.Run "FormatCells", cell, myList, mycolor
would be the syntax.
 
Upvote 0
I have to ask... what functionality do you think making your subs Private provides for you that has made you so insistent on wanting to use them that way?
 
Upvote 0
Hi,

'Call' works great with its a regular sub. I am trying to hide all my subs and make them Private Subs. 'Call' seems to only 'see' regular subs, but not private subs.

AMAS

Okay, if the procedure being called is located in a different module than the calling procedure, the called procedure cannot be Private.

I am not quite understanding on why the need to hide, as your listed procedure has arguments and thus, will not show in the macros dialog box. Am I missing something?
 
Upvote 0
Thanks everyone for your interest. This has been a learning experience for me.

Rorya: That was the correct syntax. Thank you.

Hermanito: Thank you for this great advice. I will keep it on hand and try to use the different options.

Rick: The reason I wanted to hide the subs was because I have a file consisted of around 10 modules and 30 subs. The macro listbox started to get crowded for no reason since most of the subs call each other. I was trying to find a way of housekeeping and tiding up.

GTO: You know I never noticed this. Thanks for pointing this out to me. Sometimes we miss the obvious.

Thanks again everyone.

AMAS
 
Upvote 0

Forum statistics

Threads
1,224,506
Messages
6,179,159
Members
452,892
Latest member
yadavagiri

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