PDA

View Full Version : UserForm and Macros dropping out of new Document based on template



Jentis
02-10-2021, 07:20 PM
Hi all,

I have created a Word 97 template with a UserForm attached. (Has to be word 97 unfortunately, but building it in Word for MS365).
As I was building it, it all seemed to be working quite smoothly (e.g. I'd open a new document based on the template, I'd call the UserForm by ActiveX Button and the userform would load etc...

I don't know what has happened now, but when I open a new Document based on the template, the UserForm is no longer there? Nor are any other macros?

So the Template has a UserForm, and Various Macros in the "ThisDocument" folder;
but the Document1 has nothing ("ThisDocument" is empty, the "Reference to RequestToUseAgency..." folder is empty and there is no UserForm??

As shown in attached screenshot, the template document has the User Form, but Document1 has no user form??

It seems to me that I am missing something pretty simple - but I just don't know what it is!! I'm much better at Excel VBA than Word!

Any help would be appreciated.

Thanks - Jentis

gmayor
02-10-2021, 10:44 PM
You can't store userforms or macro code in a DOCX format document. You must save it either as a macro enabled document DOCM format, or better still a macro enabled template DOTM format. None of these formats are native to Word 97. For that DOC format (or DOT format) would be preferred,

Paul_Hossler
02-14-2021, 07:55 PM
What the users call a 'template' and what Word calls a 'template' can be a little confusing

My users were used to calling a standardly formatted document a 'template' = open an old one (FebReport.docx), change data/text, save with new name (MarchReport.docx)

Word calls a template the basis for a File, New document. So a template stored in C:\Users\userid\AppData\Roaming\Microsoft\Templates as Report.dotm would have the formatting, styles, content controls, macros, etc. so that a File, New would give the user(s) 'pre-configured' (so to speak) document (DOCM)

So File, New Report.dotm creates a document (DOCM) with the formatting, etc. all ready to go

A Word template without macros is a DOTX and the result is the DOCX

27928

I keep my 'personal templates' in a folder set via Options C:\Users\Daddy\Templates (just 'cuz)

27929


When I was working, I learned that you can also store templates in a Workgroup folder, but that got my IT people:banghead::banghead: involved, and it wasn't worth it :devil2:

27930

Jentis
02-14-2021, 08:24 PM
Thank you both for responding.
My template document in Word 97-2003 is a .dot file. Not a .docx or .docm
I have created many templates, saved as .dot files which feed into a CDM our company uses, so staff can grab the template from a link in the CDM, which will default client details into the form via bookmarks. etc.
I have many other .dot templates saved and running in our CDM; all have macros; and all work.... except this new template for some reason?? As soon as I open a new document from the .dot template, it contains nothing in VBA?? I'm wondering if it has something to do with new MS 365 software installed by my ICT team in recent times? If not that, them I'm fresh out of ideas?

gmayor
02-14-2021, 11:15 PM
So File, New Report.dotm creates a document (DOCM) with the formatting, etc. all ready to goA new file created from a macro enabled template is an unnamed document that has a reference to the code in the original template. It is not a docm document unless specifically saved as one and then only contains the code if copied to the document project.

My template document in Word 97-2003 is a .dot file. Not a .docx or .docmWith a DOT format template (an old proprietary format) pretty much the same should happen, however ALL Word versions since Word 2007 create documents in XML format which, by default, will be saved as DOCX. The document should retain access to the template's macros as long as the document can 'see' the template. It will not actually contain the macros. If the document no longer has access to the template, e.g. if you email it to another user, the macros will not be available to the document.

Jentis
02-14-2021, 11:28 PM
Thanks gmayor - That certainly makes sense. And I see what you mean - don't expect to 'see' the macros in the Document1's VBA - it just 'references' the original.... The trouble is it doesn't. I'm testing on my own PC... double clicking on the .dot to create a new document from template; I can see both the Original template and "Document1" sitting in VBA, but it still doesn't work. ??
:banghead:

gmayor
02-15-2021, 04:51 AM
If you want to email the template to the contact link on my web site I will see if I can spot where the problem lies.
Does the template project actually contain the code that you want to run? How is it called from the document?
Have you thought of converting it to DOTM format? Is the template stored in a trusted location? Is the document folder trusted?

Paul_Hossler
02-15-2021, 08:57 AM
Graham --


A new file created from a macro enabled template is an unnamed document that has a reference to the code in the original template. It is not a docm document unless specifically saved as one and then only contains the code if copied to the document project.

You're correct (but you already knew that)

I just save right away as a DOCM and didn't think my comment through