| 
    
     |  | こんにちは。かみちゃん です。 
 >これらを実現するには、どうプログラムを修正すればよろしいでしょうか?
 >具体的にプログラムを書きなおしていただけると有り難いです。
 
 提示されたコードをできるだけ活かして書きなおすと以下のような感じでできると思います。
 
 Option Explicit
 
 Public Const adTypeText = 2
 Public Const adReadLine = -2
 Public Const adReadAll = -1
 Public Const CONST_CHARSET = "iso-2022-jp"
 Public Const CONST_MAIL_FOLDER_NAME = "eml"
 Public Const DivideChar = ":"
 Public Const HeaderLine = 1
 
 Sub Sample1()
 
 Dim ts As Object  ''テキストストリーム
 Dim lngTextLineNumber As Long, lngCellLineNumber As Long
 Dim ファイルパス As String, TextContents As String, LineContents() As String
 Dim DivideCharPosition As Long
 Dim FSO As Object
 Dim TextFile As Object
 Dim File As Object
 Dim FolderPosition As String
 
 Dim ss1 As String, ss2 As String, ss3 As String
 Dim lngCellColumnNumber As Long
 
 Set FSO = CreateObject("Scripting.FileSystemObject")
 
 lngCellLineNumber = HeaderLine
 
 FolderPosition = ThisWorkbook.Path & "\" & CONST_MAIL_FOLDER_NAME
 
 For Each File In FSO.GetFolder(FolderPosition).Files
 
 'ファイルをオープンする。(読み取り専用)
 Set ts = CreateObject("ADODB.Stream")
 'オブジェクトに保存するデータの種類を文字列型に指定する
 ts.Type = adTypeText
 '文字列型のオブジェクトの文字コードを指定する
 ts.Charset = CONST_CHARSET
 'オブジェクトのインスタンスを作成
 ts.Open
 'ファイルからデータを読み込む
 ts.LoadFromFile (File.Path)
 
 TextContents = ts.ReadText(adReadAll)
 LineContents = Split(TextContents, vbCrLf)
 
 lngCellLineNumber = lngCellLineNumber + 1
 
 ss1 = "": ss2 = "": ss3 = ""
 For lngTextLineNumber = 0 To UBound(LineContents)
 DivideCharPosition = InStr(LineContents(lngTextLineNumber), DivideChar)
 If ss2 <> "" Or DivideCharPosition <> 0 Then
 If DivideCharPosition <> 0 Then
 ss1 = Left(LineContents(lngTextLineNumber), DivideCharPosition - 1)
 Select Case ss1
 Case "お名前", "年月日", "店員名", "店の雰囲気", "店のサービス", "状況1", "状況2", "その他ご意見"
 ss2 = ss1
 End Select
 Select Case ss2
 Case "お名前"
 lngCellColumnNumber = 1
 Case "年月日"
 lngCellColumnNumber = 3
 Case "店員名"
 lngCellColumnNumber = 5
 Case "店の雰囲気"
 lngCellColumnNumber = 6
 Case "店のサービス"
 lngCellColumnNumber = 8
 Case "状況1"
 lngCellColumnNumber = 10
 Case "状況2"
 lngCellColumnNumber = 11
 Case "その他ご意見"
 lngCellColumnNumber = 12
 End Select
 End If
 If ss2 <> "" Then
 With Cells(lngCellLineNumber, lngCellColumnNumber)
 ss3 = Mid(LineContents(lngTextLineNumber), DivideCharPosition + 1)
 If ss2 = "年月日" Then
 ss3 = Replace(ss3, " ", "")
 ss3 = Mid(ss3, 1, InStr(ss3, "日"))
 Else
 ss3 = .Value & ss3
 End If
 .Value = ss3
 End With
 End If
 
 End If
 
 Next lngTextLineNumber
 
 ts.Close
 Set ts = Nothing
 
 Next File
 
 Set FSO = Nothing
 
 End Sub
 
 
 |  |