ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   running private sub (https://www.excelbanter.com/excel-programming/334236-running-private-sub.html)

Gary Keramidas[_2_]

running private sub
 
there has to be a simple answer. i see all these references to private sub,
how do you run the code?


private sub worksheet_test(this is a test)
code here

end sub

i have no idea how to call this, can someone explain?


thanks

--


Gary




Anne Troy[_2_]

running private sub
 
Private subs are run on the event. For instance, Private Sub
Worksheet_Activate() will run when the worksheet is activated. Private Sub
Workbook_Open() runs when the workbook is open. You can find all events like
this by going into the Visual Basic Editor and getting the code window at
right. Hit the dropdown and choose Workbook, then choose the right-hand
dropdown and choose one of the events. Then double-click one of the sheet
tabs, and do the same. You'll see all the different events there, and it
auto-creates the macro names for you so you can tell what they are.

Hope this helps!
*******************
~Anne Troy

www.OfficeArticles.com


"Gary Keramidas" wrote in message
...
there has to be a simple answer. i see all these references to private

sub,
how do you run the code?


private sub worksheet_test(this is a test)
code here

end sub

i have no idea how to call this, can someone explain?


thanks

--


Gary






Gary Keramidas[_2_]

running private sub
 
ok, i think i have it now.

thanks

--


Gary


"Anne Troy" wrote in message
news:959d5$42d368c6$97c5108d$28551@allthenewsgroup s.com...
Private subs are run on the event. For instance, Private Sub
Worksheet_Activate() will run when the worksheet is activated. Private Sub
Workbook_Open() runs when the workbook is open. You can find all events
like
this by going into the Visual Basic Editor and getting the code window at
right. Hit the dropdown and choose Workbook, then choose the right-hand
dropdown and choose one of the events. Then double-click one of the sheet
tabs, and do the same. You'll see all the different events there, and it
auto-creates the macro names for you so you can tell what they are.

Hope this helps!
*******************
~Anne Troy

www.OfficeArticles.com


"Gary Keramidas" wrote in message
...
there has to be a simple answer. i see all these references to private

sub,
how do you run the code?


private sub worksheet_test(this is a test)
code here

end sub

i have no idea how to call this, can someone explain?


thanks

--


Gary








Anne Troy[_2_]

running private sub
 
Also, Private subs don't show under Tools--Macro--Macros, so you can use
them to run subs from other subs that aren't private, you know?
*******************
~Anne Troy

www.OfficeArticles.com


"Gary Keramidas" wrote in message
...
ok, i think i have it now.

thanks

--


Gary


"Anne Troy" wrote in message
news:959d5$42d368c6$97c5108d$28551@allthenewsgroup s.com...
Private subs are run on the event. For instance, Private Sub
Worksheet_Activate() will run when the worksheet is activated. Private

Sub
Workbook_Open() runs when the workbook is open. You can find all events
like
this by going into the Visual Basic Editor and getting the code window

at
right. Hit the dropdown and choose Workbook, then choose the right-hand
dropdown and choose one of the events. Then double-click one of the

sheet
tabs, and do the same. You'll see all the different events there, and it
auto-creates the macro names for you so you can tell what they are.

Hope this helps!
*******************
~Anne Troy

www.OfficeArticles.com


"Gary Keramidas" wrote in message
...
there has to be a simple answer. i see all these references to private

sub,
how do you run the code?


private sub worksheet_test(this is a test)
code here

end sub

i have no idea how to call this, can someone explain?


thanks

--


Gary










Bob Phillips[_6_]

running private sub
 
Private subs are subs that you only want to be allowed to be called from the
module that they are contained within. So, any private subs in module1
cannot be accessed from module2 say, even in the same workbook.

By default, worksheet and workbook events are declared private, so they too
could not be called from another module. However, you can change them to
public with no problem, but if you do call them from another module, you
need to precede the macro by its sheet name, as a worksheet code module is
an instance of a class.

Private subs do not show in the list of macros under ToolsMacro, but
neither do subs that have arguments.


--

HTH

RP
(remove nothere from the email address if mailing direct)


"Gary Keramidas" wrote in message
...
there has to be a simple answer. i see all these references to private

sub,
how do you run the code?


private sub worksheet_test(this is a test)
code here

end sub

i have no idea how to call this, can someone explain?


thanks

--


Gary







All times are GMT +1. The time now is 04:43 PM.

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