Results 1 to 2 of 2
Thread: public variables (WORD 97/2000)
2002-10-17, 09:32 #1
- Join Date
- Jan 2002
- London, Gtr London, England
- Thanked 0 Times in 0 Posts
public variables (WORD 97/2000)
My question may have been lost in my last post, so here it is again. I assume answer was not straight forward, otherwise you great people would have responded by now. But anyway, here is the problem:
I have defined public variables and macros that manipulate them in my template. The process (simplification):
Public CurPaperSize As Integer (set to 7 for A4 or 2 for US Letter) - INTIAL value is 7
Public p_PostProcess As Boolean
Open 1st document
set the CurPaperSize to 2 (US Letter)
Open 2nd document
look at the CurPaperSize variable - (lo and behold it contain 2 & not 7 as I would have expected)
So it seems that public variables in a template are not specific to a document but to the whole WORD session. In other words, there is only a single instance of a public variable however many documents are opened under WORD. Is this true? If so, is there any way of signifying to WORD that I need all public variables to be specific to each document opened?
One of the things I have noticed is that we can specify variables/customproperties for the active document. Do I need to do that & put all public variables within the activedocument object when a document is opened? Or is there a better way of doing things than variables or custom properties?
So for example, insert CurPaperSize as a variable in the ActiveDocument object and use it to update is as when required, i.e.
ActiveDocument.Variables("CurPaperSize).Value = 7 (for US Letter) or
if ActiveDocument.Variables("CurPaperSize").Values = 2 (for A4) then
do something else
if CurPaperSize = A4 then
do something else
Thanks for any help.
2002-10-17, 10:36 #2
- Join Date
- Mar 2002
- Thanked 30 Times in 30 Posts
Re: public variables (WORD 97/2000)
When you create a document based on a template, the modules in the template are NOT copied to the document. A public variable defined a module in the template belongs to the template, not to the document based on it. Since the document has a reference to the template, the public variable is available in the document too, but a change in its value will be effected in the template, and be visible to all other documents based on the template. But documents based on another template don't know about the variable; if you try to use a public variable defined in TemplateA in a document based on TemplateB, you will get an error message. In other words, variables are not global to the Word session.
On the other hand, if you create document variables or custom document properties in a template, these are copied to each document based on the template. So each indivdual document has its own set of document variables and custom properties. The initial values are the values you have set in the template, but if you change a value in a document, the change applies to that document only.