Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 09-30-2023, 12:27 AM
RobiNew RobiNew is offline Change superscripts to regular text except footnote marks without using 'Selection.' Windows 10 Change superscripts to regular text except footnote marks without using 'Selection.' Office 2016
Competent Performer
Change superscripts to regular text except footnote marks without using 'Selection.'
 
Join Date: Sep 2023
Posts: 183
RobiNew is on a distinguished road
Default Change superscripts to regular text except footnote marks without using 'Selection.'

I have the macro here below to change superscripts to regular text except for footnote marks. It works OK, but now I need the same result without using 'Selection'. Can someone help? Thanks!



Quote:
Selection.Find.ClearFormatting
With Selection.Find.Font
.Superscript = True
.Subscript = False
End With
Selection.Find.Replacement.ClearFormatting
With Selection.Find.Replacement.Font
.Superscript = False
.Subscript = False
End With
With Selection.Find
.Text = "[!^02]"
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindContinue
.Format = True
.MatchCase = False
.MatchWholeWord = False
.MatchAllWordForms = False
.MatchSoundsLike = False
.MatchWildcards = True
End With
Selection.Find.Execute Replace:=wdReplaceAll
Reply With Quote
  #2  
Old 09-30-2023, 08:00 AM
vivka vivka is offline Change superscripts to regular text except footnote marks without using 'Selection.' Windows 7 64bit Change superscripts to regular text except footnote marks without using 'Selection.' Office 2016
Competent Performer
 
Join Date: Jul 2023
Posts: 227
vivka is on a distinguished road
Default

Hi, RobiNew! Just replace selection with ActiveDocument.range:
Code:
Sub Macro()

Dim oRng As range
Set oRng = ActiveDocument.range
    oRng.Find.ClearFormatting
    With oRng.Find.Font
        .Superscript = True
    End With
    oRng.Find.Replacement.ClearFormatting
    With oRng.Find.Replacement.Font
        .Superscript = False
    End With
    oRng.Find.Execute Replace:=wdReplaceAll
End Sub
Note that this is the fastest replacement.
Reply With Quote
  #3  
Old 09-30-2023, 09:04 AM
RobiNew RobiNew is offline Change superscripts to regular text except footnote marks without using 'Selection.' Windows 10 Change superscripts to regular text except footnote marks without using 'Selection.' Office 2016
Competent Performer
Change superscripts to regular text except footnote marks without using 'Selection.'
 
Join Date: Sep 2023
Posts: 183
RobiNew is on a distinguished road
Default

Thanks a lot, Vivka! That's very instructive. Can you modify the code so as to leave superscript footnote marks unchanged? This is what I need. Thanks again!
Reply With Quote
  #4  
Old 09-30-2023, 09:25 AM
vivka vivka is offline Change superscripts to regular text except footnote marks without using 'Selection.' Windows 7 64bit Change superscripts to regular text except footnote marks without using 'Selection.' Office 2016
Competent Performer
 
Join Date: Jul 2023
Posts: 227
vivka is on a distinguished road
Default

I didn't check it, but hopefully it will work properly:

Code:
Sub Macro()

Dim oRng As range
Set oRng = ActiveDocument.StoryRanges(1)
    oRng.Find.ClearFormatting
    With oRng.Find.Font
        .Superscript = True
    End With
    oRng.Find.Replacement.ClearFormatting
    With oRng.Find.Replacement.Font
        .Superscript = False
    End With
     oRng.Find.Execute Replace:=wdReplaceAll
set oRng = Nothing
End Sub
Reply With Quote
  #5  
Old 09-30-2023, 10:07 AM
RobiNew RobiNew is offline Change superscripts to regular text except footnote marks without using 'Selection.' Windows 10 Change superscripts to regular text except footnote marks without using 'Selection.' Office 2016
Competent Performer
Change superscripts to regular text except footnote marks without using 'Selection.'
 
Join Date: Sep 2023
Posts: 183
RobiNew is on a distinguished road
Default

Thanks, but this not what I need. There are texts in which superscript occurs in the text and in the footnotes. In these words and sentences I want to change superscript to normal. However, both in the text and the foonotes I want to leave the footnote marks unchanged (that is: superscript). All this I achieved with the code I originally posted, but now I need the same result without using 'Selection'.
Reply With Quote
  #6  
