in WORD DOCUMENT, I want to type in a 9-digit phone number "xxxxxx

J

jake

in WORD DOCUMENT, I want to type in a 9-digit phone number "xxxxxxxxx" and
have it automatically change to the following format: (xxx) xxx-xxxx. Please
help
 
D

Doug Robbins - Word MVP

The only way to do it automatically in Word is to have the number entered
into a Text FormField that is formatted as a Number field with the
appropriate formatting switch in a document that is protected for filling in
forms.

--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP, originally posted via msnews.microsoft.com
 
F

Fumei2 via OfficeKB.com

May I point out that

9-digit phone number "xxxxxxxxx

is indeed 9 digits.

However....

(xxx) xxx-xxxx
is 10 digit, PLUS a space - between the paraenthesis and the remaining 7
digits.

The space is not a problem, but please tell me what determines the missing
digit (from 9 to 10)? Are you making up a number for the start? For the end?
Somewhere in between?

All kidding aside (and I hope that was a typo re: 9 digit), there is another
possibility, if this is important.

You can have a macro that MUST be executed when you finish typing your - ahem
- 10 digits.

xxxxxxxxxx

As SOON AS YOU TYPE IT, execute the following. I have it set up for a
keyboard shortcut of Alt-p, so type:

xxxxxxxxxx Alt-p

Sub CovertPhone()
' keyboard shortcut = Alt-P
Dim strChangedTo As String
Selection.MoveLeft Unit:=wdCharacter, Count:=10, Extend:=wdExtend

strChangedTo = Selection.Text
strChangedTo = "(" & Left(strChangedTo, 3) & ")" & _
" " & Left(Right(strChangedTo, 7), 3) & "-" & _
Right(strChangedTo, 4)
With Selection
.Text = strChangedTo
.Collapse 0
End With
End Sub

xxxxxxxxxx

is changed to

(xxx) xxx-xxxx

I have to concur that there is no way to easily do this automatically. Not
with having to have the numbers variable.
 
F

Fumei2 via OfficeKB.com

You could also change it so that you could put the cursor into a chunk of 10
digits, and make those become:

(xxx) xxx-xxxx

So you could do it after the fact, by placing the cursor in a group of 10
digits.

AND..............

you can do the whole thing after the fact, if that helps. Although the
following will change ALL chunks of 10 digits into that format.

Sub All_10Number()
Dim r As Range
Set r = ActiveDocument.Range
With r.Find
.ClearFormatting
.MatchWildcards = True
.Text = "[1-9]{10}"
Do While .Execute(Forward:=True) = True
r.Text = "(" & Left(r.Text, 3) & ")" & _
" " & Left(Right(r.Text, 7), 3) & "-" & _
Right(r.Text, 4)
r.Collapse 0
Loop
End With
End Sub

2316674451
8907118223
6049231125

get changed to:

(231) 667-4451
(890) 711-8223
(604) 923-1125

These can be ANY place in the document.

Gerry
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top