Página 1 de 1

Código VBA CPF/CNPJ

Enviado: 28 Jul 2018 às 11:38
por SandroLima
Bom dia, amigos forumeiros.

Poderiam me ajudar com a alteração dessa SUB para aceitar a formatação de CNPJ além de somente CPF?

(###.###.###-## e ##.###.###/####.##)
Código: Selecionar todos
Private Sub txt_CPF_KeyPress(ByVal KeyAscii As MSForms.ReturnInteger)
    
        txt_CPF.MaxLength = 14
    
    Select Case KeyAscii
        Case 8, 48 To 57
            If Len(txt_CPF) = 3 Or Len(txt_CPF) = 12 Then
                txt_CPF.Text = txt_CPF & "."
                SendKeys "{End}", False
                
            ElseIf Len(txt_CPF) = 7 Then
                txt_CPF.Text = txt_CPF.Text & "."
                
            ElseIf Len(txt_CPF) = 11 Then
                txt_CPF.Text = txt_CPF.Text & "-"
                SendKeys "{End}", False
            End If
            
        Case Else
            KeyAscii = 0
    End Select
End Sub

Re: Código VBA CPF/CNPJ

Enviado: 29 Jul 2018 às 12:13
por Reinaldo