Old 09-30-2023, 10:16 AM
vivka vivka is offline Change superscripts to regular text except footnote marks without using 'Selection.' Windows 7 64bit Change superscripts to regular text except footnote marks without using 'Selection.' Office 2016
Competent Performer
 
Join Date: Jul 2023
Posts: 227
vivka is on a distinguished road
Default

The code in post 4 should change superscripts in the main text leaving footnotes intact. And this is the fastest way (as far as I know).
But (just in case) try this one. It doesn't use With...End With block:

Code:
Sub Superscripts_To_Regular_MainTxt()
 'Change all superscripts to normal text only in wdMainTextStory (1).

   For Each aStory In ActiveDocument.StoryRanges
     If aStory.StoryType = wdMainTextStory Then aStory.Font.Superscript = False
   Next aStory
 End Sub
Reply With Quote
  #7  
Old 09-30-2023, 11:59 AM
Italophile Italophile is offline Change superscripts to regular text except footnote marks without using 'Selection.' Windows 11 Change superscripts to regular text except footnote marks without using 'Selection.' Office 2021
Expert
 
Join Date: Mar 2022
Posts: 338
Italophile is just really niceItalophile is just really niceItalophile is just really niceItalophile is just really nice
Default

It is really very simple. Just replace Selection with the range you want to find in. For example ActiveDocument.Content which is the same as the MainStory:

Code:
Sub ReplaceSuperscript()
    With ActiveDocument.Content.Find
        .ClearFormatting
        With .Font
            .Superscript = True
            .Subscript = False
        End With
        .Replacement.ClearFormatting
        With .Replacement.Font
            .Superscript = False
            .Subscript = False
        End With
        .Text = "[!^02]"
        .Replacement.Text = ""
        .Forward = True
        .Wrap = wdFindContinue
        .Format = True
        .MatchCase = False
        .MatchWholeWord = False
        .MatchAllWordForms = False
        .MatchSoundsLike = False
        .MatchWildcards = True
        .Execute Replace:=wdReplaceAll
    End With
End Sub
If you need to replace throughout the entire document:

Code:
Sub ReplaceSuperscript()
    Dim story As Range
    For Each story In ActiveDocument.StoryRanges
        With story.Find
            .ClearFormatting
            With .Font
                .Superscript = True
                .Subscript = False
            End With
            .Replacement.ClearFormatting
            With .Replacement.Font
                .Superscript = False
                .Subscript = False
            End With
            .Text = "[!^02]"
            .Replacement.Text = ""
            .Forward = True
            .Wrap = wdFindContinue
            .Format = True
            .MatchCase = False
            .MatchWholeWord = False
            .MatchAllWordForms = False
            .MatchSoundsLike = False
            .MatchWildcards = True
            .Execute Replace:=wdReplaceAll
        End With
    Next story
End Sub
Reply With Quote
  #8  
Old 10-01-2023, 01:55 AM
RobiNew RobiNew is offline Change superscripts to regular text except footnote marks without using 'Selection.' Windows 10 Change superscripts to regular text except footnote marks without using 'Selection.' Office 2016
Competent Performer
Change superscripts to regular text except footnote marks without using 'Selection.'
 
Join Date: Sep 2023
Posts: 183
RobiNew is on a distinguished road
Default

Thanks a lot, Italophile! Your second code is exactly what I need. Thanks again!
Reply With Quote
Reply

Tags
replace, superscript



Similar Threads
Thread Thread Starter Forum Replies Last Post
Change superscripts to regular text except footnote marks without using 'Selection.' Loop through Footnote Reference Marks Ramses505 Word VBA 6 09-21-2023 12:10 AM
Change superscripts to regular text except footnote marks without using 'Selection.' Macro to change font size of Footnote Reference in Footnote Text TheBigBoss Word VBA 5 06-10-2022 06:14 AM
Need to change superscripts to regular text but also add parentheses DCabby Word VBA 4 11-13-2019 09:43 AM
Change superscripts to regular text except footnote marks without using 'Selection.' Convert endnote/footnote to regular text Cobb78 Word 5 07-11-2016 06:23 AM
Change superscripts to regular text except footnote marks without using 'Selection.' Regular (roman) character style doesn't change text to roman kcbenson Word 2 10-16-2014 01:31 PM

Other Forums: Access Forums

All times are GMT -7. The time now is 02:59 PM.


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