Jump to content
Macro Express Forums

Replace Every Comma With An Enter?


Recommended Posts

I've been running a macro in Word that does a control-f, inserts a comma, exits the FIND window when it encounters a comma and then TEXT TYPE's an ENTER.


I'm thinking doing this through the clipboard would be lots faster since it's currently taking us over 30 minutes to do this in Word even using REPEAT 1000's of times in just one extremely large document. (I'm converting documents from 100+ pages of text to an extremely long list.) I've been playing with variables and repeats because it should be pretty simple but no dice so far.


Could someone please post the couple of lines of code necessary to replace all of the commas in clipboard with ENTERS and then spit the result out of clipboard on to a blank page I'd have open?



Link to comment
Share on other sites

You need to fist generate the CRLF as a variable. Click here to see a small subroutine I use all the tiem for this purpose. It does both but the important thing to understand is that an enter is actually two characters, carrige return and line feed.


<REM2:Set CR><ASCIIC:95:1:13><ASCIIC:96:1:10><TVAR2:95:01:%T95%%T96%><REM2:Set CR><CLIPT><TVAR2:01:03:><TMVAR2:21:01:01:000:000:,%T95%><TEXTTYPE:%T1%>


Might look like this in the script.


// Set CR

Variable Set %T95% to ASCII Char of 13

Variable Set %T96% to ASCII Char of 10

Variable Set String %T95% "%T95%%T96%"

// Set CR

Clipboard Cut

Variable Set String %T1% from Clipboard

Replace "," with "%T95%" in %T1%

Text Type: %T1%


As an asside you might consider modifing the file directly. Read each line in directly, do the substitution and write it back out to a new file. This would be a lot faster.

Link to comment
Share on other sites

Hello HeyJim!


Another option (something I've done in the past) is to use Find and Replace (Ctrl+H) instead of just Find. See the attached picture. By setting the Search field to "All", every instance of a comma will be changed to a CR/LF at once in the document.


Link to comment
Share on other sites

Thanks, Cory, Joe.

I used both suggestions. Not that I had to do that. I had to remove the clipboard cut command from the macro and then it worked perfectly. Had me scratching my head wondering for a couple of minutes but no big deal. As I suspected and everyone else on the board probably knew it was WAY faster than the way I had been using.


Then I couldn't help but try your way, Joe. Didn't know I could use a ^p for the replace. Also found out it's case sensitive.


I've learned from both of you. Thanks again.



Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Create New...