Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 03-23-2025, 11:42 PM
gcp gcp is offline VBA Word Macro - remove superscript footnote ref Windows 11 VBA Word Macro - remove superscript footnote ref Office 2021
Novice
VBA Word Macro - remove superscript footnote ref
 
Join Date: Mar 2025
Posts: 17
gcp is on a distinguished road
Default VBA Word Macro - remove superscript footnote ref

I am trying to learn VBA - after previous attempts that defeated me. (I was OK with WordPerfect. Not WordPerfect VBA)


As a starting attempt, I have documents with superscripts in the form "(X)" where "X" may be up to 3 characters depending on the number of total footnotes. I want a macro that will remove all those superscript references. I assume that this would have already been done, if anybody can point me to appropriate code. If I can get some code that might be a good way of starting to learn VBA. Co-Pilot wrote some code for me but it didn't work.
Reply With Quote
  #2  
Old 03-24-2025, 03:57 AM
Guessed's Avatar
Guessed Guessed is offline VBA Word Macro - remove superscript footnote ref Windows 10 VBA Word Macro - remove superscript footnote ref Office 2016
Expert
 
Join Date: Mar 2010
Location: Canberra/Melbourne Australia
Posts: 4,159
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

The footnote references are linked to the footnotes so if you want to remove one, you also remove the other.
Code:
Sub KillAllFootnotes()
  Do While ActiveDocument.Footnotes.Count > 0
    ActiveDocument.Footnotes(1).Delete
  Loop
End Sub
__________________
Andrew Lockton
Chrysalis Design, Melbourne Australia
Reply With Quote
  #3  
Old 03-24-2025, 05:01 PM
macropod's Avatar
macropod macropod is offline VBA Word Macro - remove superscript footnote ref Windows 10 VBA Word Macro - remove superscript footnote ref Office 2016
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 22,370
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 don't even need a macro for that. A basic wildcard Find/Replace will do:
Find = \(*\)
Replace = nothing
where the Find format is specified as superscript.
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #4  
Old 03-24-2025, 09:22 PM
gcp gcp is offline VBA Word Macro - remove superscript footnote ref Windows 11 VBA Word Macro - remove superscript footnote ref Office 2021
Novice
VBA Word Macro - remove superscript footnote ref
 
Join Date: Mar 2025
Posts: 17
gcp is on a distinguished road
Default Remove superscript footnote

Thanks Paul. I couldn't make that work as "Replace = nothing
where the Find format is specified as superscript" is beyond my abilities.
In any event, my aim is to learn to write VBA macros.
Reply With Quote
  #5  
Old 03-24-2025, 09:43 PM
gcp gcp is offline VBA Word Macro - remove superscript footnote ref Windows 11 VBA Word Macro - remove superscript footnote ref Office 2021
Novice
VBA Word Macro - remove superscript footnote ref
 
Join Date: Mar 2025
Posts: 17
gcp is on a distinguished road
Default Remove superscript footnote

Thanks Paul (in Canberra). I selected "Find what: \(*\)". "Options: Use Wildcards". "Format: Superscript" but the result was "All done. We made 0 replacements"
In any event, my aim is to learn to write VBA macros so this task is to get me started.
I'd be interested to know why the replace did not work, but I'm more interested in trying to learn VBA.
gcp in Sydney
Reply With Quote
  #6  
Old 03-24-2025, 09:54 PM
gcp gcp is offline VBA Word Macro - remove superscript footnote ref Windows 11 VBA Word Macro - remove superscript footnote ref Office 2021
Novice
VBA Word Macro - remove superscript footnote ref
 
Join Date: Mar 2025
Posts: 17
gcp is on a distinguished road
Default

This is the code that Co-Pilot wrote for me, that doesn't work. It has elements of Paul's replace that, as a novice, I can follow. As I sat, I am trying to get my head around VBA and I hope that making this work will give me some good tuition.

