Hi
I am trying to open all the files with a known extension (.prt This are normal txt file) in a specific folder.
I have searched the web site but was unsuccessful in finding what I am looking for. The BV code i have got is the following
-------------------
Sub OpenReportFile()
Dim fs, f, fc, ReportFile
Dim FileLocation As String
FileLocation = "J:\users\reportfile\"
Set fs = CreateObject("Scripting.FileSystemsObject")
Set f = fs.GetFolder(folderspec)
Set fc = f.Files
For Each ReportFile In fc
If Right(ReportFile.Name, 4) = ".prt" Then
Workbooks.OpenText Filename:=FileLocation&ReportFile.Name, _
Origin:=xlWindows, _
StartRow:=1, _
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))
End If
Next
End Sub
The macro crashes out with "ActivX component can't create object". It's something to do with SET fs!
Any ideas?
Thanks
Regards
JB
I am trying to open all the files with a known extension (.prt This are normal txt file) in a specific folder.
I have searched the web site but was unsuccessful in finding what I am looking for. The BV code i have got is the following
-------------------
Sub OpenReportFile()
Dim fs, f, fc, ReportFile
Dim FileLocation As String
FileLocation = "J:\users\reportfile\"
Set fs = CreateObject("Scripting.FileSystemsObject")
Set f = fs.GetFolder(folderspec)
Set fc = f.Files
For Each ReportFile In fc
If Right(ReportFile.Name, 4) = ".prt" Then
Workbooks.OpenText Filename:=FileLocation&ReportFile.Name, _
Origin:=xlWindows, _
StartRow:=1, _
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))
End If
Next
End Sub
The macro crashes out with "ActivX component can't create object". It's something to do with SET fs!
Any ideas?
Thanks
Regards
JB