I am new to VBA. I need help. How to cut and paste (or move) the each footnote content next to the respective footnote indicator in Body Text. While placing the text, i need to place in between XML Tag <Footnote>..</Footnote>
. For example Footnote indicator 1
was replaced with <Footnote>Respective footnote content</Footnote>
My Input DOC file
My needed Output file
When i was refer at online there was a macro which was selecting each footnote indicator manually for placing in the body text. My Document have more footnote text, it was difficult to use this macro each time for all footnotes.
Please help me in this regarding for creating the VBA Scripts.
CodePudding user response:
For example:
Sub MoveFootNotes()
Application.ScreenUpdating = False
Dim RngSrc As Range, RngTgt As Range, f As Long
With ActiveDocument
For f = .Footnotes.Count To 1 Step -1
With .Footnotes(f)
Set RngSrc = .Range
Set RngTgt = .Reference
RngSrc.End = RngSrc.End - 1
With RngTgt
.Collapse wdCollapseStart
.FormattedText = RngSrc.FormattedText
.InsertBefore "<Footnote>"
.Characters.Last.Next.InsertBefore "</Footnote>"
End With
.Delete
End With
Next
End With
Set RngSrc = Nothing: Set RngTgt = Nothing
Application.ScreenUpdating = True
End Sub