Consulting

Results 1 to 8 of 8

Thread: UserForm and Macros dropping out of new Document based on template

  1. #1
    VBAX Newbie
    Joined
    Feb 2021
    Posts
    3
    Location

    UserForm and Macros dropping out of new Document based on template

    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

  2. #2
    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,
    Graham Mayor - MS MVP (Word) 2002-2019
    Visit my web site for more programming tips and ready made processes
    http://www.gmayor.com

  3. #3
    VBAX Sage
    Joined
    Apr 2007
    Location
    United States
    Posts
    8,711
    Location
    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

    Capture.JPG

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

    Capture1.JPG


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

    Capture2.JPG
    ---------------------------------------------------------------------------------------------------------------------

    Paul


    Remember: Tell us WHAT you want to do, not HOW you think you want to do it

    1. Use [CODE] ....[/CODE ] Tags for readability
    [CODE]PasteYourCodeHere[/CODE ] -- (or paste your code, select it, click [#] button)
    2. Upload an example
    Go Advanced / Attachments - Manage Attachments / Add Files / Select Files / Select the file(s) / Upload Files / Done
    3. Mark the thread as [Solved] when you have an answer
    Thread Tools (on the top right corner, above the first message)
    4. Read the Forum FAQ, especially the part about cross-posting in other forums
    http://www.vbaexpress.com/forum/faq...._new_faq_item3

  4. #4
    VBAX Newbie
    Joined
    Feb 2021
    Posts
    3
    Location
    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?

  5. #5
    Quote Originally Posted by Paul_Hossler View Post
    So File, New Report.dotm creates a document (DOCM) with the formatting, etc. all ready to go
    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.
    Quote Originally Posted by Jentis View Post
    My template document in Word 97-2003 is a .dot file. Not a .docx or .docm
    With 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.
    Graham Mayor - MS MVP (Word) 2002-2019
    Visit my web site for more programming tips and ready made processes
    http://www.gmayor.com

  6. #6
    VBAX Newbie
    Joined
    Feb 2021
    Posts
    3
    Location
    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. ??

  7. #7
    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?
    Graham Mayor - MS MVP (Word) 2002-2019
    Visit my web site for more programming tips and ready made processes
    http://www.gmayor.com

  8. #8
    VBAX Sage
    Joined
    Apr 2007
    Location
    United States
    Posts
    8,711
    Location
    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
    ---------------------------------------------------------------------------------------------------------------------

    Paul


    Remember: Tell us WHAT you want to do, not HOW you think you want to do it

    1. Use [CODE] ....[/CODE ] Tags for readability
    [CODE]PasteYourCodeHere[/CODE ] -- (or paste your code, select it, click [#] button)
    2. Upload an example
    Go Advanced / Attachments - Manage Attachments / Add Files / Select Files / Select the file(s) / Upload Files / Done
    3. Mark the thread as [Solved] when you have an answer
    Thread Tools (on the top right corner, above the first message)
    4. Read the Forum FAQ, especially the part about cross-posting in other forums
    http://www.vbaexpress.com/forum/faq...._new_faq_item3

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •