Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 09-30-2021, 02:00 AM
Guessed's Avatar
Guessed Guessed is offline Add footnote in a bookmark Windows 10 Add footnote in a bookmark Office 2016
Expert
 
Join Date: Mar 2010
Location: Canberra/Melbourne Australia
Posts: 4,176
Guessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant future
Default

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
Reply With Quote
  #2  
Old 09-30-2021, 03:42 AM
TheBigBoss TheBigBoss is offline Add footnote in a bookmark Windows 7 32bit Add footnote in a bookmark Office 2010 32bit
Advanced Beginner
Add footnote in a bookmark
 
Join Date: Dec 2016
Posts: 56
TheBigBoss is on a distinguished road
Default

Guessed,

I am sorry mixing two issues together and bringing confusion.
Please let me know if there is anything I can do to fix this such as editing the title

As for your code, it does the job. I had looked for a solution for days online and found none. Thank you very much for assisting

This thread can be marked "resolved".

Have a great day
Reply With Quote
Reply



Similar Threads
Thread Thread Starter Forum Replies Last Post
Add footnote in a bookmark Footnote references in the footnote section losing their style when cut+pasted from same doc emblaw Word 4 12-08-2020 06:23 AM
Add footnote in a bookmark 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
Add footnote in a bookmark 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

Other Forums: Access Forums

All times are GMT -7. The time now is 03:05 PM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2025, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2025 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft