![]() |
|
#6
|
||||
|
||||
|
How is this related to the original question where you wanted to "add a footnote reference in the bookmark [SymbolAst]"?
This new code has nothing to do with footnotes. Looking at your new code, I can see what the problem is. The issue is NOT what you think it is. When there is no separation between bookmarks AND you replace the contents of the first one with text, that text is added INSIDE the second bookmark (since inserting content immediately in front of a bookmark means the bookmark expands to include this content). This means that the next step of the macro replaces both bookmarks with the second replacement contents and restores only the second bookmark. To avoid this issue completely, I use Content Controls and replace the content inside them. This is far easier and less prone to odd behaviour. If you want to stay with the bookmarks method then you should change the approach a little bit. This code variation will work without destroying the bookmarks. Code:
Sub BMTest()
UpdateBookmark "BM1", "2021"
UpdateBookmark "BM2", "52"
UpdateBookmark "BM3", "10x"
End Sub
Private Sub UpdateBookmark(sBkName As String, sVal As String)
Dim aRng As Range, aDoc As Document, aRng2 As Range
Set aDoc = ActiveDocument
If aDoc.Bookmarks.Exists(sBkName) Then
Set aRng = aDoc.Bookmarks(sBkName).Range
aRng.InsertBefore sVal
aRng.MoveStart Unit:=wdCharacter, Count:=Len(sVal)
aRng.Text = ""
Else
Debug.Print "Bookmark not found: " & sBkName
End If
End Sub
__________________
Andrew Lockton Chrysalis Design, Melbourne Australia |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
Footnote references in the footnote section losing their style when cut+pasted from same doc
|
emblaw | Word | 4 | 12-08-2020 06:23 AM |
Removing line break and indentation between footnote number and footnote text in Word
|
jaanross | Word | 5 | 02-06-2020 12:04 AM |
| REf Fields show Bookmark whole cell when Bookmark is created by code. | pmcpowell | Word VBA | 2 | 11-16-2019 07:05 PM |
Adding footnote number as part of footnote text
|
NoCalScribe | Word VBA | 3 | 07-15-2019 07:20 PM |
| Find Bookmark, move to bookmark, execute code, repeat | raymm3852 | Word VBA | 10 | 04-15-2016 06:21 PM |