|
▼γ さま
お返事ありがとうございます。
所定のファイルの中にある文字"JAC"から始まる文字を見つけて
エクセルのセルE1に書き出す内容を作っております。
(所定のファイルは、C:\Tempに保存されているtxtファイルで名称は、日々更新されるものです。)
Sub Sample()
Dim PartsID As String
Dim i As Integer
For i = 6 To 6 'Cells(Rows.Count, 3).End(xlUp).Row
PartsID = Cells(i, 3)
PartsID = Left(PartsID, 11)
Debug.Print PartsID
Call FileSearch("C:\Temp", PartsID & "*.txt")
Next
End Sub
Sub FileSearch(Path As String, Target As String)
Dim FSO As Object, Folder As Variant, File As Variant
Dim strFILENAME As Variant
Dim info As String
Dim s As String
Dim a As String
Dim fNo As Integer
Set FSO = CreateObject("Scripting.FileSystemObject")
For Each Folder In FSO.GetFolder(Path).SubFolders
Call FileSearch(Folder.Path, Target)
Next Folder
For Each File In FSO.GetFolder(Path).Files
If File.Name Like Target Then
strFILENAME = File.Path
'++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
fNo = FreeFile
s = "JAC"
Debug.Print strFILENAME
Open strFILENAME For Input As #fNo
While Not EOF(1)
Line Input #1, a
If InStr(1, a, s) <> 0 Then
info = Mid(a, 1, InStr(1, a, s) + 30)
Debug.Print info
End If
Wend
Close #fNo
'++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
End If
Next File
End Sub
|
|