![]() |
|
|
Thread Tools | Display Modes |
#1
|
|||
|
|||
![]()
Hello and Happy New Year.
First of all, I'm new to this (as I'm sure you can see), but trying to learn as best I can, by doing. I have hit a wall, however. I have a macro which inserts a building block from my custom library when a button is clicked in the ribbon in word (button added using Custom UI Editor). This works fine, though if a user has mistakenly selected a number of cells in a Table in the word document and tries to insert the building block, it creates an error (see figure attached). My approach set out below. Sub Macro1() Dim WrdTemplate As Template Dim objBB As BuildingBlock Dim WrdRng As Range Set WrdTemplate = Application.Templates("filepath") Set objBB = WrdTemplate.BuildingBlockTypes(wdTypeCustom1).Cate gories("Legislation").BuildingBlocks("END") objBB.Insert Selection.Range End Sub I tried to get around this by changing objBB.Insert Selection.Range to objBB.Insert ActiveDocument.Range and this does avoid the error, though it overwrites the last building block I added and I need to be able to add multiple. Is there a way to handle this error so that, if a user has selected multiple cells in a table and they try to insert a building block there, an error box comes up and prevents the action? Many thanks |
|
![]() |
||||
Thread | Thread Starter | Forum | Replies | Last Post |
![]() |
chriscla | Word VBA | 16 | 04-04-2020 10:41 PM |
Error Handler If User Does Not Want to Overwrite File | ChrisOK | Excel Programming | 4 | 04-03-2020 08:31 PM |
Error when inserting Quick Table created | taryn | Word | 2 | 09-11-2017 05:44 AM |
Formatting Issues When Using If Statements and Inserting Building Blocks/Autotext | sanko787 | Mail Merge | 1 | 07-05-2014 09:00 PM |
![]() |
rollno | Word | 7 | 02-24-2014 04:29 PM |