D
David Turner
In the Word documents I translate, placeholder bookmarks (which appear as a
grey "I") are often inserted randomly right in the middle of a word.
When I import the file into the translation environment tool I use, such
bookmarks appear as a tag {1} in the middle of a word which prevents terms
being recognized (i.e. te{2}rm).
I thus want to move these placeholders to the end of the paragraph they are
located in.
I've spent hours trying to understand how these bookmarks work and looking
at related VBA code samples in the help, and after a lot of trial and error,
I at last came up with the code below.
When you step through it, it looks like its going to work. The first
bookmark is moved to the of the paragraph and the insertion point goes to the
start of the next paragraph. When it gets to the next loop, however, the code
does not go to the next bookmark but instead tries to go back to the first
one just moved. Can anyone put me straight. I guess it's some short of
range/selection collapse problem.
Many thanks in advance.
Sub MoveBkmrk()
Dim r As Range
Dim aBookmark As Bookmark
Dim char
If ActiveDocument.Bookmarks.Count >= 1 Then
ReDim aMarks(ActiveDocument.Bookmarks.Count - 1)
i = 0
For Each aBookmark In ActiveDocument.Bookmarks
If ActiveDocument.Bookmarks(aBookmark).Empty = True Then
aMarks(i) = aBookmark.Name
i = i + 1
aBookmark.Select
char = Selection.EndOf(Unit:=wdParagraph, Extend:=wdMove)
Selection.MoveLeft Unit:=wdCharacter, Count:=1
ActiveDocument.Bookmarks.Add Range:=Selection.Range,
Name:=ActiveDocument.Bookmarks(i).Name
Selection.MoveRight Unit:=wdCharacter, Count:=1
End If
Next aBookmark
End If
End Sub
grey "I") are often inserted randomly right in the middle of a word.
When I import the file into the translation environment tool I use, such
bookmarks appear as a tag {1} in the middle of a word which prevents terms
being recognized (i.e. te{2}rm).
I thus want to move these placeholders to the end of the paragraph they are
located in.
I've spent hours trying to understand how these bookmarks work and looking
at related VBA code samples in the help, and after a lot of trial and error,
I at last came up with the code below.
When you step through it, it looks like its going to work. The first
bookmark is moved to the of the paragraph and the insertion point goes to the
start of the next paragraph. When it gets to the next loop, however, the code
does not go to the next bookmark but instead tries to go back to the first
one just moved. Can anyone put me straight. I guess it's some short of
range/selection collapse problem.
Many thanks in advance.
Sub MoveBkmrk()
Dim r As Range
Dim aBookmark As Bookmark
Dim char
If ActiveDocument.Bookmarks.Count >= 1 Then
ReDim aMarks(ActiveDocument.Bookmarks.Count - 1)
i = 0
For Each aBookmark In ActiveDocument.Bookmarks
If ActiveDocument.Bookmarks(aBookmark).Empty = True Then
aMarks(i) = aBookmark.Name
i = i + 1
aBookmark.Select
char = Selection.EndOf(Unit:=wdParagraph, Extend:=wdMove)
Selection.MoveLeft Unit:=wdCharacter, Count:=1
ActiveDocument.Bookmarks.Add Range:=Selection.Range,
Name:=ActiveDocument.Bookmarks(i).Name
Selection.MoveRight Unit:=wdCharacter, Count:=1
End If
Next aBookmark
End If
End Sub