即効テクニック |
サンプルマクロは、ブックと同一フォルダ内にある3つのフィールドを持つCSVファイルの内容を正確にアクティヴシートに出力します。
Sub Sample() Dim myFileName As String Dim myFileNo As Integer Dim myBuf(1 To 3) As String Dim myRow As Long Dim myClm As Long myFileName = ThisWorkbook.Path & "\test.csv" myFileNo = FreeFile Open myFileName For Input As #myFileNo While EOF(myFileNo) = False myRow = myRow + 1 Input #myFileNo, myBuf(1), myBuf(2), myBuf(3) For myClm = 1 To 3 Cells(myRow, myClm).Value = myBuf(myClm) If Cells(myRow, myClm).Value <> myBuf(myClm) Then _ Cells(myRow, myClm).Value = "'" & myBuf(myClm) Next Wend Close #myFileNo End Sub