Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 11-01-2024, 08:18 AM
Shelley Lou Shelley Lou is offline VBA Footnote Issues Windows 10 VBA Footnote Issues Office 2016
Expert
VBA Footnote Issues
 
Join Date: Dec 2020
Posts: 259
Shelley Lou is on a distinguished road
Default VBA Footnote Issues

I found the code below on another post that formats footnotes with a tab. I seem to be having a couple of issues in that it removes the bold format from the Footnote Reference number and applies bold to the Footnote Text. How can I get the code to reverse this so the Footnote Reference is bold but the Footnote Text is not bold? I've checked the styles for both of these in the Styles Pane and they are set correctly eg Footnote Reference set as bold and Footnote Text set as not bold. I've also set the Footnote Text in the Styles Pane to be indented at 0.25" but could this be added to the code itself?

Footnote Image.JPG



Code:
Sub InsertFootnote()
ActiveDocument.Footnotes.Add Range:=Selection.Range
With Selection
.Paragraphs(1).Range.Font.Reset
.Paragraphs(1).Range.Characters(2) = ""
.InsertAfter vbTab
.Font.Bold = True
.Collapse wdCollapseEnd
End With
ActiveWindow.ScrollIntoView Selection.Range
End Sub

 
Sub InsertFootnoteNow()
ActiveDocument.Footnotes.Add Range:=Selection.Range
With Selection
.Paragraphs(1).Range.Font.Reset
.Paragraphs(1).Range.Characters(2) = ""
.InsertAfter vbTab
.Font.Bold = True
.Collapse wdCollapseEnd
End With
ActiveWindow.ScrollIntoView Selection.Range
End Sub
Reply With Quote
  #2  
Old 11-01-2024, 03:00 PM
macropod's Avatar
macropod macropod is online now VBA Footnote Issues Windows 10 VBA Footnote Issues Office 2016
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 22,340
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

All you should need is:
Code:
Sub InsertFootnote()
With Selection
  .Footnotes.Add Range:=.Range
  With .Paragraphs(1).Range
    .Characters(2) = vbTab
    .Characters.Last.Select
  End With
  .Collapse
  ActiveWindow.ScrollIntoView .Range
End With
End Sub
As for the Footnote Reference Style & Footnote Text Style, any character formats and indents should be modified at the Style level, not in code.
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #3  
Old 11-02-2024, 06:19 AM
gmaxey gmaxey is offline VBA Footnote Issues Windows 10 VBA Footnote Issues Office 2019
Expert
 
Join Date: May 2010
Location: Brasstown, NC
Posts: 1,598
gmaxey is just really nicegmaxey is just really nicegmaxey is just really nicegmaxey is just really nicegmaxey is just really nice
Default

Code:
Sub InsertFootnoteNow()
  With Selection
    .Footnotes.Add Range:=.Range
    'To adjust  the tab with, use these two lines
    .Paragraphs(1).TabStops.ClearAll
    .Paragraphs(1).TabStops(1).Position = 18 'change to suit
    With .Paragraphs(1).Range
      'If you only want the reference in the footnote modified use ...
      .Characters(1).Font.Superscript = False
      .Characters(1).Font.Bold = True
      '... otherwise change the footnote reference style
      .Characters(2) = vbTab
      .Characters.Last.Select
    End With
    .Collapse
    ActiveWindow.ScrollIntoView .Range
  End With
lbl_Exit:
  Exit Sub
End Sub
__________________
Greg Maxey
Please visit my web site at http://www.gregmaxey.com/
Reply With Quote
  #4  
Old 11-05-2024, 01:49 AM
Shelley Lou Shelley Lou is offline VBA Footnote Issues Windows 10 VBA Footnote Issues Office 2016
Expert
VBA Footnote Issues
 
Join Date: Dec 2020
Posts: 259
Shelley Lou is on a distinguished road
Default VBA Footnote Issues

Hi Macropod, thank you for the code, unfortunately, I couldn't get it to work using Ctrl Alt F.

Hi Greg, thank you for the code, I really appreciate it. I have added .Characters(1).Font.Size = 8 to bring the font size down from 10 to 8 and it seems to be working as I wanted it to without changing the actual style in the styles pane. Thank you so much.
Reply With Quote
  #5  
Old 11-05-2024, 04:06 AM
macropod's Avatar
macropod macropod is online now VBA Footnote Issues Windows 10 VBA Footnote Issues Office 2016
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 22,340
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 Shelley Lou View Post
Hi Macropod, thank you for the code, unfortunately, I couldn't get it to work using Ctrl Alt F.
Well, you didn't ask for that. To achieve that, all you need to do is add 'Now' to the macro's name.

Whilst you might be happy with Greg's code, do be aware that it will lead to an unnecessary increase in file size compared to the once-off Style modifications. And, if you made those once-off Style modifications in Word's Normal Template, you'd likely never need to bother with them again. Plus, your documents will be less prone to corruption if you modify the Styles than if you use Greg's brute-force approach to modifying each footnote's formatting.
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #6  
Old 11-05-2024, 09:55 AM
Shelley Lou Shelley Lou is offline VBA Footnote Issues Windows 10 VBA Footnote Issues Office 2016
Expert
VBA Footnote Issues
 
Join Date: Dec 2020
Posts: 259
Shelley Lou is on a distinguished road
Default VBA Footnote Issues

Thank you Macropod for pointing out any issues that may arise with the other code, as it may become an issue on our larger 200 page documents with hundreds of footnotes within them.
Reply With Quote
Reply



Similar Threads
Thread Thread Starter Forum Replies Last Post
VBA Footnote Issues 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 Footnote Issues Macro to change font size of Footnote Reference in Footnote Text TheBigBoss Word VBA 5 06-10-2022 06:14 AM
VBA Footnote Issues Footnote references in the footnote section losing their style when cut+pasted from same doc emblaw Word 4 12-08-2020 06:23 AM
VBA Footnote Issues Removing line break and indentation between footnote number and footnote text in Word jaanross Word 5 02-06-2020 12:04 AM
VBA Footnote Issues Adding footnote number as part of footnote text NoCalScribe Word VBA 3 07-15-2019 07:20 PM

Other Forums: Access Forums

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