View Single Post
 
Old 01-07-2015, 12:50 PM
ptmuldoon ptmuldoon is offline Windows 7 64bit Office 2013
Advanced Beginner
 
Join Date: Sep 2014
Posts: 93
ptmuldoon is on a distinguished road
Default

ok, hitting a roadblock again. I'm trying to learn now how to add take the field code information and then to place/add into a building block.

The field code gets created. but I want to be able to have the field in a building block.

Code:
Sub AddCustomBuildingBlock()
    Dim objTemplate As Template
    Dim objBB As BuildingBlock
    Dim objRange As Range
    Dim FilePath As String
 
    ' Set the template to store the building block
    Set objTemplate = Templates("C:\Users\paul.muldoon\AppData\Roaming\Microsoft\Word\STARTUP\Report Building Blocks.dotm")
 
    FilePath = "LINK Excel.SheetMacroEnabled.12 ""C:\\Data\\Samples\\Sample WP.xlsm"" ""Cover Charts!Charts_Cover_Main"" \p"
    Selection.Fields.Add Range:=Selection.Range, Type:=wdFieldEmpty, Text:=FilePath, PreserveFormatting:=False
  
    ' Collapse the range, set the range, and add the text
    Selection.Collapse
    Set objRange = Selection.Range
 
    objRange.Text = "Building blocks for the technically challenged"
    
     ' Add the building block to the template
        Set objBB = objTemplate.BuildingBlockEntries.Add( _
        Name:="Title", _
        Type:=wdTypeAutoText, _
        Category:="General", _
        Range:=objRange)
 
End Sub
Reply With Quote