![]() |
|
#1
|
|||
|
|||
|
Views: 21 Size: 28.6 KB">Word.png I would like to know if there is a way to do what's in the picture which is:- 1- if "footnote" found go to the next sentence copy it and reformat it and put it in foot note in one line. 2- if no "footnote" word found copy and paste it before the footnote. |
|
#2
|
||||
|
||||
|
If your document is formatted using styles to create the inter-line spacing then
Code:
Sub Macro1()
Const sFind As String = "Footnote"
Dim sNote As String
Dim oRng As Range
Set oRng = ActiveDocument.Range
With oRng.Find
Do While .Execute(sFind)
sNote = ""
With oRng
.End = .Paragraphs(1).Range.End
.Text = ""
.End = .Paragraphs(1).Range.End - 1
sNote = .Text
.End = .End + 1
.Text = ""
.End = .Paragraphs(1).Range.End - 1
sNote = sNote & " - " & .Text
.End = .End + 1
.Text = ""
.End = .Paragraphs(1).Range.End - 1
.MoveEndWhile Chr(46)
ActiveDocument.Footnotes.Add Range:=oRng, Text:=sNote
.Collapse 0
End With
Loop
End With
lbl_Exit:
Set oRng = Nothing
Exit Sub
End Sub
Code:
oRng.Text = Replace(oRng.Text, vbCr & vbCr, vbCr) oRng.ParagraphFormat.SpaceAfter = 12 Code:
Set oRng = ActiveDocument.Range
__________________
Graham Mayor - MS MVP (Word) (2002-2019) Visit my web site for more programming tips and ready made processes www.gmayor.com |
|
#3
|
|||
|
|||
|
Thank you so much for helping me. But, there is a problem which is described in the picture below.
Please have a look at the attached file, if you needed that. BeforeAndAfterRunningTheMacro.png AfterRunningMacro.docm Before.docm |
|
#4
|
||||
|
||||
|
The example document layout bears no relationship to the screenshot in your original message, so it comes as no surprise that the code intended for the screenshot layout doesn't work with the document layout. For that you would need
Code:
Sub Macro1()
Const sFind As String = "Footnote"
Dim sNote As String
Dim oRng As Range, oNote As Range
Set oRng = ActiveDocument.Range
With oRng.Find
Do While .Execute(sFind)
sNote = ""
With oRng
.End = .Paragraphs(1).Range.End
.Text = ""
.MoveStart wdParagraph
.End = .Paragraphs(1).Range.End
.MoveEnd wdParagraph
Set oNote = .Paragraphs(1).Range
oNote.End = oNote.End - 1
sNote = oNote.Text
Set oNote = .Paragraphs(2).Range
oNote.End = oNote.End - 1
sNote = sNote & " - " & oNote.Text
.Text = ""
.Start = .Start - 1
.Collapse 1
.Footnotes.Add oRng, , sNote
.Start = .Start + 1
.End = ActiveDocument.Range.End
End With
Loop
End With
lbl_Exit:
Set oRng = Nothing
Exit Sub
End Sub
__________________
Graham Mayor - MS MVP (Word) (2002-2019) Visit my web site for more programming tips and ready made processes www.gmayor.com |
|
#5
|
|||
|
|||
|
Thank you so much for your help! It's absolutely amazing. I really appreciate that you took the time to reply and I really appreciate your help.
Have a great day, |
|
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Copy/Paste from a Web Page - auto formatting? | mjwillyone | Word | 1 | 06-28-2021 06:19 PM |
| Footnote selection and paste | surya | Word | 1 | 02-03-2020 02:47 PM |
Auto populate text box based on drop-down content control and repeat the process via copy paste
|
helenndp | Word VBA | 2 | 09-27-2018 11:04 AM |
| Paste from one page to another doesnt place in the same place | MrShhh | Visio | 0 | 09-21-2016 05:47 AM |
Paste Special: Copy and Paste Formatting Only?
|
tinfanide | Word | 6 | 03-06-2013 12:21 AM |