0

Sean W 2104 post Auto displaying form on opening a template file, dotm from explorer demonstrated how to show my form when my .docm document loads.

Timothy Rylatt's response to my vba word 2016 saveas document without changing module name suggested I render my .docm as .dotm template.

However, though my .docm shows my first form on startup, opening the .dotm does not. The .dotm only shows only the underlying document (that the forms populate).

So is it that my forms (and their VBA code) do not belong in the template document they fill? Do I instead need to load a template document that doesn't contain the forms? If so, do I create a dummy .docm document whose only purpose is to house the forms (and their VBA code?) If so, what do I do with the document from the dummy? Hide it? And what does my prospective client open?

grNadpa
  • 79
  • 1
  • 8
  • Please, give more information and detail rather than simply links to prior questions. Like: What does your form do? What happens to the information gathered by the form? In general, you would want your vba in the template, but not always. – Charles Kenyon Feb 17 '22 at 03:42
  • You don't *open* templates, you create new documents from them via File | New. The answer given by Sean W that you reference tells you how to display the form. – Timothy Rylatt Feb 17 '22 at 07:57
  • I do access the template via File / New. The unpopulated document displays but, unlike the .docm version, the first form does not show. – grNadpa Feb 17 '22 at 15:50
  • @CharlesKenyon The plan is when, opened up a template per T. Rylatt, the user fills in a form that populates the top half of the document then shows another form that allows populating one or more rows of a table in the bottom half of the document.. I still have issues, but the VBA code works -- except for showing the form when I file>open the template. The code in the document: Private Sub Document_Open() txtContractAmt.Show End Sub – grNadpa Feb 17 '22 at 15:58
  • The answer given by Sean W that you reference clearly shows that you use `Document_New` with a template, not `Document_Open`. – Timothy Rylatt Feb 17 '22 at 19:53
  • @TimothyRylatt I believe I am doing what you write. I did use the word icon in my window's 10 tray. When it opens it shows the "Blank document" in the upper ribbon (With the "Home" "New" "Open" "Account" "Feedback" "Options" listed in the left column). Next to the "Blank document" icon is my "waiver Template" (followed horizontally by "Welcome to Word", "Single spaced (blank)" and "Blue grey resume". I click on "waiver Template" and my Document appears, but without the initial form. I plan to delete it and try again after a few tweaks to the document. – grNadpa Feb 17 '22 at 20:38
  • That’s probably because you’re not applying what you’ve been told. Your code to display the form should be in `Document_New`, not `Document_Open`. It is set out very clearly in the answer you reference in your question. – Timothy Rylatt Feb 17 '22 at 20:47
  • This has to be very frustrating for you. Obviously I do not understand. I appreciate your comments. I am not aware of using a Document_New anywhere. Certainly not in any VBA code I've written. So what I am doing wrong is no doubt more conceptually fundamental and my question probably only a symptom of that more fundamental issue. – grNadpa Feb 17 '22 at 22:20
  • @TimothyRylatt Took you comment to heart. Apologize. Discovered the Document_New in the waiver.docm. Added the Document_New. Then SavedAs a .dotm. There still seems to be an issue as, even after deleting it, the .dotm has three objects in it's project window: Normal, Project (Document 1) and Project(Waiver Template). Only one of the forms made it. And neither the Document_New or _Open appear anywhere. But at least I wanted to acknowledge that I finally "got" your meaning. – grNadpa Feb 18 '22 at 21:07
  • How did you create the dotm? If you used File | SaveAs to save the docm to the correct format, then all the code contained in the document would be in the template. The VBE Project window will always contain Normal and if a document has been created from your template there will be both the template and its related document, which shouldn't contain any code modules. – Timothy Rylatt Feb 19 '22 at 07:57
  • @TimothyRylatt Thank you for not giving up on me. I saved as a dotm to the Documents>CustomOfficeTemplates in Word 2016. The template name shows up in the ribbon in the standard open page. But when I click on it, I get what I guess was an earlier version. When I delete the file from CustomOfficeTemplates, the template icon remains in the ribbon but I get the "Sorry, we couldn't find..." when I click it. Upon saving it again to CustomOfficeTemplates I still get the "Sorry we couldn't find..." It doesn't show up anywhere else in the template list either. Maybe I'll try a different name – grNadpa Feb 19 '22 at 14:01
  • @TimothyRylatt As with the earlier issue, I stumbled into finding that Word 2016 has two template ribbons, The "Personal" ribbon had my template. And clicking on it opened up my current document. I can't seem to find that "Personal" template page again, but my correct template now DOES show up next to the bogus one on the normal Word Open ribbon (next to "Blank Document"). Cannot figure out how to remove the bogus one from the ribbon, but that's livable. – grNadpa Feb 19 '22 at 14:15
  • File | Options | Advanced | General | File Locations - here you will find where Word is looking for templates. To remove the template from the recently used list right click the icon and select "Remove from list" – Timothy Rylatt Feb 19 '22 at 14:21
  • Unless I am still misunderstanding (which appears likely) I do not find "File Locations" on my Word 2016 File>Options>Advanced>General path page nor does the "Remove from List" option appear upon right-clicking the bogus icon -- only "Create" with the "C" underlined. Not worth abusing your good nature further. – grNadpa Feb 19 '22 at 14:58

1 Answers1

0

You do not name your procedure Document_Open in your template but rather Document_New.

You are not opening the template, but rather creating a new document based on that template. Here is my writing on Auto Macros in templates.

You could also name the procedure AutoNew and place it in the another module of your template.

Charles Kenyon
  • 869
  • 1
  • 8
  • 19
  • Thanks for this. I really appreciate it and expect that it will solve my issue. I'll need to study it more detail after a few more tweaks to forms. – grNadpa Feb 17 '22 at 20:43