Tenho uma macro que conecta ao mysql e executa uma query que esta em arquivo de texto e adiciona os registros em uma planilha de excel. Ocorre que o texto vem desconfigurado. Exemplo: Correto: QTDE DE CHAMADAS REALIZADAS (VISÃO CPF) Como vem: QTDE DE CHAMADAS REALIZADAS (VISÃO CPF)
Como configuro e onde para que a query me traga os resultados sem os problemas com texto?
Procedure de conexão:
Sub Conexao(SQL)
On Error GoTo Error
Set myCon = New ADODB.Connection
myCon.ConnectionString = _
"driver={mysql odbc 5.2 Unicode Driver};" & _
"server=172.17.0.140;database=DWH_RBZ;uid=usuario;pwd=senha;Option=3;"
myCon.CursorLocation = adUseClient
myCon.Open
With myCmd
Set .ActiveConnection = myCon
.CommandType = adCmdText
.CommandText = SQL
End With
With myRS
.LockType = adLockPessimistic
.CursorType = adOpenKeyset
.CursorLocation = adUseClient
.Open myCmd
End With
Exit Sub
Error:
MsgBox Err.Number & vbCrLf & Err.Description, vbExclamation, "ERRO DE CONEXAO COM O BANCO"
End Sub
Procedimento que cola os dados da query na planilha
Sub Roda_Query_1()
Dim SQL As String
Dim dias As Integer
dias = CDate(Dt_Final) - CDate(Dt_Incio)
For i = 0 To dias
SQL = LinhaALinhaLer
SQL = Mid(SQL, 4, 1000000)
SQL = Replace(SQL, "(@inicio)", "('" & Format(Dt_Incio, "yyyy-mm-dd") & " 00:00:00')")
SQL = Replace(SQL, "(@fim)", "('" & Format(Dt_Final, "yyyy-mm-dd") & " 23:59:59')")
Conexao (SQL)
If myRS.RecordCount = 0 Then
MsgBox ("Erro na consulta do relatório")
myRS.Close
myCon.Close
Exit Sub
End If
If VerificaExistePlan("Produtividade") = False Then
Call Cria_Plan_Dados
End If
Sheets("Dados").Range("A2").CopyFromRecordset myRS
Next i
myRS.Close
myCon.Close
End Sub