How is it possible to import more trt file in one Excel worksheet ?
Dear Everybody,
How is it possible to import lots of trt file in one Excel worksheet?
Or where can someone convert lots of trt files to txt?
Please, help. It's urgent!
Thanks!
Lili
P.S. I'd like to use about 30 trt file in one worksheet (but in an old excel I have to import trt files singly).
And there are a lot of worksheet!
I can't programming and can't use Visual Basic, but in this homepage I found a code, which is not work/run for me good (but I set Tools-> References->Microsoft Scripting Runtime). It is Microsoft Excel 2000.
If someone solve this solution in OpenOffice it's good as well.
-----------------------------------------
Sub ImportDataFromTxtFiles()
Application.ScreenUpdating = False
Dim oFileDialog As FileDialog
Dim LoopFolderPath As String
Dim oFileSystem As FileSystemObject
Dim oLoopFolder As Folder
Dim oFilePath As File
Dim oFile As TextStream
Dim RowN As Long
Dim ColN As Long
On Error GoTo ERROR_HANDLER
Set oFileDialog = Application.FileDialog(msoFileDialogFolderPicker)
RowN = 1
With oFileDialog
With oFileDialog
If .Show Then
ActiveSheet.Columns(ColN).Cells.Clear
LoopFolderPath = .SelectedItems(1) & "\"
Set oFileSystem = CreateObject("Scripting.FileSystemObject")
Set oLoopFolder = oFileSystem.GetFolder(LoopFolderPath)
For Each oFilePath In oLoopFolder.Files
Set oFile = oFileSystem.OpenTextFile(oFilePath)
With oFile
Do Until .AtEndOfStream
ActiveSheet.Cells(RowN, ColN).Value = .ReadLine
RowN = RowN + 1
Loop
.Close
End With
Next oFilePath
End If
With oFileDialog
If .Show Then
ActiveSheet.Cells.Clear
LoopFolderPath = .SelectedItems(1) & "\"
Set oFileSystem = CreateObject("Scripting.FileSystemObject")
Set oLoopFolder = oFileSystem.GetFolder(LoopFolderPath)
For Each oFilePath In oLoopFolder.Files
Set oFile = oFileSystem.OpenTextFile(oFilePath)
With oFile
ColN = 3 ' To start from column C
Do Until .AtEndOfStream
ActiveSheet.Cells(RowN, ColN).Value = .ReadLine
ColN = ColN + 1
Loop
RowN = RowN + 1
.Close
End With
Next oFilePath
End If
End With
EXIT_SUB:
Set oFilePath = Nothing
Set oLoopFolder = Nothing
Set oFileSystem = Nothing
Set oFileDialog = Nothing
Application.ScreenUpdating = True
Exit Sub
ERROR_HANDLER:
' Some code for error handling
Err.Clear
GoTo EXIT_SUB
End Sub
--------------------------------------------------------------------
Thank you very much!
Recent comments
5 years 34 weeks ago
6 years 20 weeks ago
6 years 32 weeks ago
6 years 35 weeks ago
6 years 36 weeks ago
6 years 42 weeks ago
6 years 50 weeks ago
6 years 50 weeks ago
6 years 50 weeks ago
6 years 50 weeks ago