Lägg denna subben under LostFocus:
Formatera telefonnummer:
Private Sub Telefon_LostFocus()
Dim TTemp, TTemp1, TTemp2, TTemp3, TTemp4, MyPos As String
'Kollar om tel.nr redan finns angivet
If Len(Telefon.Text) > 0 Then
MyPos = InStr(1, Telefon.Text, "-")
If MyPos <> 0 Then
Exit Sub
Else
On Error Resume Next
TTemp = Telefon.Text
TTemp = Split(TTemp, " ")
TTemp(0) = TTemp(0) & "-"
Error.Clear
If Len(TTemp(1)) = 5 Then
TTemp1 = Mid(TTemp(1), 1, 3)
TTemp2 = Mid(TTemp(1), 4, 2)
strTTemp = TTemp(0) & TTemp1 & " " & TTemp2
ElseIf Len(TTemp(1)) = 6 Then
TTemp1 = Mid(TTemp(1), 1, 2)
TTemp2 = Mid(TTemp(1), 3, 2)
TTemp3 = Mid(TTemp(1), 5, 2)
strTTemp = TTemp(0) & TTemp1 & " " & TTemp2 & " " & TTemp3
ElseIf Len(TTemp(1)) = 7 Then
TTemp1 = Mid(TTemp(1), 1, 3)
TTemp2 = Mid(TTemp(1), 4, 2)
TTemp3 = Mid(TTemp(1), 6, 2)
strTTemp = TTemp(0) & TTemp1 & " " & TTemp2 & " " & TTemp3
End If
End If
End If
Telefon.Text = strTTemp
End Sub