none
Want to make copy of all code i added to Word Normal Template, QAT, and extra templates for a word doc. RRS feed

  • Question

  • In a word 2013 template called Tracking I have code want to make a hard copy of for, if and when I have to redo this template.

    I have noticed in looking at template then click on Developer, Then On Visual Basic, then View Project Explorer.

    I have noticed in a tree view, and I  See folders like

    Normal,

    Project(Word 2013 tips)   [the current word doc I opened to get this info], and

    TemplateProject(Best Story 2014 12 01) [an extra template with extra code for docs like this one.]

    All have sub folders like these

    Microsoft Word Objects,

    Forms [if have any UserForms],

    Modules [if have any], and some have a folder called,

    References with a sub folder of file name used as a templateProject

    What I am trying to do is back up, ALL THAT stuff just in case of an oops moment.

    Found I could pick an item and Export it.

    Seems I can pick some items and export them as a file with a built in dialog box like a File Save dialog box, and I can pick where to put file.

    As far as I can tell, only some items I can save that way.

    And even more important, I have not been able to tell if when I export file, I also automatically remove from the word doc code.

    Seems I have to export each item, I can export ONLY one item at a time. 

    Am I stuck doing it that way?     

    For my documentation of code I would like to have copy of code, even if all I could get was a text file of all the current code for my files, would be very helpful.

    Even better if I could save as a word doc.

    Thanks,  even if just to let me know I have to export each item, one at a time.


    Mark J

    Friday, September 25, 2015 12:52 AM

Answers

  • Hi Mark J,

    To back up the code in the template, I suggest that you backup the document template instead of copy the code into the text file.

    In addition, we can also write VBA to export the VBCompoent. Here is example that export the modules in the template for your reference:

    Sub ExportModule()
    Dim t As Template
    Set t = ActiveDocument.AttachedTemplate
    For Each i In t.VBProject.VBComponents
    If i.Type = vbext_ct_StdModule Then
         i.Export "C:\" + i.Name + ".txt"
    End If
    Next i
    
    End Sub

    Here is helpful link for your reference:

    Visual Basic add-in model reference

    Regards & Fei



    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    • Marked as answer by PuzzledByWord Sunday, September 27, 2015 7:31 AM
    Friday, September 25, 2015 2:45 AM
    Moderator
  • Paul,

    Thanks,

    your answer is perfect for my current level of knowledge,  and needs.

    Mark 


    Mark J

    • Marked as answer by PuzzledByWord Sunday, September 27, 2015 7:34 AM
    Sunday, September 27, 2015 7:34 AM

All replies

  • Hi Mark J,

    To back up the code in the template, I suggest that you backup the document template instead of copy the code into the text file.

    In addition, we can also write VBA to export the VBCompoent. Here is example that export the modules in the template for your reference:

    Sub ExportModule()
    Dim t As Template
    Set t = ActiveDocument.AttachedTemplate
    For Each i In t.VBProject.VBComponents
    If i.Type = vbext_ct_StdModule Then
         i.Export "C:\" + i.Name + ".txt"
    End If
    Next i
    
    End Sub

    Here is helpful link for your reference:

    Visual Basic add-in model reference

    Regards & Fei



    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    • Marked as answer by PuzzledByWord Sunday, September 27, 2015 7:31 AM
    Friday, September 25, 2015 2:45 AM
    Moderator
  • It would be rather easier to make a copy of the template itself (e.g. via Windows Explorer). Although Fei has provided code to export the template's vba modules, that doesn't address anything on the document side of things, including page layout & setup, boilerplate text, fields, objects, etc. Simply making a copy address all of those concerns in one simple step.

    Cheers
    Paul Edstein
    [MS MVP - Word]

    Friday, September 25, 2015 4:09 AM
  • Fei,

    Thanks,

    was helpful,

    and very helpful the link to   Visual Basic add-in model reference

    I am getting close to needing that info.

    I have a lot of reading, and trying of code to advance my level of coding.

    thanks again very much for code and link to what I need to learn next.

    Mark


    Mark J

    Sunday, September 27, 2015 7:30 AM
  • Paul,

    Thanks,

    your answer is perfect for my current level of knowledge,  and needs.

    Mark 


    Mark J

    • Marked as answer by PuzzledByWord Sunday, September 27, 2015 7:34 AM
    Sunday, September 27, 2015 7:34 AM