scope of variables

M

Mark L

If I have VBA code in a Word document which is using a module, some forms and
ThisDocument (ie Document_Open and Document_Close), where should I declare
Public variables so that they are accessible to the whole thing? In the past
I would have declared such variables in the Module declarations, but I think
these are not being made available to the ThisDocumant section of the code.
Thank you for any help you can give me.
 
J

Jean-Guy Marcil

Mark L was telling us:
Mark L nous racontait que :
If I have VBA code in a Word document which is using a module, some
forms and ThisDocument (ie Document_Open and Document_Close), where
should I declare Public variables so that they are accessible to the
whole thing? In the past I would have declared such variables in the
Module declarations, but I think these are not being made available
to the ThisDocumant section of the code. Thank you for any help you
can give me. --
Mark L

You cannot have public declarations in a class module (ThisDocument is a
"special" class module).

Create a module that you could call "PubVariables" and use it to declare
those public variables.

--
Salut!
_______________________________________
Jean-Guy Marcil - Word MVP
(e-mail address removed)
Word MVP site: http://www.word.mvps.org
 
J

Jonathan West

Jean-Guy Marcil said:
Mark L was telling us:
Mark L nous racontait que :


You cannot have public declarations in a class module (ThisDocument is a
"special" class module).

That's not strictly true. You can have public declarations in a class
module, but they don't act as global variables, they act as public
read-write properties of the class.
Create a module that you could call "PubVariables" and use it to declare
those public variables.

That is the way to do it. Variables declared as Public and defined before
the first Sub or Function in a module will be available to all modules,
classes and UserForms within the same project.
 

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

Top