単純なコード。どうも 海馬にある[要素に反応する神経細胞]に電気が通らなくなっている ようだ。
で、記録に残すことに...
- Public Sub デイサービスCSV変換()
- Dim mbTitle As String
- Dim isEOF As Boolean
- Dim dsn As Long, ds2 As Long
- Dim outCounter As Long
- Dim txtFile As String, csvFile As String
- Dim txtData As String, str3 As String
- Dim strName As String, strYubin As String, strJusho As String, strTel As String
- mbTitle = "デイサービスCSV変換/" & ThisWorkbook.Name
- txtFile = ThisWorkbook.Path & "\デイサービス.txt"
- csvFile = ThisWorkbook.Path & "\デーサービス.csv"
- dsn = FreeFile
- Open txtFile For Input As #dsn
- ds2 = FreeFile
- Open csvFile For Output As #ds2
- Write #ds2, "名前", "郵便番号", "住所", "電話番号"
- outCounter = 0
- Do
- GoSub ReadTextFile
- If isEOF Then Exit Do
- str3 = Left(txtData, 3)
- Select Case str3
- Case "デイサ"
- strName = ""
- Case "住所:"
- txtData = Trim(Mid(txtData, 4))
- strYubin = Trim(Left(txtData, 8))
- strJusho = Trim(Mid(txtData, 9))
- Case "電話:"
- strTel = Trim(Mid(txtData, 4))
- Case "運営事"
- If strName <> "" Then
- Write #ds2, strName, strYubin, strJusho, strTel
- outCounter = outCounter + 1
- strName = ""
- End If
- Case Else
- strName = strName & txtData
- End Select
- Loop
- Close dsn, ds2
- MsgBox outCounter & " 件の CSVファイル を作成しました。" _
- , vbInformation, mbTitle
- Application.Quit
- ThisWorkbook.Close
- Exit_デイサービス変換:
- Exit Sub
- ReadTextFile:
- isEOF = False
- Do
- If EOF(dsn) Then isEOF = True: Return
- Line Input #dsn, txtData
- If Not (txtData = "" Or txtData = ".") Then Return
- Loop
- End Sub
GoSub を使っており格好悪いが、使い捨てなので...