Máscara de Texto para Telefone - Auto-Preenchimento

Os comando abaixo é utilizado para colocar a Máscara de Texto para número de telefones.

Private Sub txtTelefone_KeyPress(ByVal KeyAscii As MSForms.ReturnInteger)

txtTelefone.MaxLength = 13 'Limita a quantidade de caracteres no campo TxtTelefone

 Select Case KeyAscii
      Case 8       'Aceita  Apara o Texto (Back Space)
      Case 13: SendKeys "{TAB}"    'Emula o TAB
      Case 48 To 57
         If txtTelefone.SelStart = 0 Then txtTelefone.SelText = "("
         If txtTelefone.SelStart = 3 Then txtTelefone.SelText = ")"
         If txtTelefone.SelStart = 8 Then txtTelefone.SelText = "-"
      Case Else: KeyAscii = 0     'Ignora os outros caracteres
   End Select

End Sub

Comentários

Postagens mais visitadas deste blog

Função VBA - Validador de CNPJ

Autocorreção no Excel - Eu Escrevo e o Excel Corrige.

Função VBA - Busca Distância Entre Cidades