View Single Post
 
Old 01-30-2017, 10:00 PM
gmayor's Avatar
gmayor gmayor is offline Windows 10 Office 2016
Expert
 
Join Date: Aug 2014
Posts: 4,137
gmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud of
Default

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
Reply With Quote