View Single Post
 
Old 11-10-2016, 01:45 AM
Katherine1995 Katherine1995 is offline Windows 10 Office 2016
Novice
 
Join Date: Nov 2016
Posts: 4
Katherine1995 is on a distinguished road
Question Run-time error '-2147467259 (80004005)': Method 'Insert' of object 'BuildingBlock' failed

I am getting the following error on the 2nd click on the command button.

Run-time error '-2147467259 (80004005)': Method 'Insert' of object 'BuildingBlock' failed

I am trying to insert the same building block at a bookmark on the click of the command button. It inserts the block successfully during the 1st click. But, on the 2nd click, the above error occurs.

Here is my code:

Code:
Private Sub ClickToAddButton_Click()

 Dim objTemplate As Template
     Dim objBB5 As BuildingBlock
     Dim BBName As String 'Building Block String
     Dim BM1 As String 'Bookmark String
     Dim Rng5, Rng5t As Range
       
    BM1 = "Bookmark1"
    Set objTemplate = ActiveDocument.AttachedTemplate
    Set Rng5 = ActiveDocument.Bookmarks(BM1).Range
    Set Rng5t = Rng5.Duplicate
    Rng5.Collapse wdCollapseEnd
        
      BBName = "MyBuildingBlock"
                       
Set objBB5 = objTemplate.BuildingBlockTypes(wdTypeAutoText).Categories("General").BuildingBlocks(BBName)

'INSERT Building BLOCK
objBB5.Insert Rng5, True              

 'After every INSERT of Building block -- reset the range variable & Re-Insert Bookmark
 Rng5.Start = Rng5t.Start
 ActiveDocument.Bookmarks.Add BM1, Rng5
           
End Sub
Can anyone point out what is wrong with my code?
Any help is appreciated.

TIA
Reply With Quote