![]() |
#1
|
|||
|
|||
![]()
Hi,
1. I have word template doc that need to be tailored, 2. to include specific paragraphs based on applicable case for example: [paragraph to include if colour is Blue] Blue is good color [paragraph to include if color is yellow] Yellow is bright colour 3. can you please propose what is my best option to create a doc out of this template 4. How can I choose a colour (blue or yellow) so that paragraphs associated with other choice (not selected) is deleted 5. Or paragraphs associated with the color blue or yellow are coded that only the paragraph associated with chosen color appears in the final doc Thanks |
#2
|
||||
|
||||
![]()
It would be better to put the paragraphs into the document as required, rather than delete them when they are not. How you store and insert the paragraph texts rather depends on how many of them there are and how they are located in the finished document, and whether they are alternatives at the same location or separate, but bookmarks associated with autotexts stored in the template are an obvious possibility, but not the only one.
Where does the colour information, that drives the process, come from? You can call the following macro, as required, to insert the autotexts Code:
Public Sub BBToBM(strBMName As String, strTemplate As String, strBBName As String) 'Graham Mayor - http://www.gmayor.com 'strBMName is the name of the bookmark to fill 'strTemplate is the full path of the template that stores the building block 'Use ThisDocumment.FullName if the template is the template with this macro 'strBBName is the name of the building block to insert Dim oRng As Range Dim iLen1 As Integer, iLen2 As Integer With ActiveDocument iLen1 = Len(ActiveDocument.Range) On Error GoTo lbl_Exit Set oRng = .Bookmarks(strBMName).Range Application.Templates(strTemplate). _ BuildingBlockEntries(strBBName).Insert _ Where:=oRng, _ RichText:=True iLen2 = Len(ActiveDocument.Range) oRng.End = oRng.End + (iLen2 - iLen1) oRng.Bookmarks.Add strBMName End With lbl_Exit: Set oRng = Nothing Exit Sub End Sub
__________________
Graham Mayor - MS MVP (Word) (2002-2019) Visit my web site for more programming tips and ready made processes www.gmayor.com |
#3
|
|||
|
|||
![]()
Many thanks. I have attached a sample doc from which I have to create a doc based on choices highlighted in yellow.
I have to make two type of selections one is to delete a certain word ("recent" in the attached template) if the communication is not recent. Second I have to select a paragraph based on the addressee say Company, Partnership etc. This is just a simple example but I have to make a lot of paragraph choices based on a criteria. Can I create a form like thing that will just include the paragraph based on a selection from a drop down menu & that drop down just disappear in the final doc ? Thanks again for the help ! |
#4
|
||||
|
||||
![]()
For a document like this I would create a userform to collect the information and write the appropriate values to bookmarks set in the template. At its simplest see the attached which you can use as the basis for your template project. Create a new document from the template and allow the macros to run.
__________________
Graham Mayor - MS MVP (Word) (2002-2019) Visit my web site for more programming tips and ready made processes www.gmayor.com |
#5
|
|||
|
|||
![]()
Many thanks !! this is super helpful. In reality I have a template which is around 12 pages that will require 7-8 Combo boxes + form that is segregated in 3 or 4 pages.
I tried to apply your model but I am new to VBA. What is my best bet here. |
#6
|
||||
|
||||
![]()
I prepared the example so it would be easy to follow and expand upon. Unless you learn more VBA you will have to get someone to do it for you. If you want to discuss rates, contact me via my web site.
__________________
Graham Mayor - MS MVP (Word) (2002-2019) Visit my web site for more programming tips and ready made processes www.gmayor.com |
![]() |
Tags |
template drop-down, vba in microsoft word |
|
![]() |
||||
Thread | Thread Starter | Forum | Replies | Last Post |
![]() |
Cadmiumcadamium | Word Tables | 1 | 08-14-2016 08:58 PM |
![]() |
brojames | Word | 7 | 11-09-2015 02:51 PM |
Creating a new template for existing document? | Stephen0352 | Word | 6 | 09-12-2011 09:00 AM |
How do you update existing Outlook calendar item from Word with macro? | Joe Patrick | Word VBA | 0 | 07-09-2011 05:32 AM |
Creating Template in Word | pusherman | Word | 1 | 12-01-2008 03:26 PM |