Couldn't you just rename the *.csv to *.txt and use the wizard to parse your
data?
If you don't want to do that, maybe you could try changing your windows settings
(everyones!) to have the same list separator.
In Win98, I can change it via:
Windows start button
Settings|control Panel|Regional Settings Applet
Number Tab
(at the bottom)
List Separator
========
Another approach that I like is to record a macro when you do it once. Continue
recording while you add your formatting/headers/print setup/filters/everything.
But for this to work, you'll still have to rename the .csv to something else
(.txt). VBA just ignores parts of your code when it sees the .csv.
Then whenever you want to open a similar file, just replay your macro. It might
even make your life a bit easier.
You'll probably want to adjust the code a little to make it more generic. When
you recorded your macro, you got something that looked like:
Option Explicit
Sub Macro1()
Workbooks.OpenText Filename:="C:\myfile.txt", Origin:=437, StartRow:=1, _
DataType:=xlFixedWidth, FieldInfo:=Array(Array(0, 1), Array(15, 1), _
Array(41, 1))
End Sub
Well, instead of having your filename in the code, you can give the user a
chance to pick it themselves (take a look at getopenfilename in VBA's help):
Sub macro1A()
Dim myFileName As Variant
myFileName = Application.GetOpenFilename(filefilter:="Text Files, *.Txt", _
Title:="Pick a File")
If myFileName = False Then
MsgBox "Ok, try later" 'user hit cancel
Exit Sub
End If
Workbooks.OpenText Filename:=myFileName '....rest of recorded code here!
End Sub
Shiperton said:
Hmmm... not possible.
(We are half way through a major project and if we changed the
delimiter now the other office would have to change their
macros and also the data would then become inconsistent...!)
Also, what happens if users want to enter commas and/or semi-colons
in the source data? Are they expected to be "escaped" in some standard way?
I find this most strange. Excel and import a tab-delimited .txt file with
no fuss if you right click on it...!
Likewise a tab-delimited CSV *can* be imported, it's just
that it takes a load of steps.
Ship
Shiperton Henethe
csv files are expected to be delimited by comma or semi-colon depending on
geography. Why don't you ask that the person or system that provides the csv
files either makes them comma separated or gives the txt extension?
I am trying to import a tab-delimited CSV file into msExcel (2002)
just by right clicking on the file. Is this possible?!
Background.
I need to look at raw data coming in several times a day
and it is a pain in the a*** to have to go through the:
Data > Import external data > Import data > [find the file]
and then step through 'Text Import Wizard' etc...
each time I need to look at the data.
- Does anyone know if there is a way of configuring msExcel
to automatically import a .CSV in a *single step*?
[Currently, if I right-click on a .CSV file it imports it
incorrectly, failing to recognise columns etc and putting lots
of horrid little squares all over the place]
FWIW, Excel seems to be able to import tab-delimited
.TXT files no problem!
Ship
Shiperton Henethe