Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Closed Thread
 
Thread Tools Display Modes
  #1  
Old 02-12-2017, 06:16 PM
thiagoafdoria thiagoafdoria is offline Transfer text to footnotes Windows 8 Transfer text to footnotes Office 2016
Novice
Transfer text to footnotes
 
Join Date: Feb 2017
Posts: 18
thiagoafdoria is on a distinguished road
Default Transfer text to footnotes

Hi!


I'm using a macro to transform every bit of green text in a document into footnotes. A person within the community of a software I use kindly shared the code to this macro. It's the followin one:

Quote:
Sub Makro8()
'
' Makro8 Makro
' Macro for MS Word converting parts of text in a special color (here: green)
' into MS Word footnotes
'
Do While Not ActiveDocument.Range.End - 1 = Selection.Range.End
Selection.Find.ClearFormatting
With Selection.Find
.Font.Color = wdColorGreen
.Text = ""
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindContinue
.Format = True
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.Find.Execute
With Selection.Font
.Color = wdColorAutomatic
End With
If Selection.Type = wdSelectionIP Then
If ActiveWindow.ActivePane.View.Type = wdPrintView Or ActiveWindow. _
ActivePane.View.Type = wdWebView Or ActiveWindow.ActivePane.View.Type = _
wdPrintPreview Then
ActiveWindow.View.SeekView = wdSeekFootnotes
Else
ActiveWindow.View.SplitSpecial = wdPaneFootnotes
End If
Exit Sub
End If
Selection.Cut
With ActiveDocument.Range(Start:=ActiveDocument.Content .Start, End:= _
ActiveDocument.Content.End)
With .FootnoteOptions
.Location = wdBottomOfPage
.NumberingRule = wdRestartContinuous
.StartingNumber = 1
.NumberStyle = wdNoteNumberStyleArabic
End With
.Footnotes.Add Range:=Selection.Range, Reference:=""
End With
Selection.PasteAndFormat (wdPasteDefault)
Selection.Find.ClearFormatting
With Selection.Find
.Text = ""
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindContinue
.Format = True
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
ActiveWindow.ActivePane.Close
Loop
End Sub
The problem is, it transforms one part of the green text at a time. If I have 46 pieces of green text, I'd have to execute the macro 46 times. Do you have any idea of what I could modify in order to execute the macro only one time?
I'm running a Microsoft Word 2016 (Office 365) in Windows 8.1. Please note that the macro is working; it just doesn't transform the several pieces into footnotes all at once.
Best regards,
Thiago
  #2  
Old 02-12-2017, 09:01 PM
macropod's Avatar
macropod macropod is offline Transfer text to footnotes Windows 7 64bit Transfer text to footnotes Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,956
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

For a much more efficient macro, try:
Code:
Sub Demo()
Application.ScreenUpdating = False
Dim Rng As Range, FtNt As Footnote
With ActiveDocument.Range
  With .Find
    .ClearFormatting
    .Replacement.ClearFormatting
    .Text = ""
    .Replacement.Text = ""
    .Forward = True
    .Format = True
    .Font.ColorIndex = wdGreen
    .Wrap = wdFindStop
    .MatchWildcards = True
    .Execute
  End With
  Do While .Find.Found
    Set Rng = .Duplicate
    .Collapse wdCollapseStart
    Set FtNt = .Footnotes.Add(.Duplicate)
    Rng.Start = FtNt.Reference.End
    FtNt.Range.FormattedText = Rng.FormattedText
    Rng.Delete
    If .End = ActiveDocument.Range.End Then Exit Sub
    .Collapse wdCollapseEnd
    .Find.Execute
  Loop
End With
Application.ScreenUpdating = True
End Sub
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
  #3  
Old 02-13-2017, 11:23 AM
thiagoafdoria thiagoafdoria is offline Transfer text to footnotes Windows 8 Transfer text to footnotes Office 2016
Novice
Transfer text to footnotes
 
Join Date: Feb 2017
Posts: 18
thiagoafdoria is on a distinguished road
Default

Thank you!
I've tried, but unfortunately the file keeps loading while the macro runs endlessly. Could it be because I'm running Microsoft Word 2016 (Office 365)?

PS: I've just replaced the old code for this new one. I don't know if I should do something else. I've just opened the Macro dialog window and then I've clicked "edit"; so I was able to do the replacement.
  #4  
