#1
|
|||
|
|||
Delete Line of Bookmark if the Text is Empty
Hello,
I have several bookmarks in a word document that I am populating via a method using content control and pulling data from excel. A dropdown at the top of the document contains 20 different account names, and when the user chooses one, the bookmarks populate from excel data specific to each account. Some of the bookmarks do not have any corresponding data in Excel, and are therefore blank. When this happens, I would like to delete the bookmark's line, because it looks as if there is an extra blank line. However, the bookmark must be reinserted when a new dropdown selection is chosen, because it will hold data for the other accounts. I have tried the following code: Dim oBMName As Range Set oBMName = ActiveDocument.Bookmarks("Bookmark1").Range ActiveDocument.Bookmarks("Bookmark1").Select If Selection.Range = "" Then Selection.Bookmarks("\Line").Range.Delete ActiveDocument.Bookmarks.Add "Bookmark1", oBMName End If This doesn't work. The document has bookmarks set up in the following way; Bookmark1 Bookmark2 Bookmark3 The code when run does delete Bookmark1 if it is empty. However, when I change the dropdown to an account that has a populated Bookmark1, the text looks like this: Bookmark2Bookmark1 Bookmark3 So, it is inserting Bookmark1 within Bookmark2. I know this is happening because when I delete the line, it looks like this Bookmark2 Bookmark3 and when I re-insert Bookmark1 with the code where it was previously, it now goes right after Bookmark2. Sorry if this is confusing! |
#2
|
||||
|
||||
Cross-posted at: http://answers.microsoft.com/en-us/o...77fa842?page=2
For cross-posting etiquette, please read: http://www.excelguru.ca/content.php?184
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
Tags |
bookmark, vba |
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
Delete row with empty cel in a table | vibor | Word VBA | 9 | 05-03-2015 05:42 AM |
Delete empty cell and shift up | Linh | Word Tables | 1 | 09-21-2014 01:52 PM |
Can you prevent an empty line from appearing in the first line of a page? | New Daddy | Word | 10 | 11-18-2013 07:01 AM |
Search for text then delete line | konopca | Word VBA | 2 | 06-07-2012 02:44 AM |
delete all bookmark text | hklein | Word VBA | 4 | 08-10-2011 04:33 AM |