+ Reply to Thread
Results 1 to 15 of 15

can't import special characters

  1. #1
    Valued Forum Contributor
    Join Date
    02-21-2010
    Location
    Tokyo, Japan
    MS-Off Ver
    Excel 2007
    Posts
    502

    can't import special characters

    I wrote a program that imports selected data from one or several csv file(s). The program opens the first csv file and then according to some characteristics copies selected data to a newly created workbook. Subsequently the remaing csv files are opened and desired data is copied to the new workbook.

    This program does its job well except that special characters are converted to japanese characters. The same problem occurs if I just open the csv file in Excel. However, if I instead of opening the csv file import it using "Data-from text" and specify File origin as Unicode UTF-8 then the special characters are not converted to japanese characters.

    What I would like to do now is to modify the below loop so that the special characters are preserved. I don't know if this can be done by just modifying the below loop which is based on opening the csv file(s) or whether the loop needs to be completely rewritten and based on importing the csv data in UTF-8.

    Yet another solution would be to change the default file opening format. On US or European Excel installations csv file special characters are not converted to japanese characters. I looked but cannot find any setting that would do the trick.

    I need some help either reprogramming the below sub routine or changing the Excel setting.

    Please Login or Register  to view this content.

  2. #2
    Forum Expert OnErrorGoto0's Avatar
    Join Date
    12-30-2011
    Location
    I DO NOT POST HERE ANYMORE
    MS-Off Ver
    I DO NOT POST HERE ANYMORE
    Posts
    1,655

    Re: can't import special characters

    Have you tried using Workbooks.OpenText instead of Open? The second argument is Origin and if you specify 65001 for that argument it should use UTF-8.
    Good luck.

  3. #3
    Valued Forum Contributor
    Join Date
    02-21-2010
    Location
    Tokyo, Japan
    MS-Off Ver
    Excel 2007
    Posts
    502

    Re: can't import special characters

    no, I have not tried Workbooks.OpenText but I understand what you are saying. Please give me a short example script so that I get an idea about what I need to change.

    I assume I need to change the following line:

    Please Login or Register  to view this content.
    However, I am not sure how exactly the Workbooks.OpenText script has to be written.

  4. #4
    Forum Expert OnErrorGoto0's Avatar
    Join Date
    12-30-2011
    Location
    I DO NOT POST HERE ANYMORE
    MS-Off Ver
    I DO NOT POST HERE ANYMORE
    Posts
    1,655

    Re: can't import special characters

    As an example

    Please Login or Register  to view this content.

  5. #5
    Valued Forum Contributor
    Join Date
    02-21-2010
    Location
    Tokyo, Japan
    MS-Off Ver
    Excel 2007
    Posts
    502

    Re: can't import special characters

    I reduced my script to the following:

    Please Login or Register  to view this content.
    I compared the import using the above script with the Data-FromText import method.
    Script: PKCζ-interacting
    Data-FromText PKCζ-interacting

    Data-FromText is correct. Script still gives the wrong result.

  6. #6
    Forum Expert OnErrorGoto0's Avatar
    Join Date
    12-30-2011
    Location
    I DO NOT POST HERE ANYMORE
    MS-Off Ver
    I DO NOT POST HERE ANYMORE
    Posts
    1,655

    Re: can't import special characters

    A bit more research (since I had no files to test with) indicates that Excel and UTF8 do not always play well together - see this post on MrExcel for example. Can you use querytables instead of opening the file?

  7. #7
    Valued Forum Contributor
    Join Date
    02-21-2010
    Location
    Tokyo, Japan
    MS-Off Ver
    Excel 2007
    Posts
    502

    Re: can't import special characters

    Yes, I know about the Excel problems with csv files and UTF8. There seems to be no easy solution.
    I have never used querytables.

  8. #8
    Forum Expert OnErrorGoto0's Avatar
    Join Date
    12-30-2011
    Location
    I DO NOT POST HERE ANYMORE
    MS-Off Ver
    I DO NOT POST HERE ANYMORE
    Posts
    1,655

    Re: can't import special characters

    The querytable is basically what the Data-Import from Text file option creates. Would that work for your needs? If so, you could simply create a new workbook, add querytables to extract the csv data you want and then copy and paste that. It might also be possible to use ADO to extract the data you are interested in from the csv files without opening it, but I cannot say whether that would suffer from the UTF8 problem or not.

  9. #9
    Valued Forum Contributor
    Join Date
    02-21-2010
    Location
    Tokyo, Japan
    MS-Off Ver
    Excel 2007
    Posts
    502

    Re: can't import special characters

    If I use the macro recorder and do a Data-FromText import then I get a QueryTable script. I am trying to fit this script into my macro. As always the problem lies in the detail. Do you know how I have to adjust the Connection in the first line of the querytable script and .Name

    Please Login or Register  to view this content.

  10. #10
    Forum Expert OnErrorGoto0's Avatar
    Join Date
    12-30-2011
    Location
    I DO NOT POST HERE ANYMORE
    MS-Off Ver
    I DO NOT POST HERE ANYMORE
    Posts
    1,655

    Re: can't import special characters

    The connection would be
    Please Login or Register  to view this content.
    The name is not really important.

  11. #11
    Forum Expert snb's Avatar
    Join Date
    05-09-2010
    Location
    VBA
    MS-Off Ver
    Redhat
    Posts
    5,649

    Re: can't import special characters

    You'd better not add x querytables into the same destination A1.

    Just make 1 and change it's connection in VBA for every file.
    After refreshing the querytable you can copy the result to another sheet or location in the same sheet so the result of the querytable won't be written over time and again.



  12. #12
    Valued Forum Contributor
    Join Date
    02-21-2010
    Location
    Tokyo, Japan
    MS-Off Ver
    Excel 2007
    Posts
    502

    Re: can't import special characters

    this is working. Thank you very much. I consider the problem solved.

  13. #13
    Valued Forum Contributor
    Join Date
    02-21-2010
    Location
    Tokyo, Japan
    MS-Off Ver
    Excel 2007
    Posts
    502

    Re: can't import special characters

    Yes, you are right. I am aware of this issue. I am working on it. I should be OK.

  14. #14
    Forum Expert snb's Avatar
    Join Date
    05-09-2010
    Location
    VBA
    MS-Off Ver
    Redhat
    Posts
    5,649

    Re: can't import special characters

    You could use:

    Please Login or Register  to view this content.
    Last edited by snb; 01-17-2012 at 05:27 AM.

  15. #15
    Valued Forum Contributor
    Join Date
    02-21-2010
    Location
    Tokyo, Japan
    MS-Off Ver
    Excel 2007
    Posts
    502

    Re: can't import special characters

    thanks for the hint. I will keep it in mind. I'll have to see whether it is better to build in your script into mine or whether it is just better to slidly modify what I got.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1