Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 01-14-2022, 08:07 AM
Abbas Abbas is offline How To Auto Copy And Paste With A Footnote In Its Place. Windows 10 How To Auto Copy And Paste With A Footnote In Its Place. Office 2016
Novice
How To Auto Copy And Paste With A Footnote In Its Place.
 
Join Date: Jan 2022
Posts: 9
Abbas is on a distinguished road
Default How To Auto Copy And Paste With A Footnote In Its Place.

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.
Reply With Quote
  #2  
Old 01-14-2022, 10:37 PM
gmayor's Avatar
gmayor gmayor is offline How To Auto Copy And Paste With A Footnote In Its Place. Windows 10 How To Auto Copy And Paste With A Footnote In Its Place. Office 2019
Expert
 
Join Date: Aug 2014
Posts: 4,101
gmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud of
Default

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
If you have empty paragraphs to provide the spacing, add
Code:
oRng.Text = Replace(oRng.Text, vbCr & vbCr, vbCr)
oRng.ParagraphFormat.SpaceAfter = 12
immediately after the line
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
Reply With Quote
  #3  
Old 01-15-2022, 03:00 AM
Abbas Abbas is offline How To Auto Copy And Paste With A Footnote In Its Place. Windows 10 How To Auto Copy And Paste With A Footnote In Its Place. Office 2016
Novice
How To Auto Copy And Paste With A Footnote In Its Place.
 
Join Date: Jan 2022
Posts: 9
Abbas is on a distinguished road
Default A formatting problem

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
Reply With Quote
  #4  
Old 01-15-2022, 05:07 AM
gmayor's Avatar
gmayor gmayor is offline How To Auto Copy And Paste With A Footnote In Its Place. Windows 10 How To Auto Copy And Paste With A Footnote In Its Place. Office 2019
Expert
 
Join Date: Aug 2014
Posts: 4,101
gmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud of
Default

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
Reply With Quote
  #5  
Old 01-15-2022, 06:33 AM
Abbas Abbas is offline How To Auto Copy And Paste With A Footnote In Its Place. Windows 10 How To Auto Copy And Paste With A Footnote In Its Place. Office 2016
Novice
How To Auto Copy And Paste With A Footnote In Its Place.
 
Join Date: Jan 2022
Posts: 9
Abbas is on a distinguished road
Default

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,
Reply With Quote
Reply

Thread Tools
Display Modes


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
How To Auto Copy And Paste With A Footnote In Its Place. 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
How To Auto Copy And Paste With A Footnote In Its Place. Paste Special: Copy and Paste Formatting Only? tinfanide Word 6 03-06-2013 12:21 AM

Other Forums: Access Forums

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