Macro (Modle) naming insight

  • Thread starter Thread starter pgarcia
  • Start date Start date
P

pgarcia

Hello all,
As you know, I'm new to VB coding and I had a question about modles with
names. How do they work? I changed a name on a modle so I can find it easly
in a list of modles, but it did not work after that and if I "Call" another
modle (macro) it also did not work.

Thanks
 
Naming your modules if a very good practice to get into. At allows you to
organize your code which makes it a lot easier to maintain. Try to give your
modules descriptive names so that you know what is in them...

One nice thing about naming your modules is that you gain intellisence drop
downs. Try this... name a new module modNew and add the following procedures.

'*******************
public sub MyPublicSub()
msgbox "Tada"
call MyPrivateSub
end sub

private sub MyPrivateSub()
msgbox "Scooby Doo"
end sub
'*******************

Now in another module or sheet type
modnew.

You should get an intellisence drop down including MyPublicSub but not
MyPrivateSub. You do not necessarily need to specify the module where your
procedure is. If you just typed
Call MyPublicSub
then the compiler will search the module or object you are in. If it is not
found then it will look in other modules. If it does not exist elsewhere then
you will get an error message. If it is elsewhere but declared private then
it will not be found. If it is in two or more modules then you will get an
ambiguious call error.

I try to include the module name in my call. It self documents the code and
keeps me from spelling / typing things wrong. It also ensures that the scope
of my procedures is correct and avoid ambiguious calls.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top