ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Discussion (Misc queries) (https://www.excelbanter.com/excel-discussion-misc-queries/)
-   -   Private Sub() - Sub() (https://www.excelbanter.com/excel-discussion-misc-queries/253664-private-sub-sub.html)

cousinexcel

Private Sub() - Sub()
 
Hi,
I know only "record macro" way, then I edit that recorded macro.
And I see that they always start Sub()

I sometimes see in your solutions
macros starting as "Private Sub..."
How do we run such macros ?

Thanks,

Cousin Excel

Joe User[_2_]

Private Sub() - Sub()
 
"CousinExcel" wrote:
I sometimes see in your solutions
macros starting as "Private Sub..."
How do we run such macros ?


Usually, such subroutines (and functions) are not intended to be executed
directly. They might be routines that support public routines, i.e. routines
that __are__ intended to executed directly.

But you can always go into VBA (press alt+F11), select the macro, and press
F5. You should not do that unless you know that the macro is intended to be
executed in that way.

I posted a Private Sub by mistake recently. I had intended to remove the
word Private.

Sometimes I have multiple experimental macros in different modules. Lacking
imagination, I might call all of them doit(). So I use the Private feature
to ensure that VBA does not get confused and raise an error. I don't need to
execute them from Excel because I am doing all my work in VBA.


----- original message -----

"CousinExcel" wrote:
Hi,
I know only "record macro" way, then I edit that recorded macro.
And I see that they always start Sub()

I sometimes see in your solutions
macros starting as "Private Sub..."
How do we run such macros ?

Thanks,

Cousin Excel


Don Guillett

Private Sub() - Sub()
 
This is done so they won't be seen. Goto the editor to fire.

--
Don Guillett
Microsoft MVP Excel
SalesAid Software

"CousinExcel" wrote in message
...
Hi,
I know only "record macro" way, then I edit that recorded macro.
And I see that they always start Sub()

I sometimes see in your solutions
macros starting as "Private Sub..."
How do we run such macros ?

Thanks,

Cousin Excel




All times are GMT +1. The time now is 03:36 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com