Microsoft Office Forums

Go Back   Microsoft Office Forums > >

 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
  #2  
Old 01-30-2017, 10:00 PM
gmayor's Avatar
gmayor gmayor is offline Macro for creating word docs from existing template Windows 10 Macro for creating word docs from existing template Office 2016
Expert
 
Join Date: Aug 2014
Posts: 4,144
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
 

Tags
template drop-down, vba in microsoft word



Similar Threads
Thread Thread Starter Forum Replies Last Post
Macro for creating word docs from existing template Creating a new Table template based on existing table Cadmiumcadamium Word Tables 1 08-14-2016 08:58 PM
Macro for creating word docs from existing template Creating a Template using a Macro to fill in various information 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

Other Forums: Access Forums

All times are GMT -7. The time now is 04:54 AM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2025, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2025 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft