Microsoft

Office challenge: How would you add hyphens to create a hyphenated phrase?

This week, test your Word skills by helping a user that needs to insert hyphens between several words to create a hyphenated phrase.

Here's another unusual user request: how to quickly add hyphens between words to create a hyphenated phrase. For example, suppose your user wants to insert hyphens between the words, best ever annual flower arranging, to create the phrase, the best-ever-annual-flower-arranging contest. Now, some of you would just skip the hyphens, but others might argue that grammatically, the phrase needs them.  (Let's skip the grammar discussion for now.) The user can manually delete the spaces and insert hyphens, but is there an easier alternative?

About

Susan Sales Harkins is an IT consultant, specializing in desktop solutions. Previously, she was editor in chief for The Cobb Group, the world's largest publisher of technical journals.

14 comments
Rick_from_BC
Rick_from_BC

of the phrase, just copy the phrase into both the find & replace boxes, change the spaces to hyphens in the replace box, and 'replace all.

hduff
hduff

Homer Duff hduff@juno.com I would use the Hard Hyphen feature (hold CTRL+SHIFT and key the hyphen) as I typed the text or delete the space then key the hard hyphen. This will also keep the phrase together--no word wrap at the end of the line.

simchuck
simchuck

I suppose this challenge is focused on doing this in Word, but the task is trivial if you don't mind a quick switch to Excel. Assuming the phrase is stored in a single cell, A1, with spaces between words: =SUBSTITUTE(A1," ","-")

Rudi-S
Rudi-S

Type the phrase with the hyphens in a blank doc. Select the phrase On the Insert | QuickParts | AutoText menu, select Save selection to AutoText Gallery, using a name for the autotext; ie: beafa The next time you need the phrase (incl. the hyphens), just type beafa at the insertion point and press ENTER. The autotext kicks in and the entire phrase is added automatically. Of course, one can add many more hyphenated phrases with their own code to insert into the doc.

bethernet
bethernet

Select the text you want to insert the hyphens into. Then click Replace on the Home tab. Replace space with a hyphen. Click Replace All, it will make the change then ask if you want to continue searching the rest of the doc. Just click "no" and you're done.

ssharkins
ssharkins

In this case, you could manually enter the hyphens quicker than you could copy to Excel, type in the formula, and copy back -- couldn't you? But, it's intriguing certainly and a good reminder that other resources are out there! If you're going to go to this much trouble though, I think I'd opt for a Word macro on the QAT -- anyone want to supply a macro for this?

CharlieSpencer
CharlieSpencer

The Autotext would work, but that method is only worth the trouble if you're going to use the phrase repeatedly.

pctrain
pctrain

I agree with bethernet. But the user could also use Control+H to open the Replace function window.

zimmerwoman
zimmerwoman

the find and replace with the 'alt-e, e' is faster for me, but only because I do have the old menu hot-keys hardwired in my brain. However, I am starting to get some of the ribbon hot-keys soldered into the old gray circuitry as well so I might answer the same way in 2 years about the ribbon. The quick-parts autotext is also a good resource and I am starting to use it. If it weren't for you, I wouldn't know the quick-parts were there, so I am getting to know it, although I think it is WAY complicated for what it's doing. Next to "swatting flies with a sledgehammer" in the idiomatic expression dictionary, there is a screenprint of the quick-parts in use. And by the way - is that supposed to be funny: "QUICK Parts"????

simchuck
simchuck

I could see the benefit of an automated solution if you want to do this replacement in multiple places. Following is a simple Word macro that gets the job done (at least in Word 2010).. Sub ChangeSpacesToHyphen() ' ' Replaces all spaces in the selected text with hyphens ' Selection.Find.Execute FindText:=" ", ReplaceWith:="-", _ Replace:=wdReplaceAll End Sub

michael_boardman
michael_boardman

Just replacing four spaces with four hyphens manually is just as easy as any of the above? I'm a great believer in using a program's features, but I think even I would jib at doing this any other way: either click on the space and delete/backspace delete, hit -, Ctrl Right arrow, and repeat, OR just click each space and delete, then hit - and repeat.

ssharkins
ssharkins

I'm wondering if the Find method (it is a method isn't it) relies on "last used" settings. Might need to explore this a bit to make sure all properties are properly set via a With statement, but this is great if that's all it takes. Thanks for providing this simchuck!

simchuck
simchuck

Using the above macro, select the text, run the macro, and... Just-replacing-four-spaces-with-four-hyphens-manually-is-just-as-easy-as-any-of-the-above? I'm-a-great-believer-in-using-a-program's-features,-but-I-think-even-I-would-jib-at-doing-this-any-other-way:-either-click-on-the-space-and-delete/backspace-delete,-hit--,-Ctrl-Right-arrow,-and-repeat,-OR-just-click-each-space-and-delete,-then-hit---and-repeat.

Editor's Picks