Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 08-29-2020, 01:00 PM
John 4 John 4 is offline Modify macro to move only Blue font footnotes into the Text Windows 10 Modify macro to move only Blue font footnotes into the Text Office 2013
Advanced Beginner
Modify macro to move only Blue font footnotes into the Text
 
Join Date: Oct 2019
Posts: 69
John 4 is on a distinguished road
Default Modify macro to move only Blue font footnotes into the Text

Hi,
I received the following macro on these forums for moving the footnotes into the text and it works very well. However I'd like to modify it so that it only moves footnotes that are in a certain font colour (blue for example), and leaves the other footnotes unmoved. Can anyone help?

Thanks for your time.

Sub MoveFootnotesIntoText()
Application.ScreenUpdating = False
Dim RngSrc As Range, RngTgt As Range, f As Long
With Selection


For f = .Footnotes.Count To 1 Step -1
With .Footnotes(f)
Set RngSrc = .Range
Set RngTgt = .Reference
RngSrc.End = RngSrc.End - 1
RngTgt.Collapse wdCollapseStart
RngTgt.FormattedText = RngSrc.FormattedText
.Delete
Next
End With
Set RngSrc = Nothing: Set RngTgt = Nothing
Application.ScreenUpdating = True
End Sub
Reply With Quote
  #2  
Old 08-29-2020, 04:35 PM
Guessed's Avatar
Guessed Guessed is offline Modify macro to move only Blue font footnotes into the Text Windows 10 Modify macro to move only Blue font footnotes into the Text Office 2016
Expert
 
Join Date: Mar 2010
Location: Canberra/Melbourne Australia
Posts: 3,932
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

You would need to know EXACTLY what color you are looking for.
Code:
Sub MoveFootnotesIntoText()
  'Application.ScreenUpdating = False
  Dim RngSrc As Range, RngTgt As Range, f As Long
  For f = ActiveDocument.Footnotes.Count To 1 Step -1
    With ActiveDocument.Footnotes(f)
      Set RngSrc = .Range
      Set RngTgt = .Reference
      RngSrc.End = RngSrc.End - 1
      If RngSrc.Font.Color = RGB(0, 112, 192) Then
        RngTgt.Collapse wdCollapseStart
        RngTgt.FormattedText = RngSrc.FormattedText
        .Delete
      End If
    End With
  Next
  Set RngSrc = Nothing: Set RngTgt = Nothing
  'Application.ScreenUpdating = True
End Sub
__________________
Andrew Lockton
Chrysalis Design, Melbourne Australia
Reply With Quote
  #3  
Old 08-29-2020, 07:42 PM
John 4 John 4 is offline Modify macro to move only Blue font footnotes into the Text Windows 10 Modify macro to move only Blue font footnotes into the Text Office 2013
Advanced Beginner
Modify macro to move only Blue font footnotes into the Text
 
Join Date: Oct 2019
Posts: 69
John 4 is on a distinguished road
Default

Fair enough,
I know I said blue originally, but we'll say red instead. The colour that's encoded by:
Font.Color = wdColorRed

Thanks Andrew
Reply With Quote
  #4  
Old 08-31-2020, 09:40 AM
John 4 John 4 is offline Modify macro to move only Blue font footnotes into the Text Windows 10 Modify macro to move only Blue font footnotes into the Text Office 2013
Advanced Beginner
Modify macro to move only Blue font footnotes into the Text
 
Join Date: Oct 2019
Posts: 69
John 4 is on a distinguished road
Default

Is there something particularly difficult about the colour red?
Reply With Quote
  #5  
Old 08-31-2020, 02:37 PM
Charles Kenyon Charles Kenyon is online now Modify macro to move only Blue font footnotes into the Text Windows 10 Modify macro to move only Blue font footnotes into the Text Office 2019
Moderator
 
Join Date: Mar 2012
Location: Sun Prairie, Wisconsin
Posts: 9,083
Charles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant future
Default

Quote:
Originally Posted by John 4 View Post
Is there something particularly difficult about the colour red?

There are literally thousands of colors available that are easy to apply manually in the user interface, only a few of which have Word constants assigned. That it looks Red does not mean it is wdColorRed. If it is not, it becomes much more difficult.
Reply With Quote
  #6  
Old 08-31-2020, 03:56 PM
Guessed's Avatar
Guessed Guessed is offline Modify macro to move only Blue font footnotes into the Text Windows 10 Modify macro to move only Blue font footnotes into the Text Office 2016
Expert
 
Join Date: Mar 2010
Location: Canberra/Melbourne Australia
Posts: 3,932
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

As Charles and I have both pointed out, you need to know exactly which shade of red is applied. The RGB values of a colour has 256 x 256 x 256 possible variations. There are probably over 10,000 various combinations that people might say are 'Red'. wdColorRed is only one particular variation of these possibilities.

Also, the code is written to be looking at the colour of the entire footnote. If there is variation inside the footnote such that there is more than one colour applied in the entire paragraph (potentially including the paragraph mark), then the colour would be undefined and therefore wouldn't be considered Red at all.
__________________
Andrew Lockton
Chrysalis Design, Melbourne Australia
Reply With Quote
  #7  
Old 08-31-2020, 04:20 PM
John 4 John 4 is offline Modify macro to move only Blue font footnotes into the Text Windows 10 Modify macro to move only Blue font footnotes into the Text Office 2013
Advanced Beginner
Modify macro to move only Blue font footnotes into the Text
 
Join Date: Oct 2019
Posts: 69
John 4 is on a distinguished road
Default