Old 02-14-2017, 03:56 AM
macropod's Avatar
macropod macropod is offline Transfer text to footnotes Windows 7 64bit Transfer text to footnotes Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,956
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

I don't understand your 'the file keeps loading while the macro runs endlessly' comment. The macro doesn't load any files. All it does is find all green text in the active document and convert that text to footnotes. The Word version is of no consequence
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
  #5  
Old 02-14-2017, 04:21 AM
thiagoafdoria thiagoafdoria is offline Transfer text to footnotes Windows 8 Transfer text to footnotes Office 2016
Novice
Transfer text to footnotes
 
Join Date: Feb 2017
Posts: 18
thiagoafdoria is on a distinguished road
Default

Sorry, I didn't express myself correctly. I mean I run the macro, but instead of converting all the green text into footnotes, MS Word begins to not respond anymore (this is what I meant by "the macro runs endlessly"). It crashes, so to speak.
  #6  
Old 02-14-2017, 04:25 AM
macropod's Avatar
macropod macropod is offline Transfer text to footnotes Windows 7 64bit Transfer text to footnotes Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,956
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

I am unable to reproduce that behaviour, regardless of where the content might be in the document body.

Can you attach the problem document to a post (delete/obfuscate anything sensitive)?
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
  #7  
Old 02-14-2017, 07:34 AM
thiagoafdoria thiagoafdoria is offline Transfer text to footnotes Windows 8 Transfer text to footnotes Office 2016
Novice
Transfer text to footnotes
 
Join Date: Feb 2017
Posts: 18
thiagoafdoria is on a distinguished road
Default

Sure!

I'm attaching the file I was using as a test. Now it seems that when I run the macro nothing happens.

I'm pretending to edit a large document (probably 30k words). I also don't know if the amount of words would matter in this case.
Attached Files
File Type: docx test.docx (30.6 KB, 6 views)
  #8  
Old 02-14-2017, 09:51 AM
thiagoafdoria thiagoafdoria is offline Transfer text to footnotes Windows 8 Transfer text to footnotes Office 2016
Novice
Transfer text to footnotes
 
Join Date: Feb 2017
Posts: 18
thiagoafdoria is on a distinguished road
Default

I've just realized that I've used a different shade of green in the document I've previously attached. That's the reason why nothing has happened when I tried to run the macro.
Now I'm sending the same document, but with the appropriate green color. Now you'll see the behavior I've mentioned early: you run the macro and the MS Word stops responding.
Thank's in advance,
Thiago
Attached Files
File Type: docx test 2.docx (30.8 KB, 8 views)
  #9  
Old 02-14-2017, 01:54 PM
macropod's Avatar
macropod macropod is offline Transfer text to footnotes Windows 7 64bit Transfer text to footnotes Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,956
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

The problem with your document is that it has trailing spaces & paragraph breaks formatted green. The following code revision will take care of that (plus tabs & line breaks):
Code:
Sub Demo()
Application.ScreenUpdating = False
Dim Rng As Range, FtNt As Footnote
With ActiveDocument.Range
  With .Find
    .ClearFormatting
    .Replacement.ClearFormatting
    .Text = ""
    .Replacement.Text = ""
    .Forward = True
    .Format = True
    .Font.ColorIndex = wdGreen
    .Wrap = wdFindStop
    .MatchWildcards = True
    .Execute
  End With
  Do While .Find.Found
    If .Characters.Last Like "[" & vbCr & vbTab & Chr(11) & Chr(160) & " ]" Then
      .Characters.Last.Font.Reset
      .End = .End - 1
    End If
    Set Rng = .Duplicate
    .Collapse wdCollapseStart
    Set FtNt = .Footnotes.Add(.Duplicate)
    Rng.Start = FtNt.Reference.End
    FtNt.Range.FormattedText = Rng.FormattedText
    Rng.Delete
    If .End = ActiveDocument.Range.End Then Exit Sub
    .Collapse wdCollapseEnd
    .Find.Execute
  Loop
End With
Application.ScreenUpdating = True
End Sub
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
  #10  
Old 02-15-2017, 06:54 AM
thiagoafdoria thiagoafdoria is offline Transfer text to footnotes Windows 8 Transfer text to footnotes Office 2016
Novice
Transfer text to footnotes
 
Join Date: Feb 2017
Posts: 18
thiagoafdoria is on a distinguished road
Default

Wow! This is truly amazing! It works perfectly. Thank you very much!
  #11  
