AutoNew

C

Cameron Powell

I have a template that is a workgroup template. When it is opened I would
like the keys Alt+S to execute the macro that is embedded. I tried to place
the following code in a macro called AutoNew()

Sub AutoNew()
Res = MsgBox("Test")
CustomizationContext = ActiveDocument
KeyBindings.Add KeyCode:=BuildKeyCode(wdKeyAlt, _
wdKeyS), KeyCategory:=wdKeyCategoryMacro, _
Command:="ShippingLabels"
End Sub

I inserted the Message box in there as a test and it does not run either. My
normal template does not include any auto macros, and I do have auto macros
enabled. Does anyone have any ideas?
 
C

Cameron Powell

Just as a note. When I change this to AutoOpen and actually open the template
this works, but when I create a new document based on the template I get
nothing either way.
 
C

Charles Kenyon

An AutoExec macro will not run from a document template.
An AutoNew macro runs when a new document is created based on the template.
An AutoOpen macro runs when the template is opened or when a document based
on the template is opened.

Since this appears to be a document template, why not simply assign the key
(either using code or manually) in your template. It will then work in all
documents based on that template.
--
Charles Kenyon

Word New User FAQ & Web Directory: http://addbalance.com/word

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

See also the MVP FAQ: 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.
 
C

Cameron Powell

I tried that, but it didn't work either.

Charles Kenyon said:
An AutoExec macro will not run from a document template.
An AutoNew macro runs when a new document is created based on the template.
An AutoOpen macro runs when the template is opened or when a document based
on the template is opened.

Since this appears to be a document template, why not simply assign the key
(either using code or manually) in your template. It will then work in all
documents based on that template.
--
Charles Kenyon

Word New User FAQ & Web Directory: http://addbalance.com/word

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

See also the MVP FAQ: 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.
 
J

Jean-Guy Marcil

Cameron Powell was telling us:
Cameron Powell nous racontait que :
I tried that, but it didn't work either.

If it is not working it means that you either did not assign the key
correctly or you are not creating documents from the template in the usual
way.
I have done this many times and it has always worked.

What Word version?
Have you tried the Document_New procedure in the ThisDocument module
instead?

By the way, I have just tested the code you posted "as is" and it worked as
expected on Word 2003 (and should work on all versions of Word as well).

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

Cameron Powell

When I put that code into the Document_New procedure, it does attempt to run
the script, but I recieve Run-time error '5346': Word cannot change the
function of the specified key.

When I have it in AutoNew() it doesn't run upon creation of the new
document, but if I run the code manually it does work. I do not understand
what it is that I could be doing wrong.

I have the template placed in my default templates directory. I am using the
File New Dialog and selecting it and opening it as a new document.

I am also using word 2003.
 
J

Jean-Guy Marcil

Cameron Powell was telling us:
Cameron Powell nous racontait que :
When I put that code into the Document_New procedure, it does attempt
to run the script, but I recieve Run-time error '5346': Word cannot
change the function of the specified key.

When I have it in AutoNew() it doesn't run upon creation of the new
document, but if I run the code manually it does work. I do not
understand what it is that I could be doing wrong.

I have the template placed in my default templates directory. I am
using the File New Dialog and selecting it and opening it as a new
document.

Are you on a network?
How about macro security?

Maybe there is a file access problem/conflict?

Have you tried with
DoEvents
before
CustomizationContext = ActiveDocument
???

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

Cameron Powell

Yes, I am on a network, and this template is a workgroup template. My
security settings are currently set to low. Now matter what I put in Sub
AutoNew() it will not run upon document creation. Is there anyway I could
e-mail this document to you and have you take a look at it?
 
J

Jean-Guy Marcil

Cameron Powell was telling us:
Cameron Powell nous racontait que :
Yes, I am on a network, and this template is a workgroup template. My
security settings are currently set to low. Now matter what I put in
Sub AutoNew() it will not run upon document creation. Is there anyway
I could e-mail this document to you and have you take a look at it?

Just un-mangle it...

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

Cameron Powell

What do you mean?

Jean-Guy Marcil said:
Cameron Powell was telling us:
Cameron Powell nous racontait que :


Just un-mangle it...

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

Jean-Guy Marcil

Cameron Powell was telling us:
Cameron Powell nous racontait que :
What do you mean?

Look in my signature block. Un-mangle my email address, i.e. remove REMOVE
CAPS THISTOO from the address.

--
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