Sub DeleteSuperscriptText()
Dim rng As Range
Dim startPos As Long
Dim endPos As Long

Set rng = ActiveDocument.Content
With rng.Find
.ClearFormatting
.Font.Superscript = True
.Text = "\(*\)"
.Forward = True
.Wrap = wdFindStop
.Format = True
.MatchWildcards = True

Do While .Execute
If rng.Font.Superscript = True Then
startPos = rng.Start
endPos = rng.End

' Adjust the range to select the characters between "(" and ")"
rng.SetRange startPos + 1, endPos - 1

' Delete the characters
rng.Delete

' Move the cursor to the next non-superscript position
Set rng = ActiveDocument.Range(rng.End, ActiveDocument.Content.End)
If rng.Find.Execute(FindText:="", Forward:=True, Wrap:=wdFindStop) Then
If rng.Font.Superscript = False Then
rng.Collapse wdCollapseStart
Exit Sub
End If
End If
End If
Loop
End With
End Sub
Reply With Quote
  #7  
Old 03-24-2025, 10:43 PM
macropod's Avatar
macropod macropod is offline VBA Word Macro - remove superscript footnote ref Windows 10 VBA Word Macro - remove superscript footnote ref Office 2016
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 22,370
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

Quote:
Originally Posted by gcp View Post
Thanks Paul. I couldn't make that work as "Replace = nothing
where the Find format is specified as superscript" is beyond my abilities.
In any event, my aim is to learn to write VBA macros.
I tested it and it worked for me. Are your parentheses superscripted?

As a macro, the Find/Replace becomes:
Code:
Sub DemoA()
Application.ScreenUpdating = False
With ActiveDocument.Range.Find
  .ClearFormatting
  .Replacement.ClearFormatting
  .Font.Superscript = True
  .Text = "\(*\)"
  .Replacement.Text = ""
  .Forward = True
  .Wrap = wdFindContinue
  .Format = False
  .MatchWildcards = True
  .Execute Replace:=wdReplaceAll
End With
Application.ScreenUpdating = True
End Sub
or even:
Code:
Sub DemoB()
Application.ScreenUpdating = False
With ActiveDocument.Range.Find
  .ClearFormatting
  .Replacement.ClearFormatting
  .Font.Superscript = True
  .Execute FindText:="\(*\)", ReplaceWith:="", MatchWildcards:=True, Format:=False, Forward:=True, Wrap:=wdFindContinue, Replace:=wdReplaceAll
End With
Application.ScreenUpdating = True
End Sub
Avoid generative AI VBA code - it's frequently bug-ridden. Even Word's macro recorder would have done better in this instance.
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #8  
Old 03-27-2025, 06:31 PM
gcp gcp is offline VBA Word Macro - remove superscript footnote ref Windows 11 VBA Word Macro - remove superscript footnote ref Office 2021
Novice
VBA Word Macro - remove superscript footnote ref
 
Join Date: Mar 2025
Posts: 17
gcp is on a distinguished road
Default

Thanks Paul. DemoB() works. Some of the footnotes had square brackets, so I added that to the macro. Thanks for your help. Little by little I'm getting there.
Reply With Quote
  #9  
Old 03-27-2025, 06:41 PM
macropod's Avatar
macropod macropod is offline VBA Word Macro - remove superscript footnote ref Windows 10 VBA Word Macro - remove superscript footnote ref Office 2016
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 22,370
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

To cater for both, you could use a single Find expression with:
"[\(\[]*[\)\]]"
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #10  
Old 03-31-2025, 08:07 PM
gcp gcp is offline VBA Word Macro - remove superscript footnote ref Windows 11 VBA Word Macro - remove superscript footnote ref Office 2021
Novice
VBA Word Macro - remove superscript footnote ref
 
Join Date: Mar 2025
Posts: 17
gcp is on a distinguished road
Default Remove superscript footnote

