DEV Community

Oscar Sun(孫守真字任真)
Oscar Sun(孫守真字任真)

Posted on

Answer: How to remove line break at the end of each paragraph and then join the paragraphs using VBA?

para.Range.MoveStart Unit: wdCharacter , Count:=-1

Should be :

para.Range.MoveStart Unit:= wdCharacter , Count:=-1

Your code is simply wrong and will clear all contents after execution! Try this code first plz:

Sub removelinebreak()
    Dim rng As Range
    Dim para As Paragraph
    Dim ur As UndoRecord
    Set ur = Word.Application.UndoRecord
    ur.StartCustomRecord "removelinebreak"

Top comments (0)