LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Open multiple text files and paste contents to single cell

Thanks to the contributions of others in this group I have a macro
which will open multiple text files (rtf to be precise) and copy them
into a single spreadsheet. However, the text files range in length and
when they are pasted into the sheet, they may range from 1 row to 50.

Since my ultimate goal is to use this file to import into an Oracle
database, I need to have the entire contents of each text file in a
single cell and then have the name of the file in the next column.

The macro I am using is the following:

Sub ImportText()
Dim fileRow As Integer
Dim pathname As String
Dim j As Integer, i As Integer, filenameLen As Integer


Application.DisplayAlerts = False
Application.ScreenUpdating = False


filetoOpen = Application.GetOpenFilename _
("Select Letter Files (*.rtf),*.txt", , , , True)


If IsEmpty(Range("A1")) Then
fileRow = 1
Else
fileRow = ActiveSheet.UsedRange.Rows( _
ActiveSheet.UsedRange.Rows.Count).Row + 1
End If


For i = 1 To UBound(filetoOpen, 1)
Workbooks.OpenText Filename:=filetoOpen(i), _
Origin:=xlWindows, StartRow:=1, _
DataType:=xlDelimited, TextQualifier:=xlDoubleQuote, _
ConsecutiveDelimiter:=False, Tab:=False, _
Semicolon:=False, Comma:=False, _
Space:=False, Other:=False


Debug.Print ActiveWorkbook.Name


Set newBook = ActiveWorkbook 'reference to textfile


ActiveSheet.UsedRange.Copy
With Workbooks("Import Letter
Templates.xls").Worksheets("Sheet1")
ActiveSheet.Paste Destination:=.Cells(fileRow, 1)
fileRow = .UsedRange.Rows( _
.UsedRange.Rows.Count).Row + 1
End With
Debug.Print fileRow
newBook.Close


Next i
Application.DisplayAlerts = True
Application.ScreenUpdating = True
End Sub

 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Cut and Paste Text with CRLF into Single Cell Jim Excel Discussion (Misc queries) 1 January 10th 08 08:57 PM
How do I copy the contents of a range of text cells and paste into one cell? davfin Excel Discussion (Misc queries) 7 July 4th 06 08:16 AM
open some txt files ,find text , copy the text before that to a single cell gus Excel Programming 2 July 11th 05 05:40 PM
Import multiple text files into a single worksheet Scott Excel Discussion (Misc queries) 0 January 13th 05 10:22 PM
Importing multiple text files into single workbook Steve[_56_] Excel Programming 1 January 15th 04 08:18 PM


All times are GMT +1. The time now is 04:04 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"