PDA

View Full Version : Replace groups of spaces with Tab



clhare
01-06-2008, 07:28 AM
I'm trying to clean up a document that uses spaces to separate columns instead of using a table. Is there a way to use a macro to determine the maximum number of spaces strung together and replace that group of spaces with a tab throughout the document, then look for the next largest number of spaces and replace with a tab throughout, and keep doing until there's only one space at a time?

I'm thinking that once I get the spaces replaced, then I could convert the text to a table and use the tabs to determine the next column.

We're going to get alot of generated documents that need this conversion, so any help or suggestion I can get would be greatly appreciated!

TonyJollans
01-06-2008, 06:01 PM
If what you want to do is replace all instances or more than one space with a single tab then all you need is a simple Find and Replace.

Ctrl+H to bring up the dialog.
Press More if need be to see the full dialog
Check Use Wildcards
Find " {2,}" (without the quotes - that's space, left brace, two, comma, right brace)
Replace "^t" (again without the quotes - that's caret, letter t)
Hit Replace All

clhare
01-07-2008, 04:27 AM
Wow! I didn't know you could do that! Thank you so much! Worked great!! I have to read up on wildcards now--I don't know anything about them!

Thanks again!

:biggrin:

EricFletcher
01-07-2008, 08:38 AM
You can use the special operator "^w" in Find and Replace: put ^w in the Find what box and ^t in the Replace with box, then Replace All. If you click the Special button (in F&R's More... expanded dialog), you'll see "White space" at the bottom, and it inserts the ^w for you. The tab character is represented by ^t.

You may need to deal with spaces at the beginning and ends of lines too: "^t^p" to "^p" will remove trailing tabs (after you've changed spaces to tabs); "^p^t" to "^p" will remove leading tabs.

EricFletcher
01-07-2008, 08:58 AM
My satellite connection dropped before the page refreshed to get my response uploaded (it gets flakey when we get wet snow here!) so I didn't see Tony's response first.

I really wish MS didn't hide the good stuff in the Find dialog: that More... button is probably the most clicked one I use!

I'd certainly encourage you to read up on the wildcard features Cheryl. They are extremely powerful tools for manipulating content in Word, but are poorly documented in Word's Help (as are the explanations about how to make effective use of capabilities hidden away in the Format and Special buttons). Here is a resource I've found very helpful for wildcards: http://word.mvps.org/faqs/general/usingwildcardscontent.htm

and on the same MVP site, this gives a good overview of using the Special and Format buttons: http://word.mvps.org/faqs/general/FindingSpecialCharacters.htm

And of course, you can always post questions here to get clarification about how you might approach a problem!

clhare
01-07-2008, 11:17 AM
Great! Thanks for the links! This will be a big help to me.