1

I need to import text files to Excel sheets. The text files come both from Macs and PCs and contain characters from various languages. For Excel 2004 (PC) I have successfully used vba code like below for converting Mac-coded text to PC-coding:

Worksheets("A").Cells.Clear
pth = Application.GetOpenFilename()
With Worksheets("A").QueryTables.Add(Connection:="TEXT;" & pth, _
 Destination:=Worksheets("A").Range("A1"))
    .TextFilePlatform = 10000
    .TextFileColumnDataTypes = Array(xlTextFormat)
    .Refresh
End With
Worksheets("A").QueryTables(1).Delete

I am trying to use similar code for Excel 2011 to convert the coding from PC to Mac, using

.TextFilePlatform = xlWindows '=2

as suggested by running the macro recorder. Doing the importing manually works perfectly, changing the coding from PC to Mac, but the vba program run in Excel 2011 does not change the coding at all. The TextFilePlatform parameter can (in my version of Excel 2011; different language versions might possibly differ here) be set to 1, 2, or 3 (any other integer from -1000000 to 1000000 gives error 5), and the resulting text looks exactly the same for these three cases. Is there some other setting that overrules my attempt to convert the text coding? Any suggestion greatly appreciated!

Edit: I have confirmed that the code with .TextFilePlatform = xlWindows properly translates windows coded text to mac coding for Excel 10 (2001) and for Excel 11 (2004), contrary to the case for Excel 2011 described above.

rolf
  • 51
  • 1
  • 6

2 Answers2

1

it is not possible to achieve this on a mac, the only solution is to run the script with windows and give the file back to mac

Sebastian Viereck
  • 5,455
  • 53
  • 53
0

Here is a nice online solution Zoho Sheet VBA

Yes, it works good with your Microsoft Excel VBA.

Hignesh Hirani
  • 1,049
  • 11
  • 16