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 / March 2005

Tip: Looking for answers? Try searching our database.

Global template document properties

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Lynne O'Regan - 17 Mar 2005 17:40 GMT
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
Jonathan West - 18 Mar 2005 01:00 GMT
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.

Signature

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

> 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
[quoted text clipped - 15 lines]
>
> Lynne O'Regan
Lynne O'Regan - 18 Mar 2005 14:03 GMT
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:
>> txtdepartment=activedocument.customdocumentproperties("department").value
...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

> Code in the add-in can refer to the properties of the add-in by looking at
> the BuiltInDocument properties or CustomDocumentProperties of the
[quoted text clipped - 20 lines]
>>
>> Lynne O'Regan
Jonathan West - 18 Mar 2005 14:48 GMT
> 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
[quoted text clipped - 4 lines]
> ...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.

Signature

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 

Lynne O'Regan - 18 Mar 2005 17:07 GMT
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

>> 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
[quoted text clipped - 31 lines]
> the template or add-in which contains the code that you are running at the
> moment.
Jonathan West - 18 Mar 2005 21:43 GMT
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.

Signature

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

> Again, thanks Jonathan.
>
[quoted text clipped - 65 lines]
>> to the template or add-in which contains the code that you are running at
>> the moment.
David Sisson - 18 Mar 2005 22:16 GMT
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.
Lynne O'Regan - 19 Mar 2005 00:01 GMT
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

> 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.
Jean-Guy Marcil - 19 Mar 2005 07:03 GMT
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...

Signature

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


Rate this thread:






 
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.