PDA

View Full Version : Find and Replace/Insert 'CR', del Space where ever a user Clicks in a Word document



DavidL
04-03-2018, 06:06 AM
Hi All,
I have text copied from various sources in different word files which I want to format in a particular style so as to match a given layout. Basically the text needs to be broken down into new lines/paragraphs at specific places which is given in the instructions. Instead of having to press 'Enter' and then remove/delete spaces at every line, I wish to do that with just one click per line using macro.
These files could be 500+ in number, so modifying all in one go using Macros is the preferred way.(Although I find it impossible when the point of insertion of 'Enter' can only be done manually on each file.) I have used Macros to achieve 90% of that however need one last step where a Macro can do the following:
1. Where ever the user clicks on the page, all space(regular, non-breaking space, white-space) until the next printed character is deleted.
2. An 'Enter' or Carriage-Return is inserted, so that the text moves to the next line.
Steps 1 and 2 are repeated at every click the user makes on the text.

[Example Text]
offer unto the LORD, have I given thee, and thy sons and thy daughters with thee, by a statute for ever: it is a covenant of salt for ever before the LORD unto thee and to thy seed with thee. 18:20 And the LORD spake unto Aaron, Thou shalt have no inheritance in their land, neither shalt thou have any part among them: I am thy part and thine inheritance among

[Expected Text]
offer unto the LORD, have I given thee,
and thy sons and thy daughters with thee,
by a statute for ever: it is a
covenant of salt for ever before the LORD
unto thee and to thy seed with thee.
18:20 And the LORD spake unto Aaron,
Thou shalt have no inheritance in their
land, neither shalt thou have any
part among them: I am thy
part and thine inheritance among

Notice that as 'Enter' is pressed at the end of these lines although they come in next line but usually a space character is there in front of those lines(appears in MS Word but not here in the forum's text window:)), which I wanted to remove automatically at one go.
Another approach is to click, delete the required spaces until the next character and then hit enter.
Something like Find ^w and Replace with ^p running at every place a user clicks, but with Macros.
Any help is appreciated.

Thanks,
David Lover

macropod
04-03-2018, 05:03 PM
Cross-posted at:
https://stackoverflow.com/questions/49631410/find-and-replace-insert-cr-del-space-wherever-a-user-clicks-in-a-word-documen
and:
http://www.msofficeforums.com/word-vba/38664-find-replace-insert-cr-delete-leading-spaces.html
Please read VBA Express' policy on Cross-Posting in item 3 of the rules: http://www.vbaexpress.com/forum/faq.php?faq=new_faq_item#faq_new_faq_item3

DavidL
04-03-2018, 11:02 PM
I got an answer which worked out for me with a minute modification. It's in a different forum, so just linking my answer there.
https://stackoverflow.com/questions/49631410/find-and-replace-insert-cr-del-space-wherever-a-user-clicks-in-a-word-documen
(http://<br />https://stackoverflow.com/a/49643714/8980537<br />)

Thanks Paul