|
Sub Sumple()
'全データの1列目に挿入するデータの頭文字
Const MasterFlg As String = "cz"
'日付データと認識させる為の頭文字
Const DateFlg As String = "cd"
'詳細データとして認識させる為の頭文字
Const VluFlg As String = "cc"
Dim Buf()
Dim Cnt As Long, RCnt As Long
Dim TxtFile As String
Dim StrMAster As String, StrDate As String, StrData As String
Cnt = 0
RCnt = 1
TxtFile = Application.GetOpenFilename("*.txt,(*.txt)", , "読み込むテキストを選択", , False)
If TxtFile = "False" Then
MsgBox "ファイルを選択してから実行して下さい。"
Exit Sub
End If
Fil = FreeFile
Open TxtFile For Input As #Fil
Do Until EOF(Fil)
ReDim Preserve Buf(Cnt)
Input #Fil, Buf(Cnt)
Cnt = Cnt + 1
Loop
For Cnt = 0 To UBound(Buf)
If Buf(Cnt) Like MasterFlg & "*" Then
StrMAster = Mid(Buf(Cnt), Len(MasterFlg) + 1)
ElseIf Buf(Cnt) Like DateFlg & "*" Then
StrDate = Mid(Buf(Cnt), Len(DateFlg) + 1)
ElseIf Buf(Cnt) Like VluFlg & "*" Then
StrData = Mid(Buf(Cnt), Len(VluFlg) + 1)
With Range(Cells(RCnt, 1), Cells(RCnt, 3))
.NumberFormatLocal = "@"
.Value = Array(CStr(StrMAster), StrData, Format(StrDate, "YYYY/MM/DD"))
End With
RCnt = RCnt + 1
End If
Next
End Sub
|
|