0
ODBC를 사용하여 HANA 데이터베이스에 연결하고 단추 클릭시 다음 시트의 테이블 데이터를 가져 오는 Excel 응용 프로그램이 있습니다. 아래 코드를 사용하여 데이터베이스에서 데이터를 가져옵니다. -데이터베이스 테이블에 중국어 문자가있는 경우 VBA 오류가 발생했습니다.
Function importRoutine(sheet As String, provider As String, databaseschema As String, server As String, app As String, row As Long, column As Long, commandText As String, displayname As String, errorFlag As Boolean) As Integer
Debug.Print commandText
Dim l As QueryTable
Dim rs As Object
Dim cnt As ADODB.Connection
Dim cmd As ADODB.Command
Dim iCols As Integer
Set cnt = New ADODB.Connection
Set cmd = New ADODB.Command
Set rcd = New ADODB.Recordset
Dim rangesheet As String
rangesheet = Sheets(sheet).Cells(row + 1, column).Address
Dim connectionsheet As String
connectionsheet = "Driver=" + provider + ";SERVERNODE=" + server + ";" + getAuthentication + "; CS=" + databaseschema + ""
cnt.ConnectionString = connectionsheet
cnt.Open
Set cmd.ActiveConnection = cnt
cmd.commandText = commandText
cmd.CommandType = adCmdText
rcd.Open commandText, cnt '', adOpenStatic
Set rs = CreateObject("ADODB.RECORDSET")
rs.ActiveConnection = cnt
rs.Open commandText, cnt
With Sheets(sheet).ListObjects.Add(SourceType:=3, Source:=rs, Destination:=Range(Sheets(sheet).Cells(row, column).Address)).QueryTable
'.commandText = commandText
'.CommandType = xlCmdSql
.RowNumbers = False
.FillAdjacentFormulas = False
.PreserveFormatting = True
.RefreshOnFileOpen = False
.BackgroundQuery = True
.RefreshStyle = xlInsertDeleteCell
.SavePassword = False
.SaveData = True
.AdjustColumnWidth = False
.RefreshPeriod = 0
.ListObject.Name = displayname
.PreserveColumnInfo = False
On Error Resume Next
.Refresh BackgroundQuery:=False
End With
Sheets(sheet).ListObjects(displayname).TableStyle = "TableStyleMedium10"
importRoutine = 0
Call deleteConnection
CloseRecordset:
rs.Close
Set rs = Nothing
CloseConnection:
cnt.Close
Set cnt = Nothing
On Error GoTo 0
End Function
테이블에 영문자가 포함되어 있으면 코드가 올바르게 작동합니다. 그러나 테이블에 일부 중국어 문자와 같은 특수 문자가 있으면 다음 시트에 데이터를 넣을 수없고 오류가 발생합니다.
VBA에 중국어 문자가 포함 된 데이터를 가져 오거나 볼 수없는 제한이 있습니까?
오류가 무엇입니까? 그리고 발생했을 때 어떤 코드가 강조되어 있습니까? – Winterknell