Merging multiple text files and wrapping in Excel

I have several text files (400-500 words each, multiple paragraphs) that I would like to append into Excel where the content of each text file is placed into one cell. This needs to be vertically appended downwards for all text files. I’d appreciate any help on this.

I have a script that will append all the text files into one master file, but nothing that will place the entire contents of each txt file into one cell that has to be wrapped.

I know there is this command but I need to be able to grab each .txt file and have them append downwards:


tell application "Microsoft Excel"
	set sampleText to range "A1" of sheet 1 of active workbook
	set wrap text of sampleText to true
end tell

Hi,

try this, the script asks for a folder which contains the text files


set theFolder to choose folder
tell application "Finder" to set textFiles to files of theFolder
tell application "Microsoft Excel"
	if (count workbooks) = 0 then make new workbook
end tell
repeat with oneFile from 1 to (count textFiles)
	set theText to read (item oneFile of textFiles as alias)
	tell application "Microsoft Excel"
		tell cell 1 of row oneFile of sheet 1 of active workbook
			set wrap text to true
			set value to theText
		end tell
	end tell
end repeat

Is the syntax of one of these lines what you are looking for?

tell application "Microsoft Excel"
	set myCell to range ("c1") of active sheet
	
	set value of myCell to value of myCell & " new text"--adds to same cell
	set value of (get offset of myCell row offset 1) to "new text"--adds to cell below
	
end tell

Stephan,

I tried the script but getting AS Error: Microsoft Excel got an error: can’t set wrap text of cell 1 of row 1 of sheet 1 of active workbook to true."

Your thoughts…

Hm, I’ve tested the script successfully with Excel 2004

Stefan,

Silly me. I had a worksheet open and cell 1 content was filled. Exited Excel, ran the script and all checks out. You have just made my life a bit easier! Danke!