I am trying to use a for next loop with an if then statement in Word VBA. The purpose of the code is that if the paragraph of the Word document is not empty, it will select the text and copy it and paste it in a new Word document. If the paragraph is empty, it will just go to the next line.
I have tried running the code and each time, it can only select the first paragraph in the whole Word document and I am not sure on how to let the code run and go on to the next paragraph to create a loop.
Sub selectparawithtext()
Dim opara As Paragraphs
Dim x As Integer
For x = 1 To 24
If Paragraphs <> "" Then
Selection.Expand wdParagraph
Selection.Copy
Documents.Add wdNewBlankDocument
Selection.PasteAndFormat (wdFormatOriginalFormatting)
Else
Selection.MoveDown Unit:=wdLine, Count:=1
End If
Next
End Sub
Aucun commentaire:
Enregistrer un commentaire