none
using vba to create a 'custom' word template (.dotm) RRS feed

  • Question

  • Say I have a template (about 50 pages when blank, about 500 when filled out) which is broken down and organized into multiple sections and parts. When filling out this template, for different scenarios, alot of sections are going to be full of "N/A" which wastes alot of time. I need to be able to write a program that is able to toggle on and off each section in the template and then ultimatley create this 'custom' document.

    I was thinking about trying to get a dialogue box to pop up upon opening this template with check boxes next to the names of each section indicating what to include in the doc and maybe a 'create' button. This is vague but anything will help.

    Thanks

    Tuesday, June 7, 2011 1:18 PM

Answers

  • Hi CTroend

    The basic approach (show a dialog box for selecting the elements to be included) seems sound.

    Often, for the very reason you're puzzling about, this is approached the other way around: assemble the document with the parts you need, rather than remove what you don't want. Usually, these "parts" are saved in the templates as BUILDING BLOCKS (pre-2007 as AutoText) entries. You insert just the building block entries required.

    If you want to do it the way you describe, one possibility would be to place BOOKMARKS around each element you may want to delete. Your code then does something like mydoc.Bookmarks("name").Range.Delete.


    Cindy Meister, VSTO/Word MVP
    Tuesday, June 7, 2011 3:12 PM
    Moderator
  • Rather than deleting the .Range of the bookmarks as Cindy suggests, I would apply the Hidden attribute the to .Range.Font so that the sections that you do not want are hidden.  If that is done, it is then possible to recall the userform with the dialog boxes so that the checked/unchecked state of any of them can be changed if it turns out that you need to change whether or not a particular section(s) need to be displayed.


    Hope this helps.

    Doug Robbins - Word MVP,
    dkr[atsymbol]mvps[dot]org
    Posted via the Community Bridge

    "CTroend" wrote in message news:1c048358-7153-41be-bdd4-1d6e74956d6e@communitybridge.codeplex.com...

    Say I have a template (about 50 pages when blank, about 500 when filled out) which is broken down and organized into multiple sections and parts. When filling out this template, for different scenarios, alot of sections are going to be full of "N/A" which wastes alot of time. I need to be able to write a program that is able to toggle on and off each section in the template and then ultimatley create this 'custom' document.

    I was thinking about trying to get a dialogue box to pop up upon opening this template with check boxes next to the names of each section indicating what to include in the doc and maybe a 'create' button. This is vague but anything will help.

    Thanks


    Doug Robbins - Word MVP dkr[atsymbol]mvps[dot]org
    Tuesday, June 7, 2011 7:57 PM

All replies

  • In specific, how do i search through my template, find a section based on the tittle or number (e.g 3.7.1) and then hide that section including the title and all of the text associated with it when i create the document?

    Tuesday, June 7, 2011 2:38 PM
  • Hi CTroend

    The basic approach (show a dialog box for selecting the elements to be included) seems sound.

    Often, for the very reason you're puzzling about, this is approached the other way around: assemble the document with the parts you need, rather than remove what you don't want. Usually, these "parts" are saved in the templates as BUILDING BLOCKS (pre-2007 as AutoText) entries. You insert just the building block entries required.

    If you want to do it the way you describe, one possibility would be to place BOOKMARKS around each element you may want to delete. Your code then does something like mydoc.Bookmarks("name").Range.Delete.


    Cindy Meister, VSTO/Word MVP
    Tuesday, June 7, 2011 3:12 PM
    Moderator
  • Rather than deleting the .Range of the bookmarks as Cindy suggests, I would apply the Hidden attribute the to .Range.Font so that the sections that you do not want are hidden.  If that is done, it is then possible to recall the userform with the dialog boxes so that the checked/unchecked state of any of them can be changed if it turns out that you need to change whether or not a particular section(s) need to be displayed.


    Hope this helps.

    Doug Robbins - Word MVP,
    dkr[atsymbol]mvps[dot]org
    Posted via the Community Bridge

    "CTroend" wrote in message news:1c048358-7153-41be-bdd4-1d6e74956d6e@communitybridge.codeplex.com...

    Say I have a template (about 50 pages when blank, about 500 when filled out) which is broken down and organized into multiple sections and parts. When filling out this template, for different scenarios, alot of sections are going to be full of "N/A" which wastes alot of time. I need to be able to write a program that is able to toggle on and off each section in the template and then ultimatley create this 'custom' document.

    I was thinking about trying to get a dialogue box to pop up upon opening this template with check boxes next to the names of each section indicating what to include in the doc and maybe a 'create' button. This is vague but anything will help.

    Thanks


    Doug Robbins - Word MVP dkr[atsymbol]mvps[dot]org
    Tuesday, June 7, 2011 7:57 PM