ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Multifile Code Error (https://www.excelbanter.com/excel-programming/276103-re-multifile-code-error.html)

Dick Kusleika

Multifile Code Error
 
MJ

It's hard to say. Record a macro while opening a file manually and compare
the arguments you get in the recorded macro to the arguments you have here.
Any differences may be the source of the problem.

--
Dick Kusleika
MVP - Excel
www.dicks-clicks.com
Post all replies to the newsgroup.

"mjwilliams" wrote in message
m...
Could someone please tell me why I'm getting the RT error 1004,
"Method 'OpenText' of object 'Workbooks' failed" when I run this
code?

Sub MultiFile()
With Application.FileSearch
.NewSearch
.LookIn = "M:\results"
.SearchSubFolders = False
.FileType = msoFileTypeAllFiles
If .Execute() 0 Then
For i = 1 To .FoundFiles.Count
Workbooks.OpenText Filename:=.FoundFiles(i),
Origin:=437, StartRow:=6, DataType:=xlDelimited,
TextQualifier:=xlDoubleQuote, ConsecutiveDelimiter:=True, Tab:=True,
Semicolon:=False, _
Comma:=False, Space:=True, Other:=False,
FieldInfo:=Array(Array(1, 1), _
Array(2, 1), Array(3, 1), Array(4, 1), Array(5, 1),
Array(6, 1), Array(7, 1), Array(8, 1), _
Array(9, 1), Array(10, 1)) 'TrailingMinusNumbers:=True
ActiveWorkbook.SaveAs FileFormat:=xlNormal
Range("O30").Select
ActiveWorkbook.Close SaveChanges:=False
Next i
Else
MsgBox "There were no files found."
End If
End With
End Sub


Thank you very much in advance!!
MJ





All times are GMT +1. The time now is 07:00 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com