Código:
If KeyAscii = 10 Then Exit Sub ' tecla retroceso If Chr(KeyAscii) = vbCr Or Chr(KeyAscii) = vbTab Then ' tecla ENTER o TAB, antes de pasar el foco al siguiente control ' verificamos el número de caracteres If Len(txtCedula) <> 10 Then ' (letra + guión + 6 caracteres) KeyAscii = 0 Else SendKeys "{Tab}" End If Exit Sub End If If Len(txtCedula) = 0 Then ' 1er dígito, lo convertimos a mayúsculas KeyAscii = Asc(UCase(Chr(KeyAscii))) If KeyAscii > 64 And KeyAscii < 91 Then ' entre ese rango todas son mayusculas ' carácter correcto, le añadimos el guión y nos posicionamos al final txtCedula.Text = Chr(KeyAscii) & "-" txtCedula.SelStart = 3 End If ' eliminamos la pulsación de tecla KeyAscii = 0 ' si se ha eliminado el guión (con la tecla de retroceso) ' convertimos el carácter digitado en un guión ElseIf Len(txtCedula) = 1 Then KeyAscii = 45 Else ' sólo números If Not IsNumeric(Chr(KeyAscii)) Then KeyAscii = 0 End If