![]() |
#1
|
|||
|
|||
![]()
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 |
#2
|
||||
|
||||
![]()
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 |
#3
|
|||
|
|||
![]()
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 |
#4
|
|||
|
|||
![]()
Is there something particularly difficult about the colour red?
|
#5
|
|||
|
|||
![]() 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. |
#6
|
||||
|
||||
![]()
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 |
#7
|
|||
|
|||
![]()
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. |
#8
|
||||
|
||||
![]()
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 |
#9
|
|||
|
|||
![]()
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 |
#10
|
|||
|
|||
![]()
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. |
#11
|
||||
|
||||
![]()
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 |
#12
|
|||
|
|||
![]()
That works great Andrew,
Thanks for your time |
![]() |
|
![]() |
||||
Thread | Thread Starter | Forum | Replies | Last Post |
![]() |
mdhg | Word VBA | 20 | 03-06-2024 08:07 AM |
![]() |
thomasoj | Word VBA | 3 | 01-15-2020 06:26 AM |
![]() |
14spar15 | Word VBA | 2 | 10-30-2018 08:27 PM |
![]() |
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 |