Results 1 to 1 of 1
  1. #1
    Super Moderator WebGenii's Avatar
    Join Date
    Jan 2001
    Location
    Redcliff, Alberta, Canada
    Posts
    4,066
    Thanks
    2
    Thanked 5 Times in 5 Posts

    Building Block Tools (Office 2010)

    I've been using a LOT of building blocks lately in my template creation work. I really don't find the Building Block organizer to be that helpful when working with a large number of entries.
    So here is some code for a couple of tools that I wrote for myself.

    You'll need to edit the Type and Category for your own purposes here.
    The user must select the text to be saved as a building block. One block at a time. But still way faster than the multi-click method provided by MS.
    -------------------------------------
    Sub BuildingMyBlocks()


    Dim MyAttachedTemplate As Template
    Dim stBlockName As String
    Dim oRng As Word.Range

    Set oRng = Selection.Range
    stBlockName = Selection.Paragraphs(1).Range
    'MsgBox stBlockName
    Set MyAttachedTemplate = ActiveDocument.AttachedTemplate
    On Error Resume Next
    MyAttachedTemplate.BuildingBlockEntries.Add _
    Name:=stBlockName, Type:=wdTypeCustom5, Category:="Scenarios 20 - 42", Range:=oRng
    If Err.Number = 5854 Then GoTo ChopName
    Exit Sub
    ChopName:
    stBlockName = InputBox("Name is too Long enter a shorter Name", "BuildingBlock Name Error", stBlockName)
    MyAttachedTemplate.BuildingBlockEntries.Add _
    Name:=stBlockName, Type:=wdTypeCustom5, Category:="Scenarios 20 - 42", Range:=oRng

    End Sub
    -----------------------------------------------------
    I find the "redefine" option in the Building Block organizer to work erratically - if at all. By deleting and and recreating the entry I know I've got the latest definition of the Building Block stored.
    Make sure the attached template is the template you want to work with.
    The user has to preselect the text that will be used for the building block.
    -----------------------------------------------------
    Sub ReplaceABlock()
    Dim MyAttachedTemplate As Template
    Dim stBlockName As String
    Dim inTypeName As Integer
    Dim stCat As String
    Dim objBBT As BuildingBlockType
    Dim myBB As BuildingBlock
    Dim oRng As Word.Range

    Set MyAttachedTemplate = ActiveDocument.AttachedTemplate
    Set oRng = Selection.Range

    'have the user pick the entry
    With Dialogs(wdDialogEditAutoText)
    .Display
    stBlockName = .Name
    End With

    'find the type and category of the Building block entry
    Set objBBT = MyAttachedTemplate.BuildingBlockEntries.Item(stBlo ckName).Type
    Set objCat = MyAttachedTemplate.BuildingBlockEntries.Item(stBlo ckName).Category
    inTypeName = objBBT.Index
    stCat = objCat.Name
    'Delete the Block
    MyAttachedTemplate.BuildingBlockTypes(inTypeName). Categories(stCat).BuildingBlocks(stBlockName).Dele te
    'Add the Block
    MyAttachedTemplate.BuildingBlockEntries.Add _
    Name:=stBlockName, Type:=inTypeName, Category:=stCat, Range:=oRng


    End Sub
    Last edited by WebGenii; 2013-04-25 at 15:22.
    [b]Catharine Richardson (WebGenii)
    WebGenii Home Page
    Moderator: Spreadsheets, Other MS Apps, Presentation Apps, Visual Basic for Apps, Windows Mobile

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •