Microsoft Office Forums

Go Back   Microsoft Office Forums > >

 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
  #3  
Old 12-12-2024, 04:31 AM
Italophile Italophile is offline copy a paragraph Windows 11 copy a paragraph Office 2021
Expert
 
Join Date: Mar 2022
Posts: 563
Italophile is just really niceItalophile is just really niceItalophile is just really niceItalophile is just really nice
Default

I don't know why your code is getting an error, but there is a better way to achieve what you want without using the clipboard.

Code:
Sub COPYPAR()
    'Copy a range from the current para's start till after "=" and
    'add it after the para.

    Dim selRng As Range: Set selRng = Selection.Paragraphs(1).Range
    
    Dim copyRng As Range: Set copyRng = selRng.Duplicate
    'make sure that = is found
    If Not copyRng.MoveEndUntil("=", wdBackward) = 0 Then
        'make sure that the = is in the same paragraph
        If copyRng.InRange(selRng) Then
            selRng.InsertParagraphAfter
            selRng.Collapse wdCollapseEnd
            selRng.FormattedText = copyRng.FormattedText
        End If
    End If
End Sub
Reply With Quote
 



Similar Threads
Thread Thread Starter Forum Replies Last Post
Macro/VBA to copy text paragraph and insert as new row in summary table, with RAG l0zzie88 Word VBA 2 01-18-2024 03:42 PM
Copy the entire paragraph in wildcards asderam Word VBA 0 01-28-2021 05:54 PM
copy a paragraph Macro to search for a particular word, copy the entire paragraph to a new document Productivity Word VBA 2 10-25-2019 06:40 AM
copy a paragraph Direct (copy-paste) reference from another paragraph (CITATION) WordNoobx Word 6 05-15-2018 05:46 AM
Copy text to new document based on paragraph numbering mike.mm Word VBA 7 11-22-2016 06:14 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 09:22 PM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2025, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2025 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft