Home |
Search |
Today's Posts |
#1
|
|||
|
|||
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
|
|||
|
|||
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
|
|||
|
|||
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
|
|||
|
|||
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
|
|||
|
|||
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 | |
|
|
Similar Threads | ||||
Thread | Forum | |||
adding the post code | Mailmerge | |||
UPC BAR CODE | Microsoft Word Help | |||
POSTNET bar code for envelopes in Word 2002? | Microsoft Word Help | |||
Errors in Postal bar code | Mailmerge | |||
How do I use the PRINT field code to ... | Microsoft Word Help |