Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 08-02-2021, 01:56 AM
jec1 jec1 is offline Footnote macro - brackets around not working properly Windows 7 32bit Footnote macro - brackets around not working properly Office 2013
Advanced Beginner
Footnote macro - brackets around not working properly
 
Join Date: Jan 2012
Posts: 84
jec1 is on a distinguished road
Default Footnote macro - brackets around not working properly

Hi everyone



Macro used to put brackets around footnotes in the body and the footnote.

But it only puts brackets around footnote in body of document now. It does not error.

Any ideas - thank you in advance.

Windows 10/Office 365 Business Standard


Sub BracketFootnoteNumbersandBody(control As IRibbonControl)

'You can run this macro multiple times if needed, for instance if you add more footnotes; it will just 'ignore all the numbers that have already been bracketed.
'If your document uses endnotes instead of footnotes, change the "wdFootnotesStory" to '"wdEndnotesStory".
'It isn't possible to make this format automatic, but you can install the following macro to
'insert brackets around any existing footnote numbers. I've assumed that you want the brackets around the numbers
'in the footnotes themselves, as well as in the references in the main text. If that's not what you want,
'remove all the code starting at the line containing "wdFootnotesStory" and
'ending with the "Set rg = 'Nothing" just before the "End Sub".

Dim rg As Range
Set rg = ActiveDocument.Range
With rg.Find
.Format = True
.Style = ActiveDocument.Styles(wdStyleFootnoteReference)
.Wrap = wdFindStop
While .Execute
If rg.Characters(1) <> "(" Then
rg.InsertBefore "("
rg.InsertAfter ")"
rg.Style = ActiveDocument.Styles(wdStyleFootnoteReference)
End If
rg.Collapse wdCollapseEnd
Wend
End With
Set rg = Nothing

Set rg = ActiveDocument.StoryRanges(wdFootnotesStory)
With rg.Find
.Format = True
.Style = ActiveDocument.Styles(wdStyleFootnoteReference)
.Wrap = wdFindStop
While .Execute
If rg.Characters(1) <> "(" Then
rg.InsertBefore "("
rg.InsertAfter ")"
rg.Style = ActiveDocument.Styles(wdStyleFootnoteReference)
End If
rg.Collapse wdCollapseEnd
Wend
End With
Set rg = Nothing
End Sub


Janine
Reply With Quote
  #2  
Old 08-02-2021, 04:49 PM
Guessed's Avatar
Guessed Guessed is offline Footnote macro - brackets around not working properly Windows 10 Footnote macro - brackets around not working properly Office 2016
Expert
 
Join Date: Mar 2010
Location: Canberra/Melbourne Australia
Posts: 3,969
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

Since nearly all of the paragraphs in the footnotes are going to start with a footnote reference, a find replace is less useful. Try this variation
Code:
Sub BracketFootnotes()
  Dim rg As Range, aPar As Paragraph, rngRef As Range
  
  Set rg = ActiveDocument.Range
  With rg.Find
    .Format = True
    .Style = ActiveDocument.Styles(wdStyleFootnoteReference)
    .Wrap = wdFindStop
    While .Execute
      If rg.Characters(1) <> "(" Then
      rg.InsertBefore "("
      rg.InsertAfter ")"
      rg.Style = ActiveDocument.Styles(wdStyleFootnoteReference)
      End If
      rg.Collapse wdCollapseEnd
    Wend
  End With
  Set rg = Nothing
  
  Set rg = ActiveDocument.StoryRanges(wdFootnotesStory)
  For Each aPar In rg.Paragraphs
    Set rngRef = aPar.Range.Words.First
    rngRef.End = rngRef.Start + Len(Trim(rngRef.Text))
    rngRef.Select
    If rngRef.Characters.First.Style = "Footnote Reference" And rngRef.Characters.First <> "(" Then
      rngRef.InsertBefore "("
      rngRef.InsertAfter ")"
      rngRef.Style = wdStyleFootnoteReference
    End If
  Next aPar
  Set rg = Nothing
  Set rngRef = Nothing
End Sub
__________________
Andrew Lockton
Chrysalis Design, Melbourne Australia
Reply With Quote
  #3  
Old 08-04-2021, 12:24 AM
jec1 jec1 is offline Footnote macro - brackets around not working properly Windows 7 32bit Footnote macro - brackets around not working properly Office 2013
Advanced Beginner
Footnote macro - brackets around not working properly
 
Join Date: Jan 2012
Posts: 84
jec1 is on a distinguished road
Default

Hi,

Yes but neither macro does the footnotes (bottom of page) - I use a tab in my footnotes set in default style - is that why? It just (1) the body of the document.

Thank you.
Janine
Reply With Quote
  #4  
Old 08-04-2021, 12:34 AM
Guessed's Avatar
Guessed Guessed is offline Footnote macro - brackets around not working properly Windows 10 Footnote macro - brackets around not working properly Office 2016
Expert
 
Join Date: Mar 2010
Location: Canberra/Melbourne Australia
Posts: 3,969
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

What style is applied to the footnote at the bottom of the page?

The code is only touching the first word when the style is "Footnote Reference" and doesn't already have a ( at the start.
__________________
Andrew Lockton
Chrysalis Design, Melbourne Australia
Reply With Quote
Reply



Similar Threads
Thread Thread Starter Forum Replies Last Post
Footnote macro - brackets around not working properly Normal dot not working properly John9210 Word 13 02-12-2018 07:50 AM
Vlookup Not working Properly josepfh Excel 1 04-19-2017 11:04 AM
It seems as if wdFindStop isn't working properly tfurnivall Word VBA 3 05-06-2016 09:58 AM
Footnote macro - brackets around not working properly Indentation Not Working Properly LaC0saNostra Word 2 02-01-2015 11:35 AM
Word 2000 Macro not working properly brianlb Word VBA 1 07-01-2009 07:04 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 07:20 AM.


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