How can I import data of a text file into a ms word file.I am using windows XP.I need to import 200+ text file data into a MS doc file.So,I need a short cut way to import selected text file data into the doc within a few clicks.If there is any other way to do it,plz tell me.

tnx

Dani AI

Generated

Practical, low-effort ways to import 200+ plain-text files into a Word document. As noted, opening single .txt files by hand works for one-off cases; for bulk work the fastest approaches are: use Word’s built-in Insert -> Text from File to select and import many files at once, or automate the task with a short Word VBA macro as suggested by . ’s point about order and organization is important — filenames should be prepared so the import happens in the desired sequence.

The Insert -> Text from File command (Ribbon: Insert -> Object -> Text from File; older menus: Insert -> File) allows multi-select of .txt files and inserts them into the current document in filename order. For predictable results, prefix files with sortable numbers (001, 002, ...). This approach requires no code and is quick for a single target document. Test with a few files first to confirm encoding and line-break behavior.

Example VBA macro to automate insertion from a folder (change folderPath to the folder containing the .txt files):

Sub InsertAllTextFilesFromFolder()
    Dim fso As Object, fld As Object, f As Object
    Dim folderPath As String
    folderPath = "C:\Path\To\TextFiles"   ' adjust this path
    Set fso = CreateObject("Scripting.FileSystemObject")
    Set fld = fso.GetFolder(folderPath)
    For Each f In fld.Files
        If LCase(fso.GetExtensionName(f.Name)) = "txt" Then
            Selection.InsertFile FileName:=f.Path, ConfirmConversions:=False
            Selection.TypeParagraph
        End If
    Next f
End Sub

Notes: if preservation of encoding is required, convert sources to a consistent encoding before importing; very large combined documents can be slow—split into parts if performance becomes a problem; always back up originals and test on a small subset first.

Recommended Answers

All 5 Replies

Hello,

Have you tried right clicking on the txt file and selecting Open With and then selecting Microsoft Word? If it is not in the liet then add it using the option at the bottom...

In your other thread you are asking how to save firefox documents to txt files. Are these 2 related? Can you explain what you are doing?

the way the question is asked ,it means more that just opening the file in Word .I asks "How can I import data of a text file into a ms word file" to me this means ,im working on a word file and i want to add some text form another source to the word file ,i do use MS Word ,and have imported text from another source into a document, but i'am no expert ,and i don't think there is any quick way of doing this , how unorganized would the file actually end up being .
so having said that you likely mean you want to change the .txt files into .docx files .not going to be quick and easy either ,at best you would have to open each one in Word and ten save as word file.me thinks

: I agree about the improt, but depending what we are talking about here the answer could either be a macro, or an ODBC pointing to a txt file and a datasource for that ODBC or a macro with OLEDB or whatever.

@caperjack: I agree about the improt, but depending what we are talking about here the answer could either be a macro, or an ODBC pointing to a txt file and a datasource for that ODBC or a macro with OLEDB or whatever.

ok,sounds good ,so poster need to look at creating macro i assume ,[]maybe something more in-depth to created one to do what poster want to do , thats a part of Word i know nothing about .maybe i learn it in that link to.

main page .
http://www.homeandlearn.co.uk/word2007_2010/Word-2007-2010.html

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.