lynxbci
Board Regular
- Joined
- Sep 22, 2004
- Messages
- 201
- Office Version
- 365
- Platform
- Windows
- MacOS
I have a ADODB connection that imports an xls file into my spreadsheet. However, one of the fields which has telephone numbers in format '+375894552698' is changing to characters that look like chinese. (cant paste images in here so hard to show it) something like 'ԫԬѫ∏' and i cannot work out why, as all i am doing is importing the file, as i have done hundreds of times.
Is there any way i can prevent this reformatting?
My is quite standard
Thanks, i know its a wild shot, but never come across before.
Kev
Is there any way i can prevent this reformatting?
My is quite standard
Code:
Sub GetManifest()
GetData ThisWorkbook.Path & "\Master - DATA.XLS", "Master - DATA", "C9:x1000", Sheets("The Data").Range("K2"), False, False
End Sub
Public Sub GetData(SourceFile As Variant, SourceSheet As String, SourceRange As String, TargetRange As Range, Header As Boolean, UseHeaderRow As Boolean)
Dim rsCon As Object
Dim rsData As Object
Dim szConnect As String
Dim szSQL As String
Dim lCount As Long
Workbooks.Open (ThisWorkbook.Path & "\Master - DATA.XLS")
' Create the connection string.
If Val(Application.Version) < 12 Then
szConnect = "Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=" & SourceFile & ";" & _
"Extended Properties=""Excel 8.0;HDR=Yes"";"
Else
szConnect = "Provider=Microsoft.ACE.OLEDB.12.0;" & _
"Data Source=" & SourceFile & ";" & _
"Extended Properties=""Excel 12.0;HDR=Yes"";"
End If
Application.Calculation = xlCalculationManual
Application.ScreenUpdating = False
Workbooks("NEW Manifest.xlsm").Activate
Sheets("The Data").Range("k2:af1000").Clear
szSQL = "SELECT * FROM [" & SourceSheet$ & "$" & SourceRange$ & "];"
On Error GoTo SomethingWrong
Set rsCon = CreateObject("ADODB.Connection")
Set rsData = CreateObject("ADODB.Recordset")
rsCon.Open szConnect
rsData.Open szSQL, rsCon, 0, 1, 1
' Check to make sure we received data and copy the data
If Not rsData.EOF Then
If Header = False Then
TargetRange.Cells(1, 1).CopyFromRecordset rsData
Else
'Add the header cell in each column if the last argument is True
If UseHeaderRow Then
For lCount = 0 To rsData.Fields.Count - 1
TargetRange.Cells(1, 1 + lCount).Value = _
rsData.Fields(lCount).Name
Next lCount
TargetRange.Cells(2, 1).CopyFromRecordset rsData
Else
TargetRange.Cells(1, 1).CopyFromRecordset rsData
End If
End If
Else
MsgBox "No records returned from : " & SourceFile, vbCritical
End If
' Clean up our Recordset object.
rsData.Close
Set rsData = Nothing
rsCon.Close
Set rsCon = Nothing
Workbooks("Master - DATA.XLS").Close savechanges = False
Application.Calculation = xlCalculationAutomatic
Application.ScreenUpdating = True
Exit Sub
SomethingWrong:
MsgBox "The file name, Sheet name or Range is invalid of : " & SourceFile, _
vbExclamation, "Error"
On Error GoTo 0
End Sub
Kev