Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 10-16-2024, 06:57 AM
Shelley Lou Shelley Lou is offline VBA Format Footnote Text Numbering Windows 10 VBA Format Footnote Text Numbering Office 2016
Expert
VBA Format Footnote Text Numbering
 
Join Date: Dec 2020
Posts: 259
Shelley Lou is on a distinguished road
Default VBA Format Footnote Text Numbering

I recorded the code below using Find and Replace but I have to have the cursor placed directly in the footnote text. The code below formats the Footnote Text Numbering from 10pt Superscript to 8pt. Normal Text.



Is there a better way I could perform this action to do the formatting automatically when running the code?

Before
Before.JPG

After
After.JPG


Code:
Sub Test1_FormatFootnoteNumber()
Selection.Find.ClearFormatting
Selection.Find.Replacement.ClearFormatting
With Selection.Find.Replacement.Font
.Size = 8
.Italic = False
.Bold = True
.Superscript = False
.Subscript = False
End With
With Selection.Find
.text = "^f"
.Replacement.text = "^&"
.Forward = True
.Wrap = wdFindContinue
.Format = True
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.Find.Execute Replace:=wdReplaceAll
End Sub
Reply With Quote
  #2  
Old 10-16-2024, 08:07 PM
Guessed's Avatar
Guessed Guessed is offline VBA Format Footnote Text Numbering Windows 10 VBA Format Footnote Text Numbering 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

The number is formatted with the Footnote Reference character style. I would just modify that style to hit them all at once. However, that same character style is also used where the footnote ref appears in the body of the document so you would also be changing those instances as well.

Perhaps search in the Footnotes story and replace that style with an alternate character style that has the attributes you want.
Code:
Sub RestyleFootnoteNums()
  Dim aRng As Range
  Set aRng = ActiveDocument.StoryRanges(wdFootnotesStory)
  With aRng.Find
    .ClearFormatting
    .Replacement.ClearFormatting
    .Text = ""
    .Style = "Footnote Reference"   'find this style
    .Replacement.Style = "Emphasis"   'replace with this style
    .Execute Replace:=wdReplaceAll
  End With
End Sub
__________________
Andrew Lockton
Chrysalis Design, Melbourne Australia
Reply With Quote
  #3  
Old 10-17-2024, 12:26 AM
Shelley Lou Shelley Lou is offline VBA Format Footnote Text Numbering Windows 10 VBA Format Footnote Text Numbering Office 2016
Expert
VBA Format Footnote Text Numbering
 
Join Date: Dec 2020
Posts: 259
Shelley Lou is on a distinguished road
Default VBA Format Footnote Text Number

Hi Andrew, thank you so much for replying. I couldn't get your code to work but after refining various find and replaced, the code below seems to work. Thank you so much for your time though, it was the wdFootnotesStory I didn't think of.

Code:
Sub FormatFootnoteNumber()
Application.ScreenUpdating = False
With ActiveDocument.StoryRanges(wdFootnotesStory).Find
    .ClearFormatting
    .Replacement.ClearFormatting
    .text = "^2"
    .Replacement.text = "^&"
    .Replacement.Font.Superscript = False
    .Replacement.Font.Size = 8
    .Replacement.Font.Bold = True
    .Forward = True
    .Format = True
    .Wrap = wdFindContinue
    .Execute Replace:=wdReplaceAll
End With
Application.ScreenUpdating = True
End Sub
Reply With Quote
Reply



Similar Threads
Thread Thread Starter Forum Replies Last Post
VBA Format Footnote Text Numbering Macro to change font size of Footnote Reference in Footnote Text TheBigBoss Word VBA 5 06-10-2022 06:14 AM
VBA Format Footnote Text Numbering Removing line break and indentation between footnote number and footnote text in Word jaanross Word 5 02-06-2020 12:04 AM
VBA Format Footnote Text Numbering Adding footnote number as part of footnote text NoCalScribe Word VBA 3 07-15-2019 07:20 PM
VBA Format Footnote Text Numbering Space between footnote number and footnote text Sabya Word 6 07-29-2018 02:30 PM
VBA Format Footnote Text Numbering Problem with footnote numbering -- Two different footnote levels mdhg Word 7 05-19-2016 06:33 AM

Other Forums: Access Forums

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