4月 7th, 2008at 19:04

Tags: ,

ファイル読み込みVBA

このエントリーをはてなブックマークに追加

例ではCSVファイルを1行ずつ読み込み、Excelのシートに挿入していく。
データは「”」で囲われているため、ダブルクォーテーション削除処理が必要になる。

ソース

Dim RowDim ImportFileOpen ImportFile For Input As #1Row = 11

'読み込むDo While Not EOF(1)

 '1行読込 Line Input #1, LineStr

 LineArray = Split(LineStr, ",")

 'タイトル ActiveWorkbook.Sheets(1).Cells(Row, 1).Value = "・" & ダブルクォーテーション削除(LineArray(4)) '開始予定日?終了予定日 ActiveWorkbook.Sheets(1).Cells(Row, 2).Value = Format(LineArray(6), "mm/dd") & "?" & Format(LineArray(7), "mm/dd") '開始日?終了日 ActiveWorkbook.Sheets(1).Cells(Row, 3).Value = Format(LineArray(8), "mm/dd") & "?" & Format(LineArray(9), "mm/dd")

 Row = Row + 1

Loop

Close #1
このエントリーをはてなブックマークに追加