#1
|
|||
|
|||
clean extra space
Hello,
I tried to change the macro below so that in one run it will delete an unnecessary space next to the + - signs Is it possible? I can duplicate the macro and put one mark per macro but that leaves me with a lot of shortcuts. Thanks Sub MFindReplacePARA() Dim aDoc As Document, strFindText As String, strReplaceText As String strFindText = "^p^p" strReplaceText = "^p" strFindText = " +" strReplaceText = "+" strFindText = "+ " strReplaceText = "+" strFindText = "- " strReplaceText = "-" strFindText = " -" strReplaceText = "-" For Each aDoc In Application.Documents With aDoc.Range.Find .Text = strFindText .Replacement.Text = strReplaceText .Forward = True .Wrap = wdFindContinue .Format = False .MatchCase = False .MatchWholeWord = True .MatchWildcards = False .MatchSoundsLike = False .MatchAllWordForms = False .Execute Replace:=wdReplaceAll End With Next aDoc End Sub |
#2
|
|||
|
|||
Hi, Yacov! It's not difficult:
Code:
Sub MFindReplacePARA() With selection.range.Find .text = " {1,}([+-]) {1,}" .Replacement.text = " \1 " .Forward = True .Wrap = wdFindStop .Format = False .MatchWildcards = True .MatchSoundsLike = False .MatchAllWordForms = False .Execute Replace:=wdReplaceAll End With End Sub You may modify the code to meet your requirements. |
#3
|
|||
|
|||
thanks a lot Vivka.
For some reason it sometimes works for me and sometimes it doesn't. But I recorded a macro that runs several macros and each one does a swap. And so by a single shortcut I can run them all together. Sub CLEAN() ' ' CLEAN Macro ' ' Application.Run MacroName:="Normal.NewMacros.MFindReplaceMINUS1" Application.Run MacroName:="Normal.NewMacros.MFindReplaceMINUS2" Application.Run MacroName:="Normal.NewMacros.MFindReplacePLUS1" Application.Run MacroName:="Normal.NewMacros.MFindReplacePLUS2" Application.Run MacroName:="Normal.NewMacros.MFindReplacePARA" Application.Run MacroName:="Normal.NewMacros.MFindReplace" End Sub |
#4
|
|||
|
|||
Yacov, could you, please, post a sample of the problem document. I'm curious, because for me the code works smoothly: it leaves only one space before and after + and -. Maybe you want to delete single spaces also? Then use:
Code:
Sub MFindReplacePARA() With selection.range.Find .text = " {1,}([+-]) {1,}" .Replacement.text = "\1" .Forward = True .Wrap = wdFindStop .Format = False .MatchWildcards = True .MatchSoundsLike = False .MatchAllWordForms = False .Execute Replace:=wdReplaceAll End With End Sub |
#5
|
|||
|
|||
Thank a lot, now it works great.
Sorry for not explaining myself in the first place. |
#6
|
|||
|
|||
Yacov, the following code will also delete empty paragraps:
Code:
Sub Spaces() With selection.range.Find .text = Chr(13) & "{2,}" .Replacement.text = Chr(13) .Forward = True .Wrap = wdFindStop .Format = False .MatchWildcards = True .MatchSoundsLike = False .MatchAllWordForms = False .Execute Replace:=wdReplaceAll .text = " {1,}([+-]) {1,}" .Replacement.text = "\1" .Execute Replace:=wdReplaceAll End With End Sub |
#7
|
|||
|
|||
very useful,
Thank you very much |
#8
|
|||
|
|||
You are welcome, Yacov!
|
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
Removing extra space between word | BillMcEnaney | Word | 9 | 02-16-2023 11:03 PM |
How to delete extra space (between lines)? | Gerald Wilhelm | Word | 15 | 08-26-2020 04:08 AM |
Merge field needs extra space when it populates | jaj42305 | Mail Merge | 3 | 04-21-2016 03:33 PM |
extra space before equation | Nice2007 | Word | 1 | 04-27-2012 05:05 PM |
Slight extra space between lines. | lucadelcarlo | Word | 1 | 04-23-2011 04:05 PM |