It is wdColorRed because that's the red I use and if i record a macro while doing something with it, that's the VBA code that comes up. Same goes for blue or any other colour I use. I only use the main colours.

If you can give me the code so that the macro does what I want it do that would be great, and I can change the part that identifies the colour as necessary.
Reply With Quote
  #8  
Old 08-31-2020, 04:41 PM
Guessed's Avatar
Guessed Guessed is offline Modify macro to move only Blue font footnotes into the Text Windows 10 Modify macro to move only Blue font footnotes into the Text Office 2016
Expert
 
Join Date: Mar 2010
Location: Canberra/Melbourne Australia
Posts: 3,932
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

Macros like this rely on patterns to identify the targets. If you don't give full details on what patterns are in and what are out then the macro may not work as expected.

If YOU want code that works with YOUR document, YOU need to provide a sample document so we can see what pattern can be used. Otherwise we are making guesses and have to either provide untested code or do a test on an artificial sample document that we have to create based on your sketchy provided information.

Ideally, instead of a colour, you would have used a style on the footnotes you wanted to transfer and the pattern used by the macro could have been less nuanced.
__________________
Andrew Lockton
Chrysalis Design, Melbourne Australia
Reply With Quote
  #9  
Old 08-31-2020, 05:24 PM
John 4 John 4 is offline Modify macro to move only Blue font footnotes into the Text Windows 10 Modify macro to move only Blue font footnotes into the Text Office 2013
Advanced Beginner
Modify macro to move only Blue font footnotes into the Text
 
Join Date: Oct 2019
Posts: 69
John 4 is on a distinguished road
Default

My apologies Andrew, I didn't see your second last post (the one that begins "As Charles and I have both pointed out") before i made my last post.

That's an interesting point you made about it not working on footnotes that are different colours but it isn't relevant at the minute as any footnotes that are coloured are coloured completely. However the point about the paragraph mark may well be; if it is then it can be changed to suit.

But now that we know that I'm using only the exact word colour red (or blue or whatever) and not any custom colour there shouldn't be any further problems? The code I've already been given for moving the footnotes works perfectly, so now it's just a case of adding a colour to the selection - I don't think there's any more guesswork involved for you?

Thanks for your help
Reply With Quote
  #10  
Old 08-31-2020, 05:33 PM
John 4 John 4 is offline Modify macro to move only Blue font footnotes into the Text Windows 10 Modify macro to move only Blue font footnotes into the Text Office 2013
Advanced Beginner
Modify macro to move only Blue font footnotes into the Text
 
Join Date: Oct 2019
Posts: 69
John 4 is on a distinguished road
Default

If you'd really prefer to code the macro for a style, go ahead and choose one. I don't use a great variety of styles in my documents and any documents that have a large variety of styles I tend to simplify.

I use Times New Roman almost exclusively, and everything's very bland and boring, so if you want to choose some exotic style that's fine. I suppose I could add a procedure to change the moved footnotes from that style to colour red at the end of the macro.
Reply With Quote
  #11  
Old 08-31-2020, 09:25 PM
Guessed's Avatar
Guessed Guessed is offline Modify macro to move only Blue font footnotes into the Text Windows 10 Modify macro to move only Blue font footnotes into the Text Office 2016
Expert
 
Join Date: Mar 2010
Location: Canberra/Melbourne Australia
Posts: 3,932
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

OK, create a paragraph style called "Footnote Text Red" and apply it to the Footnotes that need to go inline when you run the macro.
Code:
Sub MoveFootnotesIntoText()
  Dim RngSrc As Range, RngTgt As Range, f As Long
  For f = ActiveDocument.Footnotes.Count To 1 Step -1
    With ActiveDocument.Footnotes(f)
      Set RngSrc = .Range
      Set RngTgt = .Reference
      RngSrc.End = RngSrc.End - 1
      If RngSrc.Paragraphs(1).Style = "Footnote Text Red" Then
        RngTgt.Collapse wdCollapseStart
        RngTgt.FormattedText = RngSrc.FormattedText
        .Delete
      End If
    End With
  Next
  Set RngSrc = Nothing: Set RngTgt = Nothing
End Sub
__________________
Andrew Lockton
Chrysalis Design, Melbourne Australia
Reply With Quote
  #12  
Old 09-01-2020, 03:49 PM
John 4 John 4 is offline Modify macro to move only Blue font footnotes into the Text Windows 10 Modify macro to move only Blue font footnotes into the Text Office 2013
Advanced Beginner
Modify macro to move only Blue font footnotes into the Text
 
Join Date: Oct 2019
Posts: 69
John 4 is on a distinguished road
Default

That works great Andrew,

Thanks for your time
Reply With Quote
Reply

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
Modify macro to move only Blue font footnotes into the Text Word macro for selecting text and putting it in footnotes mdhg Word VBA 20 03-06-2024 08:07 AM
Modify macro to move only Blue font footnotes into the Text VBA - Word how to globally change the font and font size in footnotes thomasoj Word VBA 3 01-15-2020 06:26 AM
Modify macro to move only Blue font footnotes into the Text Modify macro to only add bullets to highlighted text if it exists. 14spar15 Word VBA 2 10-30-2018 08:27 PM
Modify macro to move only Blue font footnotes into the Text sum numbers whose font is blue OracleDBA Excel 2 06-29-2018 10:53 AM
All my footnotes turned to blue underlined text. bww Word 0 07-11-2013 08:35 AM

Other Forums: Access Forums

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