PDA

View Full Version : vba script on a central place



michelle
03-01-2007, 04:07 AM
Dear vba users,

We are busy to create a lot of templates with the same VBA code, because we don?t want to write the same code in each document, we are searching for a system to place the code in a central place.
Is this possible and can someone please give use an explanation how to do this or maybe an url where to find more information about this.

Nice regards,
Michelle. :help

Bob Phillips
03-01-2007, 04:38 AM
Any directory on a server would be fine.

You can define that location to all Word clients in Tools>Options>File Locations>Workgroup Templates.

michelle
03-01-2007, 04:55 AM
Hello xld,

Thanks for the reaction but we want that all common script for all templates is placed in a central place, maybe a document. We expect 40 templates, if there is a change in a common function we have to change it 40 times! We have also to check 40 times the changed templates.

Hopefully you all have a solution.
Regards,
Michelle.

michelle
03-01-2007, 05:13 AM
As done in a normal.dot

Bob Phillips
03-01-2007, 07:10 AM
Normal.dot ia ONE template. If you put all your templates in there it ceases to be a template, but becomes a collection of templates.

A directory is a central place, I don't see what the problem is.

michelle
03-01-2007, 08:05 AM
The problem is, as we wrote, that the scripting will be in a lot of templates the same. That common VBA script must be placed central, maybe in a document.
We are searching for such a system.

lucas
03-01-2007, 08:17 AM
Michell,
Use a global template in the startup folder...

Your giving conflicting information...

the scripting will be in a lot of templates the same. That common VBA script must be placed central, maybe in a document.

so will the code be in each template or do you wish to have the code in a place where it can be run from any open document.

If so you should set up a global.dot with your procedures and they can be called from any open document.

Quoting from Gerry and Malcolm:


having procedures NOT in Normal.dot is a very good idea. You may want to consider having the .DOT file with your code load as a global template. That way you will have access to all your code, independently of normal.dot.

Save your code in a template eg. Novel.dot. Move that template to your Startup folder eg. C:\Program Files\Microsoft Office\Office\Startup
Malcolm
There are two locations for loading a global automatically.
The Program Files\YaddaYadda\Office\Startup folder; OR
F:\Documents and Settings\Main\Application Data\Microsoft\Word\STARTUP
The first loads the global for all user sessions. The second loads it for the username session. Obviously, if you are the only user of the machine then it does not matter.
Note 1: you can also UNLOAD a global, either manually (Tools > Templates and Addins), or by code.
Note 2: globals are dynamic. You can open the global .dot file itself and add/change/remove procedures to it. These are immediately accessible.

When a global template is "loaded" it is important to note that the file itself is NOT, repeat NOT, loaded - ie. opened. A global template has its procedures parsed and pointers are created for them. So, in fact, the term "loading" a global template is a bit of a misnomer. No document content is loaded - only pointers to procedures.

fumei
03-01-2007, 08:33 AM
That is indeed the way to go.

Put your global code in a global template. That file can be anywhere. It does not:

1. have to be in either the Workgroup template folder, OR the User template folder.

2. have to be loaded on Startup. It can be loaded dynamically if you wish.

If you have common VBA code, then absolutely, putting that code into a global template is the most efficient way to make it available.

michelle
03-07-2007, 03:46 AM
Thanks a lot everybody for giving me advise, the global template is working great!

Michelle.

:friends: