Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 11-10-2016, 01:45 AM
Katherine1995 Katherine1995 is offline Run-time error '-2147467259 (80004005)': Method 'Insert' of object 'BuildingBlock' failed Windows 10 Run-time error '-2147467259 (80004005)': Method 'Insert' of object 'BuildingBlock' failed Office 2016
Novice
Run-time error '-2147467259 (80004005)': Method 'Insert' of object 'BuildingBlock' failed
 
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
  #2  
Old 11-10-2016, 05:56 PM
Guessed's Avatar
Guessed Guessed is offline Run-time error '-2147467259 (80004005)': Method 'Insert' of object 'BuildingBlock' failed Windows 10 Run-time error '-2147467259 (80004005)': Method 'Insert' of object 'BuildingBlock' failed Office 2013
Expert
 
Join Date: Mar 2010
Location: Canberra/Melbourne Australia
Posts: 3,977
Guessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant future
Default

There is nothing intrinsically wrong with your code but it might be related to content in your BuildingBlock. Is it possible via the GUI interface to insert a second copy of the BB in the location of the bookmark?
__________________
Andrew Lockton
Chrysalis Design, Melbourne Australia
Reply With Quote
  #3  
Old 11-10-2016, 06:23 PM
Katherine1995 Katherine1995 is offline Run-time error '-2147467259 (80004005)': Method 'Insert' of object 'BuildingBlock' failed Windows 10 Run-time error '-2147467259 (80004005)': Method 'Insert' of object 'BuildingBlock' failed Office 2016
Novice
Run-time error '-2147467259 (80004005)': Method 'Insert' of object 'BuildingBlock' failed
 
Join Date: Nov 2016
Posts: 4
Katherine1995 is on a distinguished road
Default

Hi Guessed,

It is all via Command button in the WORD file(the desired interface for the client).
I am able to insert the building block successfully at the bookmark the 1st time (command button click).
But 2nd time click on the command button is giving me this error.

Note: The bookmark is re-inserted as per the code. So, the bookmark exists.

Is something wrong with the range?

Thanks
Reply With Quote
  #4  
Old 11-10-2016, 07:53 PM
Guessed's Avatar
Guessed Guessed is offline Run-time error '-2147467259 (80004005)': Method 'Insert' of object 'BuildingBlock' failed Windows 10 Run-time error '-2147467259 (80004005)': Method 'Insert' of object 'BuildingBlock' failed Office 2013
Expert
 
Join Date: Mar 2010
Location: Canberra/Melbourne Australia
Posts: 3,977
Guessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant future
Default

The code works for me on repeated running but I am using a different BB to you. Is there something about the BB that doesn't allow you to insert something into it (eg Content Controls, Table, Floating shapes etc).

After running the code once, are you able to insert the same BB in the same location without using a macro?

Perhaps you could upload the template so we can take a look at what is going on.
__________________
Andrew Lockton
Chrysalis Design, Melbourne Australia
Reply With Quote
  #5  
Old 11-11-2016, 01:08 AM
Katherine1995 Katherine1995 is offline Run-time error '-2147467259 (80004005)': Method 'Insert' of object 'BuildingBlock' failed Windows 10 Run-time error '-2147467259 (80004005)': Method 'Insert' of object 'BuildingBlock' failed Office 2016
Novice
Run-time error '-2147467259 (80004005)': Method 'Insert' of object 'BuildingBlock' failed
 
Join Date: Nov 2016
Posts: 4
Katherine1995 is on a distinguished road
Lightbulb you 'guessed' it right! :)

My building block had ActiveX radio buttons & Combobox. I replaced them with a static checkbox and it worked.
But the thing I need is radio buttons to map 2 different fields of 7 & 3 options each (which otherwise will have to be handled with 21 different combinations of building blocks) which is not practical.

Any suggestions??

TIA
Reply With Quote
  #6  
Old 11-11-2016, 09:10 PM
Guessed's Avatar
Guessed Guessed is offline Run-time error '-2147467259 (80004005)': Method 'Insert' of object 'BuildingBlock' failed Windows 10 Run-time error '-2147467259 (80004005)': Method 'Insert' of object 'BuildingBlock' failed Office 2013
Expert
 
Join Date: Mar 2010
Location: Canberra/Melbourne Australia
Posts: 3,977
Guessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant future
Default

It sounds like the position of the bookmark is locked in some way so that the BB cannot be inserted there. Perhaps if you offset the insertion point by one character then there wouldn't be a need to keep resetting the bookmark location
Code:
  Dim objTemplate As Template
  Dim objBB5 As BuildingBlock
  Dim BBName As String 'Building Block String
  Dim BM1 As String 'Bookmark String
  Dim Rng5 As Range
   
  BM1 = "Bookmark1"
  Set objTemplate = ActiveDocument.AttachedTemplate
  Set Rng5 = ActiveDocument.Bookmarks(BM1).Range
  Rng5.InsertAfter "  "  'two spaces
  Rng5.Start = Rng5.End + 1   'collapse the range to between those spaces
  BBName = "One"
  Set objBB5 = objTemplate.BuildingBlockTypes(wdTypeAutoText).Categories("General").BuildingBlocks(BBName)
  objBB5.Insert Rng5, True  'INSERT Building BLOCK
An alternative is the redo the BuildingBlock to include a space before whatever comes first
__________________
Andrew Lockton
Chrysalis Design, Melbourne Australia
Reply With Quote
  #7  
Old 11-17-2016, 12:04 PM
Katherine1995 Katherine1995 is offline Run-time error '-2147467259 (80004005)': Method 'Insert' of object 'BuildingBlock' failed Windows 10 Run-time error '-2147467259 (80004005)': Method 'Insert' of object 'BuildingBlock' failed Office 2016
Novice
Run-time error '-2147467259 (80004005)': Method 'Insert' of object 'BuildingBlock' failed
 
Join Date: Nov 2016
Posts: 4
Katherine1995 is on a distinguished road
Thumbs up Problem resolved....(RCA: ActiveX content controls in Building Block)

Hi,

The above change in Range did not work either. The problem was the content controls in the building block. INSERT does not work in a loop if building block has any ActiveX component as it has to assign unique name for each of them at every INSERT in the document and I was initializing them on document OPEN & NEW event. So, when I redefined the blocks with non-ActiveX drop downs it just worked.

@ guessed : Thanks for all your help.

Cheers
Reply With Quote
Reply

Tags
bookmark, building blocks, insert



Similar Threads
Thread Thread Starter Forum Replies Last Post
ADODB import of Excel data results in "Run-time error -2147467259: <sheet> is not a valid name." misaak Excel Programming 3 06-20-2016 07:55 AM
Run-time error '-2147467259 (80004005)': Method 'Insert' of object 'BuildingBlock' failed Run-time error '424': Object required zlodeh Excel Programming 1 02-24-2016 01:58 AM
Run time error - Pivot Cache Failed patrick1063 Excel Programming 0 02-08-2016 07:56 PM
Run-time error '-2147467259 (80004005)': Method 'Insert' of object 'BuildingBlock' failed Run Time Error 424 - Object Required Doug Needham Excel Programming 4 01-12-2015 10:54 PM
OUTLOOK : the operation failed. an object cannot be found luotzabl Outlook 0 02-28-2010 02:48 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 12:26 AM.


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