# WORD VBA Search criteria for ENTER + ENTER (Forum Tools Pasting Issue)



## DocAElstein (May 21, 2015)

Hi, 
.   I have been learning Excel VBA through participation in this board on and off for the last year. 
.-  I have no real experience with WORD VBA. WORD I mostly use for simple text Files.
.   Occasionally I need to do simple substitution of selected bits of text or remove bits from selected bits of text.
.   When the text is big I do a quick macro by “cheating” and using the Macro recorder whilst using the spreadsheet search and replace dialogue box thing..
……
.  I hit a problem when I want to remove an ENTER and an ENTER  from selected data..

.   For example, I have this text selected in WORD



[tr][td]1[/td][td]   Alan’s   [/td][/tr]

[tr][td]]2[td][td]   Nuts    [/td][/tr]


… and I want the macro to work on that selected text to return this


[tr][td]1[/td][td]   Alan’s   [/td][/tr][tr][td]2[td][td] Nuts [/td][/tr]


…  in this case the macro has removed the combination of an ENTER and an ENTER ( Knocked out 2 ENTERs which were alongside each other )   (In the practice I have lots of theses and I want all occurrences of a double ENTER to be knocked out

… can anyone give me the code or code line that does this?

.. below is the sort of code I get from the Macro recorder if I want to knock out spaces , it turns this



[tr][td]1[/td][td]   Alan’s   [/td][/tr]

[tr][td]]2[td][td]   Nuts    [/td][/tr]



Into this



[tr][td]1[/td][td]Alan’s[/td][/tr]

[tr][td]]2[td][td]Nuts[/td][/tr]



```
Code:
 
Sub KnockSpacesOut()
Selection.Find.Text = " "
Selection.Find.Replacement.Text = ""
 
Selection.Find.Execute Replace:=wdReplaceAll
End Sub
```
 
.. so maybe I just need the thing what says ENTER ENTER instead of “ “ in this line ?


```
[CODE]Selection.Find.Text = " "
```
[/CODE]

Or any non macro invented code would be better as I am keen to learn the right way to do this sort of thing with a macro.

Thanks
Alan

P.s.

I have to do a lot of this fiddling about when I paste a BB code or HTML Code from the clipboard into WORD when what I have in the clipboard was got with the MrExcel Screen shot Posting Tools.
.  So maybe there is a way to get the Clipboard to paste the stuff in properly. That might be an alternative solution to this and other problems. But this is a messy one… Somehow the MrExcel Editor does or does not sometimes remove spaces between text ( A very inconsistent problem I find which can be Browser dependant………………………….


----------



## Macropod (Jun 7, 2015)

You really don't need a macro for this - a simple Find/Replace will do, where:
Find = ^p^p
Replace = nothing (or the character of your choice)


----------



## DocAElstein (Jun 7, 2015)

Thanks Paul,



Macropod said:


> You really don't need a macro for this - a simple Find/Replace will do, where:
> Find = ^p^p
> Replace = nothing (or the character of your choice)


 
I was missing the ^ -That is  a weird character on my key board…   If you hit the ^ on my keyboard it does not come up..   So copying what you wrote I was able to get there…. ( Later I noticed by coincidence that if you hit that key  twice you get ^^  Then I simply edit one of them away to get the single ^ ) 

.   Anyways, does the trick as you said. Great. Thanks.
.  I would use it in a code if I was doing lots of Formatting changes or corrections at the same time. Using your suggested method whilst recording a macro I was able to get the code I would need, for example.




```
[color=purple]Sub[/color] KnockDoubleCarriageReturnAndSpacesOutAndSomeFunWithBBCodeColors()
[color=lightgreen]'RemoveDoubleEnter'Paul:http://www.mrexcel.com/forum/general-excel-discussion-other-questions/856462-word-visual-basic-applications-search-criteria-enter-enter-forum-tools-pasting-issue.html[/color]
Selection.Find.Text = "^p^p" [color=lightgreen]'Suche[/color]
Selection.Find.Replacement.Text = "" 'Ersetzen
Selection.Find.Execute Replace:=wdReplaceAll [color=lightgreen]'Ersetzenalles[/color]
'RemoveSinglespaces
Selection.Find.Text = ""
Selection.Find.Replacement.Text = ""
Selection.Find.Execute Replace:=wdReplaceAll
[color=lightgreen]'ChangeBluetoPurpleinBBCode(JustforFun!!)[/color]
Selection.Find.Text = "[color=purple]"
Selection.Find.Replacement.Text = "[color=purple]"
Selection.Find.Execute Replace:=wdReplaceAll
[color=purple]End[/color] [color=purple]Sub[/color]
```
 

Thanks again 
Alan

P.s. I see you are the Mr Excel Word Expert and were busy clearing out all the Word Threads!!!!  Glad to have you back!!


----------



## DocAElstein (Jun 7, 2015)

DocAElstein said:


> .......... get the code I would need, for example.
> 
> 
> 
> ...


 
Oops   The 10 minute edit time span caught me out again...  code ( color change correction!! )


```
[COLOR=blue]Sub[/COLOR] KnockDoubleCarriageReturnAndSpacesOutAndSomeFunWithBBCodeColors()
[COLOR=lightgreen]'RemoveDoubleEnter'Paul:http://www.mrexcel.com/forum/general-excel-discussion-other-questions/856462-word-visual-basic-applications-search-criteria-enter-enter-forum-tools-pasting-issue.html[/COLOR]
Selection.Find.Text = "^p^p" [COLOR=lightgreen]'Suche[/COLOR]
Selection.Find.Replacement.Text = "" 'Ersetzen
Selection.Find.Execute Replace:=wdReplaceAll [COLOR=lightgreen]'Ersetzenalles[/COLOR]
'RemoveSinglespaces
Selection.Find.Text = ""
Selection.Find.Replacement.Text = ""
Selection.Find.Execute Replace:=wdReplaceAll
[COLOR=lightgreen]'ChangeBluetoPurpleinBBCode(JustforFun!!)[/COLOR]
Selection.Find.Text = "[color=blue]"
Selection.Find.Replacement.Text = "[color=purple]"
Selection.Find.Execute Replace:=wdReplaceAll
[COLOR=blue]End[/COLOR] [COLOR=blue]Sub[/COLOR]
```


----------



## Macropod (Jun 7, 2015)

More efficient would be:

```
Sub KnockDoubleCarriageReturnAndSpacesOutAndSomeFunWithBBCodeColors()
With Selection.Find
  'RemoveDoubleEnter
  .Text = "^p^p" 'Suche
  .Replacement.Text = "" 'Ersetzen
  .Execute Replace:=wdReplaceAll 'Ersetzenalles
  'RemoveSinglespaces
  .Text = " "
  .Execute Replace:=wdReplaceAll
  'ChangeBluetoPurpleinBBCode(JustforFun!!)
  .Text = "[color=blue]"
  .Replacement.Text = "[color=purple]"
  .Execute Replace:=wdReplaceAll
End With
End Sub
```


----------



## DocAElstein (Jun 7, 2015)

Macropod said:


> More efficient would be:
> 
> ```
> Sub KnockDoubleCarriageReturnAndSpacesOutAndSomeFunWithBBCodeColors()
> ...



Thanks for the Reply,

.  Yep, I guess I must get used to using the  With  End With thing. 
.  While I am learning I alwasy prefer not to use them as I can follow codes a bit easier. - ( - especially when there are multiple With End With nested within...  Then I get really confused!! )
.  But, it always seems to be said to be efficienter, -  so I must get used to them, ( and probably a lot of more bad habits I need to get out of!! )

Thanks again,
.  have a nice Sunday
Alan


----------

