Open CSV file

S

Striker

I need to open a CSV file in Excel 2000, find the end of the file and select
that range and copy it to spreadsheet "B" starting at A2. I am using the
following to open the file. How can I find the end of the range of a CSV
file, then copy that range to an excel sheet.

Thanks


sfile1 = Application.GetOpenFilename("Text Files (*.csv), *.txt")
If sfile1 <> "" Then
Open sfile1 For Input As 1
End If
 
D

Dave Peterson

I would just open it as a workbook and then copy the used range

dim sFile1 as variant
dim destCell as range
dim wkbkCSV as workbook
sfile1 = Application.GetOpenFilename("CSV Files, *.csv")
if sfile1 = false then
exit sub
end if

set destcell = workbooks("b.xls").worksheets("somenameHere").range("A2")

set wkbkcsv = Workbooks.Open(Filename:=sfile1)

wkbkcsv.worksheets(1).usedrange.copy _
destination:=destcell

wkbkcsv.close savechanges:=false

======
Uncompiled, untested--watch for typos!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top