Re: Problems with AutoNew in Normal.dot



Jean-Guy,

I have tried the approach outlined in the link you posted: Here is
what I did:

Created a .dot file in the word startup folder and put the following
VBA code in:

*************************************************************************************
Class1

Public WithEvents oApp As Word.Application

Private Sub Class_Initialize()
MsgBox "initialise"
End Sub

Private Sub oApp_DocumentOpen(ByVal Doc As Document)
MsgBox "Doc Open"
End Sub

Private Sub oApp_NewDocument(ByVal Doc As Document)
MsgBox "New Doc"
End Sub
*************************************************************************************
Module1

Dim oAppClass As New Class1

Public Sub AutoExec()
Set oAppClass.oApp = Word.Application
MsgBox oAppClass.oApp.Documents.Count
End Sub

*************************************************************************************
When I launch Word I get the pop-up from the class_initialise event and
a 1 from the document count pop-up but nothing else. If I then open a
new blank document I get the desired "New Doc" message!!!!

It would appear that even if this application level event handling is
used in an add-in that one cannot get a new document event for the
'default' document which is displayed when Word is started?!?

Do you have any other ideas how to do this?

- Background: I need to populate a document variable in the header of
every word document created at my firm without leaving any VBA code in
the document that gets produced. The company templates I already have
a solution for but it does not work for blank documents created from
normal.dot because of this issue with the new document event.

Cheers,
Sunny


Jean-Guy Marcil wrote:
Sunny was telling us:
Sunny nous racontait que :

Hi All,

I am getting some frustrating problems with the AutoNew procedure when
I use it inside Normal.Dot. I am using Word 10 (XP).

I have put the following code into a new module in Normal.dot:

Sub AutoNew()
MsgBox "You are in AutoNew"
End Sub

When I open Word I get a new blank document but no code runs in the
AutoNew procedure. If I then open a New Blank Document the code runs
!!!!!!

Does anyone know why the code does not run when I open Word and the
initial document is displayed? (Surely this IS a new blank document?)

More importantly does anyone know HOW to get this code to run when
Word is opened?

AutoNew (now deprecated) and Document_New in the ThisDocument class module
do not run when Word is first launched. The first blank document you get
when you launch Word (Document 1) is not so much a New document as it is a
"default" document that you have no say over its creation.

What are you trying to achieve?
Normally, code in Normal.dot is not really recommended. What kind of code do
you need to execute whenever any document based on Normal.dot is created?

Also, note that documents based on other templates will not benefit form
this code in Normal.dot. If you want to have an impact whenever any document
is created, the route is a little more complicated.

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

.



Relevant Pages

  • Re: Go to Control with IIf statement
    ... Private Sub Form_AfterUpdate ... MsgBox "Must fill in Approved Pantone Number", ... After Update of my combo box and even if I pick other categories, the macro ...
    (microsoft.public.access.formscoding)
  • Re: Change Address Fields with Combo on Form
    ... MsgBox "Update Completed" ... Private Sub cmb_Addr_change_AfterUpdate ... Dim SQL_Text As String ... MsgBox "Update canceled by user" ' Cancel update. ...
    (microsoft.public.access.forms)
  • Re: Change Password by User
    ... Admin privledges and 28 users with limited privledges, ... Private Sub ChgUsersPswdBtn_Click ... On Error GoTo ErrHandler ... MsgBox "New passwords are not identical. ...
    (microsoft.public.access.security)
  • Re: Cancel = True still letting user exit
    ... Private Sub PrintBehReptBut_Click ... If mOKToClose Eqv False Then ... MsgBox "You must fix the current record before closing the form." ... Cancel = True ...
    (microsoft.public.access.forms)
  • Re: AutoNew and Private
    ... Dim cb As CommandBarComboBox ... Private Sub SetComboBox ... If however I declare AutoNew as Private so that it is hidden from the ...
    (microsoft.public.word.vba.general)