move hiddenbookmarks to the end of paragraph

J

JAS

is it possible to move hidden bookmarks to the end of the paragraph?
I work with special tools for translators, where Word documents are imported
and formatting/bookmarks etc are shown as codes. In quite a few cases hidden
bookmarks create so many codes inside single words, that I would prefer to
the bookmark either at the end of the paragraph or at least at the end of
the word.

Kind regards and thanks
Judy Ann
 
J

Jonathan West

Hi Judy

JAS said:
is it possible to move hidden bookmarks to the end of the paragraph?
I work with special tools for translators, where Word documents are imported
and formatting/bookmarks etc are shown as codes. In quite a few cases hidden
bookmarks create so many codes inside single words, that I would prefer to
the bookmark either at the end of the paragraph or at least at the end of
the word.

The problem with doing this is that the hidden bookmarks are inserted by
Word for a reason, so it would be a bad idea to move them.

However, quite often bookmarks are left behind even when no longer needed,
so it is probably safe to remove some of them. The trick is knowing which
ones can be removed.

The most common cause of hidden bookmarks being inserted in a document is
rebuilding the table of contents. When that is done, a new bookmark is put
down on every heading, and no attempt is made to re-use the older one. So
the hidden bookmarks that have names beginnign with _Toc can all be deleted,
provided that you rebuild the ToC once more immediately afterwards. This
might cut down the number of bookmarks present by a surprising amount. The
following code does the needful, and displays its progress on the status bar
of the document window

Sub RebuildToC()
Dim i As Long
Dim j As Long
Dim k As Long
ActiveDocument.Bookmarks.ShowHidden = True
For i = ActiveDocument.Bookmarks.Count To 1 Step -1
j = j + 1
If LCase$(Left$(ActiveDocument.Bookmarks(i).Name, 4)) = "_toc" Then
ActiveDocument.Bookmarks(i).Delete
k = k + 1
End If
Application.StatusBar = j & " bookmarks checked, " & k & " bookmarks
deleted."
Next i
ActiveDocument.TablesOfContents(1).Update
End Sub
 
J

JAS

Hi Jonathan, thanks for the answer,
Normally the hidden bookmarks from word show up as a code at the end of the
paragraph or of a word in my tool. These are no problem. but I have one
customer who manages to put the bookmarks into the document in a way, that
they somehwo spread over the entire word or paragraph. leavng me with codes
after every letter. My idea was, if word normaly puts them in at the end of
a word/paragraph it would not harm to move them to that place. the bookmarks
are not from the toc, they all look like _Hlt23219756
kind regards
Judy Ann
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top