PDA

View Full Version : Create a macro with a macro?



alexander110
10-30-2007, 04:16 PM
Hi all - I am using a template to create new documents via a user form, and would like those new documents to contain a macro. Is it possible to do this? Or is it too much of a security risk for vba to insert vba subroutines into a new document?

The reason i would like a macro in the document is so as to enable users of that document to easily accept all&switch off track changes using a shortcut key; the macro also performs a few simple find/replace operations to keep formatting within a predefined style. I don't have access to their normal.dot so figured the only way to do it was with an embedded macro in each individual document.

Word version 2003, Windows XP.

Thanks everyone,

alex

TonyJollans
10-31-2007, 04:09 AM
It is possible but, since 2002, it requires explicit consent from the user which is unlikely to be set in a corporate environment.

If you are creating a document based on a template and the user has access to that template, then macros in that template will be available to the document. Is that not enough?

OTWarrior
10-31-2007, 08:56 AM
if you were to copy the document as a file and open it, it would have the macros i think.

could you have the (blank) document saved somewhere, and make a copy which would be saved where the user wants?

(NB: i do mean to code this in vba, but try it in windows first to see if everything copies ok, which i am faily certain it will)

a template is the easier option though.

Sirfanta
11-01-2007, 02:08 AM
Correct me if I’m wrong.

There are to ways to make a template.

1. Save as --> Document Template (*.dot)

When you make a new doc using the template, you will get doc that refers to the template.

2. If you save it as a doc, then rename the file from a doc to a dot.
When you make a new doc using the template, the macro will be copied to the new doc.

TonyJollans
11-01-2007, 06:02 AM
Renaming a .doc file to .dot does not make it a Template - it makes it a Document with a .dot suffix. If you then create "new from existing" (an option I despise) you will probably get the macros in the document (I haven't checked but it seems like it would be the thing most likely to happen)

Sirfanta
11-02-2007, 12:50 AM
(I haven't checked but it seems like it would be the thing most likely to happen)

Try it ;)
Whats the catch by just renaming it?

TonyJollans
11-02-2007, 03:05 AM
I'm not sure what you mean.

Renaming a file does not change it. Do you think it would become a spreadsheet if you renamed it as .xls? Documents and Templates are different types of file.

The fact that you can create a document from another document does not make the original a template.

fumei
11-02-2007, 12:27 PM
And therein lies the misunderstanding about what is a template, and what is a document.

Nelviticus
11-05-2007, 05:08 AM
If you're just looking to give everyone some generic toolbars and code you can put these into a blank template and store it in %AppData%\Microsoft\Word\STARTUP. That way, you don't need to put the code in all your templates, you don't interfere with Normal.dot and as it's globally available they can use it with all their documents, even old ones.

Regards