Autostarting macro

M

Mitja

H

How to autostart this macro every time I open a word template

Here is the macro

Sub Macrodatum(

ActiveDocument.SaveAs "Order" & Format(Date, "yyyy-mm-dd") & ".doc

End Su

Please advice
 
M

Malcolm Smith

All you have to do is to place

ActiveDocument.SaveAs "Order" & Format(Date, "yyyy-mm-dd") & ".doc"

in the template's Document_Open event (look at ThisDocument in the project
tree) and then it will save each time a document based on that template
opens.

However, if you have two people doing the same thing on the same time then
do you want to the second one to overwrite the first one?

- Malc
www.dragondrop.com
 
M

Mitja

Sorry I'm a total macro beginner. Could you explain me again in detail how the macro must be modified.

Thanks
 
C

Charles Kenyon

If you want the macro to run every time you create a new document based on
your template, name your macro "AutoNew." It will run whenever you create a
new document. The one that Malcolm gave you will _not_ run when a new
document is created but will run whenever a document based on the template
is opened. I suspect that this is not what you want to do, although it is
what you asked for.
--

Charles Kenyon

Word New User FAQ & Web Directory:
<URL: http://addbalance.com/word/index.htm>

Intermediate User's Guide to Microsoft Word (supplemented version of
Microsoft's Legal Users' Guide)
<URL: http://addbalance.com/usersguide/index.htm>

See also the MVP FAQ: <URL: http://www.mvps.org/word/> which is awesome!
--------- --------- --------- --------- --------- ---------
This message is posted to a newsgroup. Please post replies
and questions to the newsgroup so that others can learn
from my ignorance and your wisdom.
 
M

Malcolm Smith

Charles

Okay, so I misread the original message; if he wanted to execute when the
document is created then the Document_New() event is the place to shove
the code.

I prefer to place it in the ThisDocument because it's easier to locate
than to hunt through loads of modules later on. But, it's a personal
choice and, well, it's more OO innit? :)

Nonetheless, my original point is still valid. What happens if two people
create a document based on the same template in the same day?

- Malc
www.dragondrop.com
 
M

Mitja

Thanks for help Charles

We are close to the solution of my problem, but let me explain: I want to create 3 identical templates (layout), which will be used for creating "Purchase order" word documents for 3 different suppliers. I want Word automatically names these word documents something like "Order_Supplier1_savedate.doc", "Order_Supplier2_savedate.doc" and "Order_Supplier3_savedate.doc" depending which template I use

If I use the AutoNew macro like you suggested all the 3 templates gives to the word documents the same filename, for example "Order_Supplier1_savedate.doc"

Can I create 3 AutoNew macros

Thanks for your help and your patience.
 
D

Doug Robbins - Word MVP - DELETE UPPERCASE CHARACT

Hi Mitja,

If you are creating 3 templates, then you would have an autonew macro in
each template. Each of those macros would then be unique to the template in
which they are created.

While you only have 3 suppliers, managing a template for each one would not
be too much of a problem. In time however, you may end up with many more
suppliers and then having one for each could become an issue. On the
assumption that the purchase orders for each supplier are similar, you may
want to consider having one template that contains a userform which contains
a combobox from which you can select the supplier to whom you wish to issue
the purchase order and that selection can then be used as part of the
filename as well as being used to populate the relevant parts of the
document that is being produced.

If you are interested in this approach, post back here and we will give you
some more information.

Please post any further questions or followup to the newsgroups for the
benefit of others who may be interested. Unsolicited questions forwarded
directly to me will only be answered on a paid consulting basis.

Hope this helps
Doug Robbins - Word MVP
Mitja said:
Thanks for help Charles.

We are close to the solution of my problem, but let me explain: I want to
create 3 identical templates (layout), which will be used for creating
"Purchase order" word documents for 3 different suppliers. I want Word
automatically names these word documents something like
"Order_Supplier1_savedate.doc", "Order_Supplier2_savedate.doc" and
"Order_Supplier3_savedate.doc" depending which template I use.
If I use the AutoNew macro like you suggested all the 3 templates gives to
the word documents the same filename, for example
"Order_Supplier1_savedate.doc".
 
M

Mitja

Thanks to all for your help. I have finally managed to get the 3 templates working. The problem was I set the AutoNew macro to work for all active templates documents and templates (in Macros dialog box), so I had the same AutoNew macro working in all 3 templates. Now finally all works like I want.

Thanks again for your help and patience. Without your support I couldn't have done it.
 
J

jokop

Hello
I also tried to activate AutoNew and Document_New macros. the macros indeed executes when making a new document
except
it executes only for new documents which I make from the WordApplication->File->New option
but if i start a new document by pressing the WordApplication icon on my desktop AutoNew and Document_New macros dont excecute
I hope U understand my problem and thanks in advance
 

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