Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Word / Programming / February 2005

Tip: Looking for answers? Try searching our database.

scope of variables

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Mark L - 24 Feb 2005 13:17 GMT
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.
Signature

Mark L

Jean-Guy Marcil - 24 Feb 2005 15:06 GMT
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
[quoted text clipped - 4 lines]
> 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.

Signature

Salut!
_______________________________________
Jean-Guy Marcil - Word MVP
jmarcilREMOVE@CAPSsympatico.caTHISTOO
Word MVP site: http://www.word.mvps.org

Jonathan West - 24 Feb 2005 15:22 GMT
> Mark L was telling us:
> Mark L nous racontait que :
[quoted text clipped - 10 lines]
> 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.

Signature

Regards
Jonathan West - Word MVP
www.intelligentdocuments.co.uk
Please reply to the newsgroup

 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.