Userform will not open anymore

A

Auschten

I had created a template in Word 2003 that would open one userform upon
creation of a new document and would open a second userform when opening a
saved document. This worked great in 2003, but now doesn't work at all in the
Word 2007 format. The code I've been using is this:

In the NewMacros module:
Sub AutoNew()
Form1.Show
End Sub

In the ThisDocument object:
Private Sub Document_Open()
Form2.Show
End Sub

I don't get any errors or anything; the forms just don't open. I've set
macro security to "Enable all macros". I've checked the "Trust access to VBA
project object module". I've placed the template and all documents created
from it in a Trusted Location. If I save the templates and documents in the
"Word 97-2003" format, they work just fine, but when saved as .docx or .dotm,
the userform won't open.

Any suggestions?

Thanks in advance,
Auschten
 
D

Doug Robbins - Word MVP on news.microsoft.com

While there is no reason to save the template in Word 2007 format (it must
be dotm), it should work and a dotm template containing an autonew and an
autoopen macro, both of which contain the command UserForm1.Show and a
UserForm1, certainly works for me, displaying the user form on creation of a
new document from the template and on re-opening a document that was created
from the template.

If you want to send me your template I will take a look at it.

--
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, originally posted via msnews.microsoft.com
 
A

Auschten

The reason to save the template in Word 2007 format would be to keep
consistent. Let's assume I leave the template as a .dot. Upon creation of a
new document from that .dot, the first userform opens fine (I have two
different userforms). Upon submission of that first userform, the SaveAs
dialog comes up. In Word 2007, the default file type is .docx which will not
save macros, and I need the macros so I can open a second form when the
document is re-opened. The user would have to remember to save the document
as .dot or .docm. I cannot hide the SaveAs dialog from the user (believe me,
I tried) because they need to be able to choose where to save to. But to hope
that they are going to remember to choose the correct file type is asking too
much. For now, I've configured Word 2007 to save all documents as .doc by
default, which is a great work around for now especially since my users are
in a mixed 2003 and 2007 environment, but it's silly to have to reconfigure
Word on every computer just so these templates will work.

Yes, the AutoNew macro works great when the template is saved as .dotm.
However, AutoOpen and/or Document_Open will not open up that second userform
(or even the first one) whether the file is saved from the .dotm template as
a .docm or .dot or even when just opening the .dotm template (right-click on
template icon, click Open). I hope that made sense.

The only was this consistently works is if the files are saved in the .dot
and .doc formats. Is there a way to do that in the VBA code instead of
globaly in Word? Currently my code is hardcoded to use ".doc", but Word
overrides that and defaults to .docx (unless I reconfigure Word itself).

Thanks!
Auschten
 
D

Doug Robbins - Word MVP on news.microsoft.com

If you create a document from a template (in the proper way, by using
File>New), macros in the template are NOT saved in the document. However,
if the template from which the document was created is available on a
machine on which the document is opened, a reference to the template is
created so that the macros are available for use with that document.

Assuming that the template will be available, if you want something to
happen automatically when the document is re-opened, the code for the event
must be in an AutoOpen macro in the 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, originally posted via msnews.microsoft.com
 
G

grixnair

We are having a similar problem with the VBA no longer working once a
second file has been created based on the first template.

I followed the steps you outline and it works, unless the user has run
the macros before saving the new version of the file.
The macros don't work in the new version even if the original template
is on the same machine and the reference to the original template is
there.

Is there another step or setting we are missing?
 
D

Doug Robbins - Word MVP on news.microsoft.com

What are the macros doing? Show us the code?

--
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, originally posted via msnews.microsoft.com
 
G

grixnair

One of the macros builds the header for subsequent pages based on
information entered into the date field and a claim number field. It
is called when the user tabs out of the claim number field or the date
field. But if the document is saved with values in these fields, the
macro does not run the next time the document is opened. It worked
fine in Office 2003 and seems to still work in 2007 if the file format
is a word 2003 .doc

Public Sub Checkheader()
Dim lsString As String

lsString = ActiveDocument.FormFields("DATE_LETTER").Result & vbCr
lsString = lsString + "Re: " + ActiveDocument.FormFields
(WRK_FIRST_NAME).Result
lsString = lsString + " " + ActiveDocument.FormFields
(WRK_LAST_NAME).Result

ActiveDocument.BuiltInDocumentProperties("KEYWORDS").Value =
lsString


lsString = "Claim #" + ActiveDocument.FormFields
(WCB_CLAIM_NUMBER).Result
lsString = lsString + " " + ActiveDocument.FormFields
("CLAIM_TRAILER").Result & vbCr

ActiveDocument.BuiltInDocumentProperties("COMMENTS").Value =
lsString
ActiveDocument.Sections(1).Headers
(wdHeaderFooterPrimary).Range.Fields.Update

End Sub
 
D

Doug Robbins - Word MVP on news.microsoft.com

When you save the document as a Word 2007 document, are you saving it in
..docm (macro enabled document) format. If you save it in .docx format, the
macros will be deleted from the document.

I would suggest that you do not mix the use of & and +. The use of + is
best reserved for arithmetic operations

You code can be rewritten as:

With ActiveDocument
lsString = .FormFields("DATE_LETTER").Result & vbCr _
& "Re: " & .FormFields(WRK_FIRST_NAME).Result _
& " " & .FormFields(WRK_LAST_NAME).Result
.BuiltInDocumentProperties("KEYWORDS").Value = lsString
lsString = "Claim #" & .FormFields(WCB_CLAIM_NUMBER).Result _
& " " & .FormFields("CLAIM_TRAILER").Result & vbCr
.BuiltInDocumentProperties("COMMENTS").Value = lsString
.Sections(1).Headers(wdHeaderFooterPrimary).Range.Fields.Update
End With

which saves a lot of typing of ActiveDocument (which I have a habit of
getting as ActiveDocumnet)
--
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, originally posted via msnews.microsoft.com
 
D

Doug Robbins - Word MVP on news.microsoft.com

By the way, this type of form is NOT as UserForm.

--
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, originally posted via msnews.microsoft.com
 

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