Sorry to bother you. I lost my macros and couldn't find them. Normal.dotm was in templates but it apparently didn't have any macros in it. I have now re-entered your DemoB() but it won't run as it did before. I have made sure that it was copied exactly from your code below. Any hints?
Reply With Quote
  #11  
Old 03-31-2025, 08:23 PM
macropod's Avatar
macropod macropod is offline VBA Word Macro - remove superscript footnote ref Windows 10 VBA Word Macro - remove superscript footnote ref Office 2016
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 22,370
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

It's possible the problem isn't with your Normal.dotm but that you've managed to change your system's VBA security settings so as to disable all macros. See under File|Options|Trust Center>Trust Center Settings. The 'Disable all macros with notification' option should be checked.
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #12  
Old 03-31-2025, 11:16 PM
gcp gcp is offline VBA Word Macro - remove superscript footnote ref Windows 11 VBA Word Macro - remove superscript footnote ref Office 2021
Novice
VBA Word Macro - remove superscript footnote ref
 
Join Date: Mar 2025
Posts: 17
gcp is on a distinguished road
Default Remove superscript footnote

Thanks Paul. I had checked that and just checked it again. The macros are enabled as is "Trust access to the VBA project object model". I didn't think it was the security settings as my other macro works fine on the same document.
Reply With Quote
  #13  
Old 04-01-2025, 09:53 AM
Italophile Italophile is offline VBA Word Macro - remove superscript footnote ref Windows 11 VBA Word Macro - remove superscript footnote ref Office 2021
Expert
 
Join Date: Mar 2022
Posts: 539
Italophile is just really niceItalophile is just really niceItalophile is just really niceItalophile is just really nice
Default

Quote:
Originally Posted by gcp View Post
Thanks Paul. I had checked that and just checked it again. The macros are enabled as is "Trust access to the VBA project object model". I didn't think it was the security settings as my other macro works fine on the same document.
Unless you really know what you are doing and are using VBA code to manipulate other VBA code, "Trust access to the VBA project object model" should be disabled.
Reply With Quote
  #14  
Old 04-02-2025, 12:30 AM
gcp gcp is offline VBA Word Macro - remove superscript footnote ref Windows 11 VBA Word Macro - remove superscript footnote ref Office 2021
Novice
VBA Word Macro - remove superscript footnote ref
 
Join Date: Mar 2025
Posts: 17
gcp is on a distinguished road
Default Remove superscript footnote

The footnotes were hyperlinked, so I added
Selection.WholeStory
Selection.Fields.Unlink
And it now works.
Thanks for the help
Reply With Quote
  #15  
Old 04-02-2025, 03:00 PM
macropod's Avatar
macropod macropod is offline VBA Word Macro - remove superscript footnote ref Windows 10 VBA Word Macro - remove superscript footnote ref Office 2016
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 22,370
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

Instead of
Code:
Selection.WholeStory
Selection.Fields.Unlink
use
Code:
ActiveDocument.Fields.Unlink
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
Reply



Similar Threads
Thread Thread Starter Forum Replies Last Post
VBA Word Macro - remove superscript footnote ref Word Macro for removing parentheses around footnote numbers LLLCa947 Word VBA 6 11-21-2024 01:44 AM
VBA Word Macro - remove superscript footnote ref Convert superscript numbers to auto-footnote markers ra_beale Word VBA 4 09-05-2022 07:09 AM
VBA Word Macro - remove superscript footnote ref How to remove extra space between footnote separator and 1st footnote. No para breaks present. Swarup Word 2 07-09-2022 07:42 PM
VBA Word Macro - remove superscript footnote ref Macro to change font size of Footnote Reference in Footnote Text TheBigBoss Word VBA 5 06-10-2022 06:14 AM
VBA Word Macro - remove superscript footnote ref Footnote reference numbers precede by superscript '(' and follow w/ superscript ')' Swarup Word 4 07-18-2019 05:51 PM

Other Forums: Access Forums

All times are GMT -7. The time now is 08:00 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