Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 08-10-2025, 01:23 AM
RRB's Avatar
RRB RRB is offline Brackets around FN references Windows 11 Brackets around FN references Office 2021
Susan Flamingo
Brackets around FN references
 
Join Date: May 2014
Location: The Holy City of Jerusalem
Posts: 302
RRB is on a distinguished road
Default Brackets around FN references

Hi, Dear Friends!



I asked ChatGPT to write a macro that inserts a footnote and then places square brackets around the FN reference in the main text area, formatting the whole string as superscript.

It gave me this:

Quote:
Sub InsertFootnoteWithBracketsAndSuperscript()
' This macro overrides the default Ctrl+Alt+F behavior for inserting footnotes.
' It inserts the footnote reference within square brackets and formats the
' entire string (brackets + reference) as superscript.

Dim newFootnote As Footnote
Dim footnoteAreaRefRange As Range
Dim footnoteAreaRange As Range
Dim footnoteRefRange As Range
Dim originalSelectionRange As Range

' Disable screen updating to prevent visual flickering during the macro execution.
Application.ScreenUpdating = False

' Error handling in case something goes wrong.
On Error GoTo ErrorHandler

' Store the current selection or insertion point in the main document.
Set originalSelectionRange = Selection.Range.Duplicate

' 1. Insert the footnote at the current cursor position.
' The Footnotes.Add method inserts the footnote reference number (e.g., "¹")
' and automatically moves the cursor to the footnote text area at the bottom
' of the page/document, ready for the user to type the footnote content.
Set newFootnote = ActiveDocument.Footnotes.Add(Range:=originalSelect ionRange)

' 2. Get the Range object that represents the newly inserted footnote reference
' number in the main document text (e.g., the "¹" itself).
Set footnoteRefRange = newFootnote.Reference

' 3. Insert the opening square bracket "[" immediately before the footnote reference.
' The 'footnoteRefRange' object will automatically adjust its starting point
' to include this newly inserted character.
footnoteRefRange.InsertBefore "["

' 4. Insert the closing square bracket "]" immediately after the footnote reference.
' The 'footnoteRefRange' object will automatically adjust its ending point
' to include this newly inserted character. At this point, 'footnoteRefRange'
' now encompasses the entire string, e.g., "[¹]".
footnoteRefRange.InsertAfter "]"

' 5. Apply superscript formatting to the entire range, which now includes
' both the brackets and the footnote reference number.
footnoteRefRange.font.Superscript = True
' Re-enable screen updating.
Application.ScreenUpdating = True

Exit Sub
This works fine. But then I asked it to also enclose the new FN reference in the FN area in square brackets and format the entire string as regular text, and then place the cursor after that so I can start writing the actual FN. It just cannot get it right!

Can we outdo him?

Thank you, and have a good day!
Susan Flamingo

Last edited by RRB; 08-10-2025 at 01:24 AM. Reason: typos
Reply With Quote
  #2  
Old 08-10-2025, 03:44 PM
macropod's Avatar
macropod macropod is offline Brackets around FN references Windows 10 Brackets around FN references Office 2016
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 22,465
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

You could use a macro like the following:
Code:
Sub InsertFootnote()
Dim Rng As Range: Set Rng = Selection.Range
Application.Dialogs(wdDialogInsertFootnote).Execute
Rng.End = Rng.End + 1: Rng.InsertBefore "[": Rng.InsertAfter "]": Rng.Style = wdStyleFootnoteReference
Selection.Start = Selection.Start - 1
Set Rng = Selection.Range: Rng.Collapse wdCollapseStart
Rng.Start = Rng.Start - 1: Rng.InsertBefore "[": Rng.InsertAfter "]": Rng.Style = wdStyleFootnoteReference
Selection.Collapse wdCollapseEnd
If ActiveWindow.ActivePane.View.Type = wdPrintView Or ActiveWindow. _
  ActivePane.View.Type = wdWebView Or ActiveWindow.ActivePane.View.Type = wdPrintPreview Then
  ActiveWindow.View.SeekView = wdSeekFootnotes
Else
  ActiveWindow.View.SplitSpecial = wdPaneFootnotes
End If
End Sub
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #3  
Old 08-11-2025, 12:10 AM
RRB's Avatar
RRB RRB is offline Brackets around FN references Windows 11 Brackets around FN references Office 2021
Susan Flamingo
Brackets around FN references
 
Join Date: May 2014
Location: The Holy City of Jerusalem
Posts: 302
RRB is on a distinguished road
Default Works great - thank you!

I guess we still need some real intelligence from real people
Reply With Quote
Reply



Similar Threads
Thread Thread Starter Forum Replies Last Post
Brackets around FN references VBA Format text in brackets to Italics but only after cross references Shelley Lou Word VBA 4 01-07-2025 01:13 PM
Subscript and bold number between square brackets and remove square brackets nonno Word 0 02-10-2024 08:23 AM
Find and delet all text within brackets and the brackets themselves ranjan Word VBA 2 07-22-2021 01:06 AM
Brackets around FN references find and delet all text within brackets and the brackets themselves wrdy Word 2 08-03-2017 06:55 PM
Convert manual cross references in footnotes to other footnotes to automatic cross references ghumdinger Word VBA 7 11-20-2014 11:47 PM

Other Forums: Access Forums

All times are GMT -7. The time now is 09:08 AM.


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