Format Phone Number in a text field

B

BruDe

I'm just looking for a simple macro or VBA procedure to let me format a phone
number in a from field so I can enter it like this, "1234567890", and when I
tab to the next field it formats to look like this, "(123) 456-7890" I did
this in Word version 2, but of course, coding has marched on and left me
behind
 
D

Doug Robbins

Assuming that the formfield has the bookmark name of Phone, using the
following in a macro run on exit from the formfield will do it:

Dim Pnumber As String
Pnumber = ActiveDocument.FormFields("Phone").Result
ActiveDocument.FormFields("Phone").Result = "(" & Left(Pnumber, 3) & ") " &
Mid(Pnumber, 4, 3) & "-" & Right(Pnumber, 4)


--
Please respond to the Newsgroup for the benefit of others who may be
interested. Questions sent directly to me will only be answered on a paid
consulting basis.

Hope this helps,
Doug Robbins - Word MVP
 

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