Old 05-13-2019, 07:47 PM
thiagoafdoria thiagoafdoria is offline Transfer text to footnotes Windows 8 Transfer text to footnotes Office 2016
Novice
Transfer text to footnotes
 
Join Date: Feb 2017
Posts: 18
thiagoafdoria is on a distinguished road
Default

Hi there!
Sorry for taking back an old thread. The macro below transforms text in green color into footnotes.

Code:
Sub Demo()
Application.ScreenUpdating = False
Dim Rng As Range, FtNt As Footnote
With ActiveDocument.Range
  With .Find
    .ClearFormatting
    .Replacement.ClearFormatting
    .Text = ""
    .Replacement.Text = ""
    .Forward = True
    .Format = True
    .Font.ColorIndex = wdGreen
    .Wrap = wdFindStop
    .MatchWildcards = True
    .Execute
  End With
  Do While .Find.Found
    If .Characters.Last Like "[" & vbCr & vbTab & Chr(11) & Chr(160) & " ]" Then
      .Characters.Last.Font.Reset
      .End = .End - 1
    End If
    Set Rng = .Duplicate
    .Collapse wdCollapseStart
    Set FtNt = .Footnotes.Add(.Duplicate)
    Rng.Start = FtNt.Reference.End
    FtNt.Range.FormattedText = Rng.FormattedText
    Rng.Delete
    If .End = ActiveDocument.Range.End Then Exit Sub
    .Collapse wdCollapseEnd
    .Find.Execute
  Loop
End With
Application.ScreenUpdating = True
End Sub
I would like to change it, so that the footnotes are made from fragments between "[!" and "!]", not green text anymore. For example:

This is normal text.[!This should be turned into a footnote.!] This is normal text. This is normal text... And so on.

Is that possible?

Thank's in advance,

Thiago
  #12  
Old 05-13-2019, 07:54 PM
macropod's Avatar
macropod macropod is offline Transfer text to footnotes Windows 7 64bit Transfer text to footnotes Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,956
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

Change:
Code:
    .Text = ""
    .Replacement.Text = ""
    .Forward = True
    .Format = True
    .Font.ColorIndex = wdGreen
to:
Code:
    .Text = "\[\!*\!\]"
    .Replacement.Text = ""
    .Forward = True
    .Format = False
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
  #13  
Old 05-14-2019, 06:37 PM
thiagoafdoria thiagoafdoria is offline Transfer text to footnotes Windows 10 Transfer text to footnotes Office 2019
Novice
Transfer text to footnotes
 
Join Date: Feb 2017
Posts: 18
thiagoafdoria is on a distinguished road
Default

Fantastic! Thank you very much!
If it's not too much trouble: would there also be a macro to do just the opposite (turn footnotes into delimited fragments between "[!" and "!]" in the body of the text)?
  #14  
Old 05-14-2019, 07:28 PM
macropod's Avatar
macropod macropod is offline Transfer text to footnotes Windows 7 64bit Transfer text to footnotes Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,956
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

Simple:
Code:
Sub Demo()
Application.ScreenUpdating = False
With ActiveDocument
  Do While .Footnotes.Count > 0
    With .Footnotes(1)
      .Reference.InsertAfter "[!" & .Range.FormattedText & "!]"
      .Delete
    End With
  Loop
End With
Application.ScreenUpdating = True
End Sub
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
  #15  
Old 05-22-2019, 08:37 AM
thiagoafdoria thiagoafdoria is offline Transfer text to footnotes Windows 10 Transfer text to footnotes Office 2019
Novice
Transfer text to footnotes
 
Join Date: Feb 2017
Posts: 18
thiagoafdoria is on a distinguished road
Default

macropod, thank you very very much! And sorry for the late reply.
Thiago
Closed Thread

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
Transfer text to footnotes How to change superscript footnotes into genuine Word footnotes Knounte29 Word VBA 41 01-16-2020 04:48 PM
Transfer text to footnotes Help with Tracking: Bold in body text, but not in Footnotes Bobbety Word 3 05-17-2015 11:17 PM
Transfer text to footnotes word 2007 - footnotes and text box glggluig Word 1 08-10-2014 04:09 AM
All my footnotes turned to blue underlined text. bww Word 0 07-11-2013 08:35 AM
Transfer text to footnotes create footnotes from custom text mosrozen Word VBA 2 06-14-2012 06:59 AM

Other Forums: Access Forums

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