Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 12-21-2015, 09:50 AM
ljg713 ljg713 is offline Delete Line of Bookmark if the Text is Empty Windows 7 64bit Delete Line of Bookmark if the Text is Empty Office 2010 64bit
Novice
Delete Line of Bookmark if the Text is Empty
 
Join Date: Dec 2015
Posts: 20
ljg713 is on a distinguished road
Default 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!
Reply With Quote
  #2  
Old 12-21-2015, 04:27 PM
macropod's Avatar
macropod macropod is offline Delete Line of Bookmark if the Text is Empty Windows 7 64bit Delete Line of Bookmark if the Text is Empty Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,962
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

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]
Reply With Quote
Reply

Tags
bookmark, vba

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
Delete Line of Bookmark if the Text is Empty Delete row with empty cel in a table vibor Word VBA 9 05-03-2015 05:42 AM
Delete Line of Bookmark if the Text is Empty 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
Delete Line of Bookmark if the Text is Empty Search for text then delete line konopca Word VBA 2 06-07-2012 02:44 AM
Delete Line of Bookmark if the Text is Empty delete all bookmark text hklein Word VBA 4 08-10-2011 04:33 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 02:21 PM.


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