Strange Macro actions when creating Userforms within templates

D

Darren Ingram

Hi all,

I've created a template with a Userform. When the template is opened as
'Document1' it works when the autonew macro is found in the 'Normal' template
but won't if it isn't.

This is only a problem when opening up a new blank document based on the
'Normal' template. The Userform pops up!

Please help. As I want to create a whole lot of templates for my team and
have them opening up as new documents with the userform.

Need advice! system: XP, Word 2000 used.
 
D

Doug Robbins - Word MVP

The AutoNew macro should be located in a module in the template and the use
should create the document by selecting New from the File menu and then
select the template. You should remove the macro from the Normal.dot
template.

--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP
 
D

Darren Ingram

Hi Doug,

I tried what I think you ment but it didn't work. I think I need to explain
what I'm seeing a little better as I think I haven't told the whole story.

In VBA the project window reads like this:

+Normal
-Project (Statement Reconciliation sheet)
- Microsoft Word Objects
ThisDocument
-Forms
UserForm2
-Modules
NewMacros
-References
Reference to Normal

Am I reading this correctly to say that when the new 'Document1' is opened
up after clicking the template then the macros refer to those held in the
'Normal' template?

Darren
 
D

Doug Robbins - Word MVP

What code do you have/have you tried in the module NewMacros?

--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP
 
D

Darren Ingram

Hi Doug,

The following is the only macro held in the NewMacros folder..

Sub Autonew()
'
' Statement1 Macro
' Macro created 18/02/2009 by Darren
'
UserForm2.Show

End Sub
---------------------------------------------------------------------
This is the code I have in the UserForm2:

Private Sub CommandButton1_Click()
With ActiveDocument
..Bookmarks("Client1").Range _
..InsertBefore TextBox1
..Bookmarks("Accountnumber1").Range _
..InsertBefore TextBox2
..Bookmarks("Statementending1").Range _
..InsertBefore TextBox3
..Bookmarks("Statementnumber1").Range _
..InsertBefore TextBox4
..Bookmarks("Bankbalance1").Range _
..InsertBefore TextBox5
..Bookmarks("Client2").Range _
..InsertBefore TextBox6
..Bookmarks("Accountnumber2").Range _
..InsertBefore TextBox7
..Bookmarks("Statementending2").Range _
..InsertBefore TextBox8
..Bookmarks("Statementnumber2").Range _
..InsertBefore TextBox9
..Bookmarks("Bankbalance2").Range _
..InsertBefore TextBox10

End With

UserForm2.Hide
End Sub
-----------------------------------------------------------------
And this is the code I have in the 'ThisDocument':

Private Sub Document_Open()

Autonew

End Sub
----------------------------------------------------------------------
More than you asked for but I thought I'd put the lot in so that you get the
whole picture.

Thanks for your advice...

Darren.
 
D

Doug Robbins - Word MVP

As I said, you should remove the autonew macro from the Normal template.

Get rid of the code from the Private Sub Document_Open() so that the only
place that you have Autonew() is in the NewMacros module.

Alternatively, you could have the UserForm2.Show in a Private Sub
Document_New() in the ThisDocument

--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP
 
D

Darren Ingram

Hi Doug,

Thanks for the reply. I've removed the macro from the NewMacros and put the
following in the ThisDocument object folder:

Private Sub Document_Open()

UserForm2.Show

End Sub

-------------------------------------------------------

Also tried leaving the 'ThisDocument' empty and leaving the NewMacros with
the

Sub Autonew()
'
' Statement1 Macro
' Macro created 18/02/2009 by Darren
'
UserForm2.Show

End Sub
----------------------------------------------------------------

Both actions didn't work. When I open the template in a new doc nothing
happens.
The object folder 'References' - Reference to Normal that appears below the
Module Object folder....is that saying that there are macros attached to the
Normal folder? Or is this attachment just because it's a template project
and when it opens the template it opens in a normal state? If it is because
there is a link to the Normal template and thus a macro attached to the
Normal template....well I've deleted all macros in the Normal template that I
can see.

How do you remove that linking between the Normal.dot and the project.dot?

Sorry for all my questions. I've not a Microsoft MVP but a LPMP (Learner
plate microsoft player). I'm sure you see many of us! :)

Out of curiousity are you on the West Coast US? I'm in the UK and I'm
working out when you sleep?

Darren.
 
D

Doug Robbins - Word MVP

You must use File>New and select the template. You do not open the
template. If you are putting the UserForm2.Show in the ThisDocument, it
must be in a routine with the name of Document_New(), NOT Document_Open

--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP
 
D

Darren Ingram

Doug, you are a legend! It worked and I think it was the Document_New()
that did it. It works both by clicking the .dot file and through the
File>New method.

Thank you for all your assistance!

Darren.
 

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