Sendkeys does not work with accented word in VBA - Excel

Asked

Viewed 852 times

0

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 some word that has accents, are not working.

I am using the Application.SendKeys as, in the section below, to fill 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 in this cell (i,"D") there is a word that does not contain accentuation, everything will be fine. But if it has accent, it is not "typed"

For example: if the cell is written 'José Mauricio', it will be typed 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 validation of data listbox has, she wouldn’t accept it if it was typed Jose Mauricio in place of José Mauricio, because it doesn’t exist on the list

How would I get the seats sent?

1 answer

0

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

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

But the SendKeys, despite writing the words with accentuation, as I was needing, it skips the characters that are parentheses "(" and ")".

Since I know that there will not be, in this list that receives the information, equal items, that have parentheses to the right and after this character, have any different data, I had to locate the position of this special character and send only what it contains to the position immediately preceding it, in the word

The final code went 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

Browser other questions tagged

You are not signed in. Login or sign up in order to post.