Este fórum está sendo desativado

Depois de 9 anos, este fórum será desativado. Mas calma.... estamos migrando para uma comunidade no DISCORD. Junte-se a nós.

ENTRAR PARA DISCORD

Tópicos relacionados a códigos VBA, gravação de macros, etc.
  • Avatar do usuário
Por eloirfabio
Posts
#52887
Olá.
Estou tentando fazer uma máscara para PIS, no formato 000.00000.00-0, adaptando de uma máscara de CPF, porém, o traço não está saindo no final, somente pontos. Não sei muito bem onde está o erro. Caso alguém possa ajudar, ficarei agradecido.
Segue o código abaixo:
Código: Selecionar todos
Private Sub txtPIS_KeyPress(ByVal KeyAscii As MSForms.ReturnInteger)
    'Limita a Qde de caracteres
    txtPIS.MaxLength = 14
 
     Select Case KeyAscii
        Case 8, 48 To 57 ' BackSpace e numericos
          If Len(txtPIS) = 3 Or Len(txtPIS) = 12 Then
            txtPIS.Text = txtPIS.Text & "."
            SendKeys "{End}", False
 
        ElseIf Len(txtPIS) = 9 Then
            txtPIS.Text = txtPIS.Text & "."
 
        ElseIf Len(txtPIS) = 3 Then
            txtPIS.Text = txtPIS.Text & "-"
            SendKeys "{End}", False
          End If
 
        Case Else ' o resto é travado
            KeyAscii = 0
      End Select
End Sub
Avatar do usuário
Por fcarlosc2018
Posts Avatar
#52906
Bom dia

Tente assim:
Código: Selecionar todos
Private Sub txtPIS_KeyPress(ByVal KeyAscii As MSForms.ReturnInteger)
    ''Limita a Qde de caracteres
    txtPIS.MaxLength = 14
 
     Select Case KeyAscii
        Case 8, 48 To 57 ' BackSpace e numericos
          If Len(txtPIS) = 3 Or Len(txtPIS) = 13 Then
            txtPIS.Text = txtPIS.Text & "."
            SendKeys "{End}", False
 
        ElseIf Len(txtPIS) = 9 Then
            txtPIS.Text = txtPIS.Text & "."
 
        ElseIf Len(txtPIS) = 12 Then
            txtPIS.Text = txtPIS.Text & "-"
            SendKeys "{End}", False
          End If
 
        Case Else ' o resto é travado
            KeyAscii = 0
      End Select
End Sub

Att,
Francisco
long long title how many chars? lets see 123 ok more? yes 60

We have created lots of YouTube videos just so you can achieve [...]

Another post test yes yes yes or no, maybe ni? :-/

The best flat phpBB theme around. Period. Fine craftmanship and [...]

Do you need a super MOD? Well here it is. chew on this

All you need is right here. Content tag, SEO, listing, Pizza and spaghetti [...]

Lasagna on me this time ok? I got plenty of cash

this should be fantastic. but what about links,images, bbcodes etc etc? [...]

Estamos migrando para uma comunidade no Discord