ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Reading .csv file into array (https://www.excelbanter.com/excel-programming/283627-reading-csv-file-into-array.html)

mousetrap

Reading .csv file into array
 
Hi,

I have a "comma separated values" file and I need to read it and load it
into an array using VBA. I cannot use any excel specific functions. How
do I do that? Actually, the file is generated from excel; I need to read
the file using VBA from a graphic program like CorelDraw or
AdobeIllustrator.

Thanks.

---------
MouseTrap

Jan Karel Pieterse

Reading .csv file into array
 
Hi Mousetrap,

I have a "comma separated values" file and I need to read it and load it
into an array using VBA.


This code reads a file line-by-line. You can then separate out the
individual entries using the split function.

Sub test()
Dim sFile As String
Dim sArray() As String
Dim lCount As Long
sFile = "c:\data\book1.csv"
ReDim sArray(1)
Open sFile For Input As #1
Do
lCount = lCount + 1
ReDim Preserve sArray(lCount)
Line Input #1, sArray(lCount)
'place code here to split the read line into individual elements
Loop Until EOF(1)
Close #1
End Sub


Regards,

Jan Karel Pieterse
Excel MVP
www.jkp-ads.com



All times are GMT +1. The time now is 01:23 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com