Re: Code won't execute Main Macro Calls - non breaking spaces
- From: "Ann Marie" <am@xxxxxxxxxxxxx>
- Date: Tue, 29 Aug 2006 16:46:46 +1000
Hi Greg,
Oops. I need ALL the help I can get - that's great. Thank you for that. My
project is almost complete because you were all so willing to share. THANK
YOU.
"Greg Maxey" <gmaxey@xxxxxxxx> wrote in message
news:1156770243.017998.313960@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
Ann,
Hi yourself. I don't recall being involved in this thread and perhaps
you have confusted me with Graham.
I couldn't sort out what your second search pattern was looking for,
but some reasons the first didn't work is that you didn't have regular
spaces in the search string and you didn't have wildcards set to
"True." Try this:
Public Sub MainMacro()
'Dates - replace spaces with non breaking spaces
DoFindReplace "([0-9]{1,}) ([ADFJMNOS][A-Za-z]{2,}) ([0-9]{4})",
"\1^0160\2^0160\3", True
'Remove double spaces TEST WORKS
DoFindReplace " ", " ", False
'Remove all double tabs TEST WORKS
DoFindReplace "^t^t", "^t", False
'Remove empty paras (unless they follow a table or start or finish a
doc) TEST WORKS
DoFindReplace "^p^p", "^p", False
End Sub
Sub DoFindReplace(FindText As String, ReplaceText As String,
bMatchWildCards As Boolean)
Dim oRng As Word.Range
Set oRng = ActiveDocument.Range
With oRng.Find
.Text = FindText
.Replacement.Text = ReplaceText
.MatchWildcards = bMatchWildCards
.MatchAllWordForms = False
.Execute Replace:=wdReplaceAll
End With
'Free up some memory
ActiveDocument.UndoClear
End Sub
Ann Marie wrote:
Hi again Doug and Greg,
My MAIN MACRO does not execute the first 2 options DO FIND AND REPLACE.
But
both syntax work in the Find and Replace window. The remainder of the
MAIN
MACRO options execute.
Would appreciate if someone could point me in the right direction to fix
this. I would like to expand on my call routines but one step at a time.
Would really appreciate it.
TEST DATA:
20 June 2007
XXX 19 233 444 555
XXX 000 222 222
10 MAY 2006
13 JUNE 2006
13 may 2006
XXXX 123444
And this is a test sentence. This replace is just a test. Thank you for
helping? And that is that.
***MACROS***
Option Explicit
Sub DoFindReplace(FindText As String, ReplaceText As String, _
Optional bMatchWildCards As Boolean = False)
With Selection.Find
.ClearFormatting
.Replacement.ClearFormatting
.Text = FindText
.Replacement.Text = ReplaceText
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
Do While .Execute
'Keep going until nothing found
.Execute Replace:=wdReplaceAll
Loop
'Free up some memory
ActiveDocument.UndoClear
End With
End Sub
'Call the macro:
Public Sub MainMacro()
'Replace spaces with non breaking spaces
Call DoFindReplace("([0-9]{1,2})([ADFJMNOS][A-Za-z]{2,})([0-9]{4})",
"\1^0160\2^0160\3^0160\4")
'Dates - replace spaces with non breaking spaces
Call
DoFindReplace(FindText:="([0-9]{1,2})(([0-9]{1,2})([ADFJMNOS][A-Za-z]{2,})([0-9]{4})",
ReplaceText:="\1^0160\2^0160\3", bMatchWildCards:=True)
'Remove double spaces TEST WORKS
Call DoFindReplace(" ", " ")
'Remove all double tabs TEST WORKS
Call DoFindReplace("^t^t", "^t")
'Remove empty paras (unless they follow a table or start or finish a
doc) TEST WORKS
Call DoFindReplace("^p^p", "^p")
End Sub
.
- References:
- Code won't execute Main Macro Calls - non breaking spaces
- From: Ann Marie
- Re: Code won't execute Main Macro Calls - non breaking spaces
- From: Greg Maxey
- Code won't execute Main Macro Calls - non breaking spaces
- Prev by Date: Re: What did I do wrong...UserForm and AutoNew
- Next by Date: Re: MoveUntil method hangs
- Previous by thread: Re: Code won't execute Main Macro Calls - non breaking spaces
- Next by thread: how to print at least 1 cm of row before break
- Index(es):
Relevant Pages
|