VB6 엑셀파일 읽고 쓰는 예제

Public objXcl As Excel.Application
Set objXcl = Excel.Application
objXcl.Workbooks.Add
objXcl.Sheets(1).Select

'Open csv file, then read
Do Until EOF(nFileNbr)
Input #nFileNbr, sTextField(0), sTextField(1), sTextField(2), sTextField(3)

With objXcl
Range("B1").Select
.Range("B1").Value = sTextField(0)
Range("B2").Select
.Range("B2").Value = sTextField(1)
Range("B3").Select
.Range("B3").Value = sTextField(2)
End With
Loop

    FileNum = FreeFile
    Open "e:\data\code\VBElw.csv" For Input As #FileNum
    Line Input #FileNum, nextLine
    ElwCode = Split(nextLine, vbLf)
    n5 = UBound(ElwCode)
    'Open "e:\data\code\VBElw.csv" For Input As #FileNum
    'i = 0
    'Do Until EOF(FileNum)
        'ReDim Preserve StockCode(i)
        'Line Input #FileNum, nextLine
        'LinesFromFile = LinesFromFile + nextLine + vbCr + vbLf
        'splitLine = Split(nextLine, ",")
        'elwCode(i) = splitLine(0)
        'ElwCode(i) = nextLine
        'i = i + 1
    'Loop
    
    FileNum = FreeFile
    Open "e:\data\code\VBStockFuture.csv" For Input As #FileNum
    Line Input #FileNum, nextLine
    StockFutureCode = Split(nextLine, vbLf)
    n6 = UBound(StockFutureCode)
    'Line Input #FileNum, LinesFromFile
    'splitLines = Split(LinesFromFile, ",")
'
    'sFilename = splitLines(0)
    'sFilename = splitLines(1)
    'sFilename = splitLines(2)
    'i = 0
    'Do Until splitLines(i) <> Null
    'splitLine = Split(splitLines(i), ",")
    'elwCode(i) = splitLine(0)
    'i = i + 1
    'Loop
    'Text1.Text = splitLine(0)

Leave a Reply

Your email address will not be published. Required fields are marked *

 characters available

+ 87 = 91