Hi there,
If you are using a protected form, then use this macro as the On exit event
for the field containing the telephone number:
'_______________________________________
Sub TelNumber()
Dim TelRange As Range
Dim FirstNum As String
Dim FormatNum As String
ActiveDocument.Unprotect
Set TelRange = Selection.Paragraphs(1).Range
Set TelRange = TelRange.FormFields(1).Range
FirstNum = TelRange.Text
'Remove formatting if just changing already
'formatted number
FirstNum = Replace(FirstNum, "(", "")
FirstNum = Replace(FirstNum, ")", "")
FirstNum = Replace(FirstNum, "-", "")
FirstNum = Replace(FirstNum, " ", "")
'Must have digits
If Not IsNumeric(FirstNum) Then
MsgBox "You must input only digits in " _
& "this field.", vbExclamation, "Digits"
GoTo LeaveSub
End If
'Must have 10 digits
If Len(FirstNum) < 10 _
Or Len(FirstNum) > 10 Then
MsgBox "You must input exactly 10 digits in " _
& "this field.", vbExclamation, "Digits"
GoTo LeaveSub
End If
FormatNum = "(" + Left(FirstNum, 3) + ") " _
+ Mid(FirstNum, 4, 3) + "-" + _
Right(FirstNum, 4)
TelRange.FormFields(1).Result = FormatNum
LeaveSub:
ActiveDocument.Protect _
Type:=wdAllowOnlyFormFields, NoReset:=True
End Sub
'_______________________________________
--
Cheers!
_______________________________________
Jean-Guy Marcil - Word MVP
(e-mail address removed)
Word MVP site:
http://www.word.mvps.org
jgetch said:
I have forms that ask for telephone numbers, & would like to be able to
key in the 10 digits without having to add any formating, i.e. entering
8576571234 would appear as (857) 657-1234. This is a feature that works
well in Excel, but I do not see a similar feature in Word 2003.