> I want to open a CSV file into an already open Sheet
> the same way Excel opens it as a new, complete Workbook.
Not sure I'm understanding what you mean here. Do you mean you want to
open a CSV file and move the contents into an already-open sheet?
The important point here is that Excel is opening a CSV FILE, and this
is done with the normal File/Open type of facility. I.e. it's a whole
file and will become a whole workbook.
I can't see that Excel would offer you any facilities to import a CSV
FILE into an EXISTING workbook.
However, you should be able to open the CSV file from VBA and then
select all the data in its sheet and copy that into an existing sheet,
using copy/paste-values if you want to preserve the formatting in the
existing sheet.
In fact, I imagine you can record a macro of yourself doing all of this
manually. It would require tailoring, but should have the basics of
what you need to do.
Regards, Dave S
________________________________
From: ExcelVBA@yahoogroups.com [mailto:ExcelVBA@yahoogroups.com] On
Behalf Of noskosteve
Sent: Wednesday, 6 June 2012 13:48
To: ExcelVBA@yahoogroups.com
Subject: [ExcelVBA] Opening a CSV file and populating cells just like
Excel does
I wanna' be just like my daddy...
I want to open a CSV file into an already open Sheet the same way Excel
opens it as a new, complete Workbook.
It is a simple CSV file with records (lines) that have either text or
numbers in the fields (with commas between, of course) and CR at the
end. There are no quotes around the strings (they aren't Write strings).
Typical records:
2,Anthem,442.525000,,5.000000,Tone,114.8,,,,,,,
3,Bank One,146.820000,-,0.600000,Tone,159.8,,,,,,,
As you see, there can even be blank fields, thus blank cells.
I already can and do open tab delimited files, but I use Input # and
normally get the individual fields into individual variables by manually
(code) parsing the resulting whole record (line) strings.
However, I want to open the file at the users command (a button push)
and have the values put into adjacent cells just the way it happens when
you open a CSV file using Excel's Open. [Recording this operation shows
that it simply opens another complete Workbook.]
Help says that Line Input # is for reading Print # lines.
and that
Input # is for reading Write # lines...
but that the fields are brought into individual variables.
I don't know if this can be done automatically, or if I must bite the
bullet and use code to parse the values and put them in cells.
I didn't know where to start looking.
I spoze' I could do a regular Open a CSV Workbook, copy to the desired
Sheet, then close the CSV Workbook, but it would seem since Excel does
it, VBA should be able to make that happen as well.
Ya' know ... something like "Application.OpenCSVFile = xlJustLikeExcel
Filename = "whatever" Destination=Sheet4"
(;-)
--
73, Steve
----------
Visit our website at http://www.ubs.com
This message contains confidential information and is intended only
for the individual named. If you are not the named addressee you
should not disseminate, distribute or copy this e-mail. Please
notify the sender immediately by e-mail if you have received this
e-mail by mistake and delete this e-mail from your system.
E-mails are not encrypted and cannot be guaranteed to be secure or
error-free as information could be intercepted, corrupted, lost,
destroyed, arrive late or incomplete, or contain viruses. The sender
therefore does not accept liability for any errors or omissions in the
contents of this message which arise as a result of e-mail transmission.
If verification is required please request a hard-copy version. This
message is provided for informational purposes and should not be
construed as a solicitation or offer to buy or sell any securities
or related financial instruments.
UBS reserves the right to retain all messages. Messages are protected
and accessed only in legally justified cases.
[Non-text portions of this message have been removed]
Be sure to check out TechTrax Ezine for many, free Excel VBA articles! Go here: http://www.mousetrax.com/techtrax to enter the ezine, then search the ARCHIVES for EXCEL VBA.
----------------------------------
Visit our ExcelVBA group home page for more info and support files:
http://groups.yahoo.com/group/ExcelVBA
----------------------------------
More free tutorials and resources available at:
http://www.mousetrax.com
----------------------------------
Tidak ada komentar:
Posting Komentar