Share via

Editing Multiple Building Blocks

Anonymous
2014-11-05T18:09:49+00:00

I need to edit 36 Building Blocks in Word 2013. Is there a way that I can change the text 2014 to 2015 in multiple Building Blocks without having to insert each one, change it and then Save it back to their Building Blocks locations'? I am hoping to find a way to be able to just change the Code in the Building Block.dotx but am unable to find any reference to being able to do this. Thank you.

Microsoft 365 and Office | Word | For home | Windows

Locked Question. This question was migrated from the Microsoft Support Community. You can vote on whether it's helpful, but you can't add comments or replies or follow the question.

0 comments No comments

Answer accepted by question author

Anonymous
2014-11-05T20:21:50+00:00

The concept is the same.  Try:

Sub ScratchMacro()

 'A basic Word macro coded by Greg Maxey

 Dim oTmp As Template

 Dim oBB As BuildingBlock

 Dim lngIndex As Long

 Templates.LoadBuildingBlocks

 For Each oTmp In Templates

    If oTmp.Name = "Building Blocks.dotx" Then

    For lngIndex = 1 To oTmp.BuildingBlockEntries.Count

      Set oBB = oTmp.BuildingBlockEntries.Item(lngIndex)

      oBB.Value = Replace(oBB.Value, "2015", "2016")

    Next lngIndex

    Exit For

  End If

  Next oTmp

  Set oTmp = Nothing

 End Sub

I have several tools for working with building blocks on my website or I can create a custom add-in for you if you are interested.

Was this answer helpful?

0 comments No comments

4 additional answers

Sort by: Most helpful
  1. Anonymous
    2014-11-05T20:47:19+00:00

    Dawn,

    You're welcome.  Of course that should have been "2014" and "2015."  You need to be aware that the code is indiscriminate.  It will affect "ANY" building block in the template containing the replacement term.  Not just the 36 that you may be concerned about.

    Was this answer helpful?

    0 comments No comments
  2. Anonymous
    2014-11-05T20:41:19+00:00

    Thank you, thank you, thank you. It worked perfectly.

    I will continue to follow your website for future information. Thanks again, Dawn

    Was this answer helpful?

    0 comments No comments
  3. Anonymous
    2014-11-05T19:14:58+00:00

    You could do it with a macro.  The following code assumes the buildingblocks are defined in the normal template:

    Sub ScratchMacro()

    'A basic Word macro coded by Greg Maxey

    Dim oTmp As Template

    Dim oBB As BuildingBlock

    Dim lngIndex As Long

    Set oTmp = ThisDocument.AttachedTemplate

    For lngIndex = 1 To oTmp.BuildingBlockEntries.Count

      Set oBB = oTmp.BuildingBlockEntries.Item(lngIndex)

      oBB.Value = Replace(oBB.Value, "2014", "2015")

    Next lngIndex

    End Sub

    No, I did not define them in the normal template, they are in a Building Block.dotx. I have multiple users that use these buildingblocks and I thought that it would be easier to create the building blocks file so I wouldn't have to overlay their existing Normal templates every year. This is the first year that I have used the buildingblocks, previously for the last several years, I have overlaid their existing normal templates, which was a pain because I would have to re-create their new template to have the same attributes as the one that I was replacing, (Quick Access Toolbar, Ribbon, etc....)

    Was this answer helpful?

    0 comments No comments
  4. Anonymous
    2014-11-05T18:32:26+00:00

    You could do it with a macro.  The following code assumes the buildingblocks are defined in the normal template:

    Sub ScratchMacro()

    'A basic Word macro coded by Greg Maxey

    Dim oTmp As Template

    Dim oBB As BuildingBlock

    Dim lngIndex As Long

    Set oTmp = ThisDocument.AttachedTemplate

    For lngIndex = 1 To oTmp.BuildingBlockEntries.Count

      Set oBB = oTmp.BuildingBlockEntries.Item(lngIndex)

      oBB.Value = Replace(oBB.Value, "2014", "2015")

    Next lngIndex

    End Sub

    Was this answer helpful?

    0 comments No comments