|
|
Thread Tools | Display Modes |
#1
|
|||
|
|||
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 Any help is appreciated. TIA |
#2
|
||||
|
||||
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 |
#3
|
|||
|
|||
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 |
#4
|
||||
|
||||
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 |
#5
|
|||
|
|||
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 |
#6
|
||||
|
||||
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
__________________
Andrew Lockton Chrysalis Design, Melbourne Australia |
#7
|
|||
|
|||
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 |
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 '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 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 |