Reply
 
Thread Tools Display Modes
  #1   Report Post  
Dennis
 
Posts: n/a
Default Help making VBA code more efficient

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
  #2   Report Post  
Doug Robbins
 
Posts: n/a
Default

Sounds like this might help:

See the article "Clean Web Text" at:

http://word.mvps.org/FAQs/Formatting/CleanWebText.htm


--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP
"Dennis" wrote in message
...
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



  #3   Report Post  
Dennis
 
Posts: n/a
Default

Thanks Doug,

Any thoughts on how to make the code more efficient?

Dennis

"Doug Robbins" wrote:

Sounds like this might help:

See the article "Clean Web Text" at:

http://word.mvps.org/FAQs/Formatting/CleanWebText.htm


--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP
"Dennis" wrote in message
...
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




  #4   Report Post  
Graham Mayor
 
Posts: n/a
Default

See http://www.gmayor.com/replace_using_wildcards.htm
or even
http://www.gmayor.com/Zips/stripmail.zip

--

Graham Mayor - Word MVP

My web site www.gmayor.com
Word MVP web site http://word.mvps.org




Dennis wrote:
Thanks Doug,

Any thoughts on how to make the code more efficient?

Dennis

"Doug Robbins" wrote:

Sounds like this might help:

See the article "Clean Web Text" at:

http://word.mvps.org/FAQs/Formatting/CleanWebText.htm


--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP
"Dennis" wrote in message
...
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



  #5   Report Post  
Suzanne S. Barnhill
 
Posts: n/a
Default

You might see http://gregmaxey.mvps.org/Clean_Up_Text.htm

--
Suzanne S. Barnhill
Microsoft MVP (Word)
Words into Type
Fairhope, Alabama USA
Word MVP FAQ site: http://word.mvps.org
Email cannot be acknowledged; please post all follow-ups to the newsgroup so
all may benefit.

"Dennis" wrote in message
...
Thanks Doug,

Any thoughts on how to make the code more efficient?

Dennis

"Doug Robbins" wrote:

Sounds like this might help:

See the article "Clean Web Text" at:

http://word.mvps.org/FAQs/Formatting/CleanWebText.htm


--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP
"Dennis" wrote in message
...
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





Reply
Thread Tools
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
adding the post code Louise Mailmerge 3 May 4th 05 06:27 PM
UPC BAR CODE davek Microsoft Word Help 4 March 22nd 05 11:16 PM
POSTNET bar code for envelopes in Word 2002? Brady in Helotes Microsoft Word Help 1 March 5th 05 11:27 PM
Errors in Postal bar code Tom Hadley Mailmerge 0 January 10th 05 10:13 PM
How do I use the PRINT field code to ... Dave Microsoft Word Help 3 December 13th 04 03:06 PM


All times are GMT +1. The time now is 09:25 PM.

Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 Microsoft Office Word Forum - WordBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Word"