Postagens

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

Imagem
A função abaixo tem como objetivo buscar a distância entre duas cidades. No entrando, os comandos necessitam que a referência "Microsoft XML, v6.0" esteja ativada. Habilite a referencia acima e cole o código abaixo em um módulo VBA. Function Busca_Km(Origem As String, Destino As String) As Double     'Requer referência ao: 'Microsoft XML, v6.0'     Dim Solicitacao As XMLHTTP60     Dim Doc As DOMDocument60     Dim Distancia_Pontos As IXMLDOMNode     Let Busca_Km = 0     'Checa e limpa as entradas     On Error GoTo Sair     Let Origin = Replace(Origem, " ", "%20")     Let Destination = Replace(Destino, " ", "%20")     ' Le os dados XML da API do Google Maps.     Set Solicitacao = New XMLHTTP60     Solicitacao.Open "GET", "http://maps.googleapis.com/maps/api/directions/xml?origin=" _         & Origin & "&destination=" & Destino & "&sens

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

Máscara de Texto Para CEP Pelo Auto-Preenchimento

Private Sub txtCep_KeyPress(ByVal KeyAscii As MSForms.ReturnInteger) txtCep.MaxLength = 10 'Limita a Quantidade de Caracteres do capo CEP  Select Case KeyAscii       Case 8       'Aceita apagar o campo, ou seja, Back Space       Case 13: SendKeys "{TAB}"    'Emula o TAB       Case 48 To 57          If txtCep.SelStart = 2 Then txtCep.SelText = "."          If txtCep.SelStart = 6 Then txtCep.SelText = "-"       Case Else: KeyAscii = 0     'Ignora os outros caracteres    End Select End Sub

Máscara de Texto para CPF Pelo Auto-Preenchimento

Private Sub txtCpf_KeyPress(ByVal KeyAscii As MSForms.ReturnInteger) txtCpf.MaxLength = 14 'Limita a quantidade de caracteres do campo CPF.   Select Case KeyAscii       Case 8       'Aceita apagar o texto, ou seja, utilizar o Back Space       Case 13: SendKeys "{TAB}"    'Emula o TAB       Case 48 To 57          If txtCpf.SelStart = 3 Then txtCpf.SelText = "."          If txtCpf.SelStart = 7 Then txtCpf.SelText = "."          If txtCpf.SelStart = 11 Then txtCpf.SelText = "-"          Case Else: KeyAscii = 0     'Ignora os outros caracteres       End Select End Sub

Máscara de Texto Para CNPJ Pelo Auto-Preenchimento

Os comandos abaixo coloca a máscara de CNPJ pelo auto-preenchimento. Private Sub txtCnpj_KeyPress(ByVal KeyAscii As MSForms.ReturnInteger)    txtCnpj.MaxLength = 18  'Limita a Quantidade de Caracteres da caixa de texto CNPJ     Select Case KeyAscii         Case 8       'Aceita apagar o texto, ou seja, Back Space       Case 13: SendKeys "{TAB}"    'Emula o TAB       Case 48 To 57            If txtCnpj.SelStart = 2 Then txtCnpj.SelText = "."          If txtCnpj.SelStart = 6 Then txtCnpj.SelText = "."          If txtCnpj.SelStart = 10 Then txtCnpj.SelText = "/"          If txtCnpj.SelStart = 15 Then txtCnpj.SelText = "-"          Case Else: KeyAscii = 0     'Ignora os outros caracteres       End Select End Sub

Máscara de Texto Para Data Pelo Auto-Preenchimento

O Procedimento Abaixo coloca máscara de auto-preenchimento para campos (caixa de Texto) dos Formulários VBA. Private Sub txtData_KeyPress( ByVal KeyAscii As MSForms.ReturnInteger)     With txtData         .MaxLength = 10                                        'Limita a Quantidade de caracteres do campo.         Select Case KeyAscii             Case 8                                                     'Aceita o Back Space (Apagar Texto)             Case 13: SendKeys "{TAB}"                 'Emula o TAB             Case 48 To 57                                         'Aceita apenas números de 0 a 9                 If .SelStart = 2 Then .SelText = "/"    'Adiciona a primeira barra da data                 If .SelStart = 5 Then .SelText = "/"    'Adiciona a segunda barra da data             Case Else : KeyAscii = 0                        'Ignora outros Caracteres         End Select     End With End Sub

Função Excel Para Limpar Caracteres Especiais do Texto

Function SemAcentos(strTexto As String)         'Declaração de Variáveis     Dim strComAcentos As String     Dim strSemAcentos As String     Dim VarPosicao As Integer     Dim i As Integer         strComAcentos = "ÀÁÂÃÄÅÇÈÉÊËÌÍÎÏÒÓÔÕÖÙÚÛÜàáâãäåçèéêëìíîïòóôõöùúûü"     strSemAcentos = "AAAAAACEEEEIIIIOOOOOUUUUaaaaaaceeeeiiiiooooouuuu"         'Loop     For i = 1 To Len(strTexto)                 VarPosicao = InStr(strComAcentos, Mid(strTexto, i, 1))                 If VarPosicao > 0 Then                         strTexto = Replace(strTexto, Mid(strComAcentos, VarPosicao, 1), Mid(strSemAcentos, VarPosicao, 1))                 End If         Next SemAcentos = strTexto End Function