Excelで以下のExcel VBAを実行すると、ファイルを見つけることができないというエラー53メッセージが表示されます。しかし、そのファイルには正確なファイル拡張子と名前があります。 これは、テキストファイルを見て、それをExcelの列に分割する必要があります。しかし、ファイルを見つけることができないというエラー53が表示されています。VBAエラー53ファイルが見つかりません
ご協力いただければ幸いです。私はたくさんのものを探してフォルダをループ終わると感謝
Sub SplitTxt_01()
Const HelperFile As String = "ABCD" '<<< temp. helper text file Name
Const N As Long = 500000 '<<< split each txt in N rows, CHANGE
Dim myPath
myPath = "C:\Desktop\" '<<< folder path, CHANGE'
Dim myFile
myFile = "2015226d.txt" '<<< your text file. CHANGE txt file name as needed
Dim WB As Workbook, myWB As Workbook
Set myWB = ThisWorkbook
Dim myWS As Worksheet
Dim t As Long, r As Long
Dim myStr
Application.ScreenUpdating = False
'split text file in separate text files
myFile = Dir(myPath & myFile)
Open myPath & myFile For Input As #1
t = 1
r = 1
Do While Not EOF(1)
Line Input #1, myStr
If r > N Then
t = t + 1
r = 1
End If
Open myPath & HelperFile & t & ".txt" For Append As #2
Print #2, myStr
Close #2
r = r + 1
Loop
Close #1
'copy txt files in separate sheets
For i = t To 1 Step -1
Workbooks.OpenText Filename:=myPath & HelperFile & i & ".txt", DataType:=xlDelimited, Tab:=True
Set WB = ActiveWorkbook
Set Rng = ActiveSheet.UsedRange
Set myWS = myWB.Sheets.Add
myWS.Name = HelperFile & i
Rng.Copy myWS.Cells(1, 1)
WB.Close False
Next
myWB.Save
'Delete helper txt files
Set Fso = CreateObject("Scripting.FileSystemObject")
Set Fldr = Fso.GetFolder(myPath)
For Each Filename In Fldr.Files
If Filename Like "*" & HelperFile & "*" Then Filename.Delete
Next
Application.ScreenUpdating = True
End Sub
もあなたはmyStrの設定を決してしません。 –