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

DocAElstein

Banned user
Joined
May 24, 2014
Messages
1,336
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:
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:
[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………………………….
 

Excel Facts

Round to nearest half hour?
Use =MROUND(A2,"0:30") to round to nearest half hour. Use =CEILING(A2,"0:30") to round to next half hour.
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)
 
Upvote 0
Thanks Paul,

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.



Code:
[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!!
 
Upvote 0
.......... get the code I would need, for example.



Code:
[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]

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

Code:
[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]
 
Upvote 0
More efficient would be:
Code:
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
 
Upvote 0
More efficient would be:
Code:
Sub KnockDoubleCarriageReturnAndSpacesOutAndSomeFunWithBBCodeColors()
With ....
... .
..........
End With
End Sub

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
 
Last edited:
Upvote 0

Forum statistics

Threads
1,223,725
Messages
6,174,134
Members
452,546
Latest member
Rafafa

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top