Code won't execute Main Macro Calls - non breaking spaces



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




.



Relevant Pages

  • Re: closing a macro completely upon connect
    ... fixed the bug associated with SET KEY and terminal mode, ... invoking a macro as a kverb works. ... interactively from the command prompt. ... A macro mapped to a key will not execute if you enter CONNECT mode ...
    (comp.protocols.kermit.misc)
  • Re: How to insert pdf attachment with word email merge?
    ... "Then execute to a new document the mail merge that you want to send out by ... document when you run the macro. ... Doug Robbins - Word MVP ...
    (microsoft.public.word.mailmerge.fields)
  • Re: PC Word Macro Not Working in Mac Word
    ... I wrote my original in Mac Word, ... .Execute Replace:=wdReplaceAll ... Do ' A post-test loop! ... I did a test macro with basically just the code you ...
    (microsoft.public.mac.office.word)
  • Re: Code wont execute Main Macro Calls - non breaking spaces
    ... I am going to attach my first array which is the same as you have ... So each macro will execute one after the other. ... separated each find string and each replace string for the sake of ...
    (microsoft.public.word.vba.general)
  • Re: Email merge with attachment
    ... The first one is the catalog/directory type mail merge which is the one in the main document of which you setup the table with the mailmerge field that contains the email addresses in the first cell and, in your case as it sounds like you are sending the same file to each person, the path and filename of that file in the second cell like the second example in the article. ... You must execute that merge to a new document and the document produced by that merge will contain a table with a row of data for each record in the data source. ... Then with the document created by executing that merge as active document, you then run the macro. ...
    (microsoft.public.word.mailmerge.fields)

Loading