Global template document properties

L

Lynne O'Regan

At present I have a series of templates each with their own custom document
properties. If I have a user form with, say, a textbox with the name
'txtdepartment' I can then access the custom document property as follows:
txtdepartment=activedocument.customdocumentproperties("department).value and
it enters that into the textbox

Now I want to get a little more adventurous and keep all of the many custom
properties in the global template with each different active document
looking for its own properties as and when I open it. I've tried various
combinations of coding but cannot convince Word VBA to look in the global
template to access its custom properties. Working with VBA Help gives me
every sort of answer except the one I need!

Can anyone shed a little light on this point, please?

Regards

Lynne O'Regan
 
J

Jonathan West

Code in the add-in can refer to the properties of the add-in by looking at
the BuiltInDocument properties or CustomDocumentProperties of the
ThisDocument object. ThisDocument is refers to the document or template
actually containing the running code.

--
Regards
Jonathan West - Word MVP
www.intelligentdocuments.co.uk
Please reply to the newsgroup
Keep your VBA code safe, sign the ClassicVB petition www.classicvb.org
 
L

Lynne O'Regan

Thanks Jonathan for the reply. However, please excuse my muddle-headed
thinking and I realise you're giving me a clue to follow but I've lost the
plot here...

At present I've got this:....whick looks at the attached template and sucks out the value of the
"Department" CDP.

What I want to do is find the key word which I can put where
"activedocument" is in the example above and pick out a value from cdp's in
the Global Template which I can see is loaded. I've tried, even, hard coding
the global template's file name where "activeDocument" is written but to no
avail.

Even though the Global template is loaded does it have to be attached to the
active document prior to accessing the CDPs of that template? Or is "loaded"
considered to be also "attached"?

Regards

Lynne
 
J

Jonathan West

Lynne O'Regan said:
Thanks Jonathan for the reply. However, please excuse my muddle-headed
thinking and I realise you're giving me a clue to follow but I've lost the
plot here...

At present I've got this:
...whick looks at the attached template and sucks out the value of the
"Department" CDP.

No it doesn't. When you create a new document based on the template, it
contains a copy of the template's document properties. This line of code
reads the "department" property of the document itself
What I want to do is find the key word which I can put where
"activedocument" is in the example above and pick out a value from cdp's
in the Global Template which I can see is loaded. I've tried, even, hard
coding the global template's file name where "activeDocument" is written
but to no avail.

Like I said, use ThisDocument instead

txtdepartment=ThisDocument.customdocumentproperties("department").value

This will pull the "department" property out of the add-in that contains the
currently running code. It really is that simple.
Even though the Global template is loaded does it have to be attached to
the active document prior to accessing the CDPs of that template? Or is
"loaded" considered to be also "attached"?

The attached template is the template on which the document is based. There
can only be one attached template at a time for a document. You can have as
many loaded add-ins as you want. The ThisDocument object refers to the
template or add-in which contains the code that you are running at the
moment.

--
Regards
Jonathan West - Word MVP
www.intelligentdocuments.co.uk
Please reply to the newsgroup
Keep your VBA code safe, sign the ClassicVB petition www.classicvb.org
 
L

Lynne O'Regan

Again, thanks Jonathan.

Regrettably, I must report that it doesn't work in my case.

Let me just summarise - more for my own benefit, I suppopse...

I have a template called MyLetter.dot

Inside that template there is a user form called frmMyForm which has a
textfield called txtMyDepartment

There is also the global template called myGlobalTemplate.dot which is
loaded.

Inside that global template is a custom document property called
"department". That property has a text value of "Human Resources"

When I create a document based on MyLetter.dot and the UserForm appears
containing the texfield txtMyDepartment I want the a VBA to run off and read
the value of the "department" CDP and place it into my textfield.

Based on your guidance, Jonathan, I've written the following:

txtMyDepartment = ThisDocument.CustomDocumentProperties("department").Value.
By the way, is not the code that is running situated within MyLetter.dot?

The error message I get is this:
"Could not set the Value Property. Invalid property value."

Thanks again.

Lynne
 
J

Jonathan West

You didn't make it clear that your code was in the attached template, not in
the add-in.

I don't think you can retrieve properties from a template loaded as an
add-in from a macro outside te add-in.

If all you want is a general storage for a few settings, I would recommend
you use the registry instead, and use GetSettings and SaveSetting to save
and retrieve them.


--
Regards
Jonathan West - Word MVP
www.intelligentdocuments.co.uk
Please reply to the newsgroup
Keep your VBA code safe, sign the ClassicVB petition www.classicvb.org
 
D

David Sisson

Would it be feasible to add a listbox and let the user choose their
dept? Then based on the user's choice, you can populate the userform
with proper info.
 
L

Lynne O'Regan

I could have David - done it many times before. Just was trying to be clever
I suppose and use the add-in template as a place to hold default values.
Clients I'm creating this for don't want anything written to the registry.
This last method being a possible alternative as Jonathan suggested. Pity,
actually, as that might have been the better idea.

Regards

Lynne
 
J

Jean-Guy Marcil

Lynne O'Regan was telling us:
Lynne O'Regan nous racontait que :
I could have David - done it many times before. Just was trying to be
clever I suppose and use the add-in template as a place to hold
default values. Clients I'm creating this for don't want anything
written to the registry. This last method being a possible
alternative as Jonathan suggested. Pity, actually, as that might have
been the better idea.

You can use an *.ini file instead of the registry...

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

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