Help making VBA code more efficient

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Office Pro 2003

The following code works well but I am too much a novice to do it efficiently.

The code finds Soft Return, Hard Return, vbLf and three spaces for two
(Normally there are two spaces after a period. The code below makes three
spaces 2+1. Therefore, I must reset three with two)

Sub FindReplaceHardSoftReturn()
With Selection.Find
.Text = vbLf 'Line Feed Chr(10)
.Replacement.Text = " "
.Forward = True
.Wrap = wdFindContinue
.Execute Replace:=wdReplaceAll
End With

With Selection.Find
.Text = "^l" 'Soft Return Chr(11)
.Replacement.Text = " "
.Forward = True
.Wrap = wdFindContinue
.Execute Replace:=wdReplaceAll
End With

With Selection.Find
.Text = "^p" 'Hard Return Chr(13)
.Replacement.Text = " "
.Forward = True
.Wrap = wdFindContinue
.Execute Replace:=wdReplaceAll
End With

With Selection.Find
.Text = " " 'Three spaces replaced with two
.Replacement.Text = " "
.Forward = True
.Wrap = wdFindContinue
.Execute Replace:=wdReplaceAll
End With

End Sub


Any thoughts would be helpful.


Dennis
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top