Private Sub??

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

hello...When writing a VBA macro in Excel what is the difference in using for example Private Sub test1() versus Sub Test1()?
what does the word "Private" mean in the macro name?

I have 2 macros in a worksheet, one is labeled Private Sub the other is not. When I email the worksheet to another and they open it the macro that is NOT using the "Private" wordage sometimes dosent work, depending on the persons PC.
For example..On one PC when they went to run the macro they got a DLL error. On some other PC's I got the Debug window when I went to run the macro. Most of the time I have to re-associate the macro button (right click) and reasign the macro again to the macro button that is on the worksheet.
Does this have anything to do with the macro not labeled as "Private Sub"?
Thank you
He4Giv
 
Marking a Sub or Function as Private makes it only available to b
called from it own module.

You may also mark it Public to make it available from anywhere.

AND last but not least, you may mark it Public in a module that use
the "Option Private" in which case it will only be available to al
modules within it's own project. - Piku
 
Private is a scope declaration. That means that any function or subroutine preceded by Private can only be accessed by other procedures in that module. Each sheet in your workbook has its own code module, and your workbook has a code module. You can also add standard modules which aren't associated with either a worksheet or workbook. These standard modules are where Excel's macro recorder places the macros that you record. Recorded macros are not preceded with the Private statement. If they were, you wouldn't be able to call them directly from within the workbook itself.

I don't think it's related to your problem. Perhaps if you posted your macro code we could help with the other problem

-Brad
 
Back
Top