Hello all,
Does anyone know how to open an internationally formatted CSV file using VBA? The CSV file uses the semicolon as the column separator and the comma as the decimal point.
I created a userform that enables a user to point to a data directory and open a series of files that are incrementally numbered such as: p1_001.csv, p1_002.csv and so on.
I can open the files manually in Excel 2003 if I change the international options to not use the Systems Separators, then open the file, and then turn the Systems Separators option back on. This opens the file with the correct format so that I can copy the data to another sheet and move on with the next file.
I tried to automate this process, but I can't get the file to open with the right settings, which causes the data to become jumbled. Here are two options that I tried in my userform code.
Note: fname and filepath are two declared string variables.
Does anyone know how to open an internationally formatted CSV file using VBA? The CSV file uses the semicolon as the column separator and the comma as the decimal point.
I created a userform that enables a user to point to a data directory and open a series of files that are incrementally numbered such as: p1_001.csv, p1_002.csv and so on.
I can open the files manually in Excel 2003 if I change the international options to not use the Systems Separators, then open the file, and then turn the Systems Separators option back on. This opens the file with the correct format so that I can copy the data to another sheet and move on with the next file.
I tried to automate this process, but I can't get the file to open with the right settings, which causes the data to become jumbled. Here are two options that I tried in my userform code.
Code:
'Option 1
ChDir filepath
With Application
.DecimalSeparator = ","
.ThousandsSeparator = ","
.UseSystemSeparators = False
End With
Application.Workbooks.Open fname
With Application
.DecimalSeparator = ","
.ThousandsSeparator = ","
.UseSystemSeparators = True
End With
'Option 2
Application.Workbooks.OpenText Filename:= _
fname, _
Origin:=437, StartRow:=1, DataType:=xlDelimited, TextQualifier:= _
xlDoubleQuote, ConsecutiveDelimiter:=True, Tab:=False, Semicolon:=True, _
Comma:=False, Space:=False, Other:=False, FieldInfo:=Array(Array(1, 1), _
Array(2, 1), Array(3, 1), Array(4, 1), Array(5, 1), Array(6, 1)), TrailingMinusNumbers _
:=False
Note: fname and filepath are two declared string variables.