|
カンマが複数の場合、この方が善いかも?
Private Sub CSVRead(ByVal strFileName As String, _
ByRef rngWrite As Range, _
Optional ByRef lngRow As Long = 1, _
Optional strDelim As String = ",")
Dim i As Long '☆追加
Dim dfn As Integer
Dim vntField As Variant
Dim strBuff As String
Dim blnMulti As Boolean
Dim strREC As String
'ファイルをOpen
dfn = FreeFile
Open strFileName For Input As dfn
Do Until EOF(dfn)
'1行読み込み
Line Input #dfn, strBuff
'論理レコードに物理レコードを追加
strREC = strREC & strBuff
'"="を""に置き換え
strREC = Replace(strREC, "=", "") '☆追加
'論理レコードをフィールドに分割
vntField = SplitCsv(strREC, strDelim, , , blnMulti)
'フィールド内で改行が有る場合
If Not blnMulti Then
'★
For i = 0 To UBound(vntField) '☆追加
'各Fieldで先頭に"="が必要なら
' vntField(i) = "=" & vntField(i) '☆追加
'","を"。"に変換する場合
vntField(i) = Replace(vntField(i), ",", "。") '☆追加
Next i '☆追加
With rngWrite.Offset(lngRow)
With .Resize(, UBound(vntField) + 1)
'出力範囲を文字列に設定
.NumberFormat = "@"
'データを出力
.Value = vntField
End With
End With
'出力行をインクリメント
lngRow = lngRow + 1
strREC = ""
Else
'セル内改行として残す場合
strREC = strREC & vbLf
End If
Loop
Close #dfn
End Sub
|
|