SendKeys does not work with accented word in VBA - Excel

1

I'm developing a script in VBA, in Excel. This code will populate another program, using the data collected in the cells. But cells that contain a word that has accents are not working.

I'm using Application.SendKeys as in the following section to fill in the other program

Sub teste()
   '(...)
    For i=2 to ultimaLinha
        'parte que simula o clique no mouse
        Application.SendKeys (Plan2.Cells(i,"D").Value)
        'restante do código
    Next
    '(...)
End Sub

If this cell (i, "D") has a word that does not contain accentuation, everything goes very well. But if you have an accent, it is not "typed"

For example, if the cell is written 'José Mauricio', only Jos Mauricio And it needs to be sent exactly as it is contained in the cell, because the program will receive this information in a listbox and, because of the data validation the listbox she would not accept it if she was typed Jose Mauricio instead of Jose Mauricio , because it does not exist in the list

How do I get the accents to be sent?

    
asked by anonymous 06.01.2017 / 01:37

1 answer

0

I was able to solve the problem using only SendKeys (without Application. )

But for some reason, I had to add a wait time, before the line of code that contained it.

But SendKeys , despite typing accented words, as I was needing, it skips the characters that are parentheses " and " " .

As I know there will be no matching items in the list that receives the information, which have parentheses to their right and after that character, have some different data, I had to find the position of that special character and send only what contains up to the position just prior to it in the word

The final code looks like this:

Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)

Sub teste()

   '(...)

    For i = 2 To ultimaLinha

        'parte que simula o clique no mouse

        indice = InStr(1, Plan2.Cells(i, "D").Value, Chr(40)) 'procura por ( - Chr(40)
        indice2 = InStr(1, Plan2.Cells(i, "D").Value, Chr(34)) 'procura por " - (Chr(34)

        Sleep (500)

        palavra = ""

        If indice > 0 Then
            For j = 1 To (indice - 1)
                palavra = palavra & Mid(Plan2.Cells(i, "D").Value, j, 1)
            Next
            SendKeys (palavra)
        End If
        If indice2 > 0 Then
            For k = 1 To (indice2 - 1)
                palavra = palavra & Mid(Plan2.Cells(i, "D").Value, k, 1)
            Next
            SendKeys (palavra)
        End If
        If indice = 0 And indice2 = 0 Then
            SendKeys (Plan2.Cells(i, "D").Value)
        End If

        'restante do código

    Next

    '(...)

End Sub
    
07.01.2017 / 10:55