Microsoft Office Forums

Go Back   Microsoft Office Forums > >

 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
  #4  
Old 11-13-2023, 06:23 AM
gmaxey gmaxey is offline Can somebody help me with a macro to move a line two lines down? Windows 10 Can somebody help me with a macro to move a line two lines down? Office 2019
Expert
 
Join Date: May 2010
Location: Brasstown, NC
Posts: 1,636
gmaxey is just really nicegmaxey is just really nicegmaxey is just really nicegmaxey is just really nicegmaxey is just really nice
Default

It seems that Vivka's code misses the last instance of your keyword. I also don't understand the reason for the If .found condition. You might try:


Code:
Sub Move_Two_Lines_Down()
Dim oRng As Range
  Set oRng = ActiveDocument.Range
  Application.ScreenUpdating = False
  With oRng.Find
    .ClearFormatting
    .Replacement.ClearFormatting
    .Text = "Keywords ^#"
    .Forward = True
    .Format = True
    .Wrap = wdFindStop
    While .Execute
      oRng.Paragraphs(1).Range.Cut
      oRng.Move unit:=wdParagraph, Count:=2
      oRng.Paste
      If oRng.End = ActiveDocument.Range.End - 1 Then
        oRng.InsertBefore vbCr
        oRng.Paragraphs.Last.Next.Range.Delete
      End If
       oRng.Collapse wdCollapseEnd
    Wend
  End With
  Application.ScreenUpdating = True
lblExit:
  Set oRng = Nothing
  Exit Sub
End Sub
__________________
Greg Maxey
Please visit my web site at http://www.gregmaxey.com/
Reply With Quote
 



Similar Threads
Thread Thread Starter Forum Replies Last Post
1st line of 4-line poem centrally aligned; how to get lines 2-4 to start at same location on page Swarup Word 6 09-16-2022 11:07 AM
Can somebody help me with a macro to move a line two lines down? I need a macro to move dangling words to a new line please iNeedaMacroPlease Word VBA 2 11-27-2020 11:34 AM
How to move a line to another line that starts with a chain selected in the 1st one? gloub Word VBA 24 03-19-2019 03:12 PM
Lock line so text does not move to next line saundrals Word 2 06-19-2014 03:59 PM
Lines move between close and open jsmath22 PowerPoint 0 12-15-2010 07:44 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 09:47 AM.


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