![]() |
|
#2
|
||||
|
||||
|
Hi mizankabir,
the following macro allows you to simply select a folder and have Word import the contents of all txt files in that folder. Code:
Sub Import_Text()
Application.ScreenUpdating = False
Dim strFolder As String, strFile As String, wdDoc As Document, txtFile As Document
strFolder = GetFolder
If strFolder = "" Then Exit Sub
strFile = Dir(strFolder & "\*.txt", vbNormal)
Set wdDoc = ActiveDocument
While strFile <> ""
Set txtFile = Documents.Open(FileName:=strFolder & "\" & strFile, AddToRecentFiles:=False, Visible:=False, ConfirmConversions:=False)
wdDoc.Range.InsertAfter txtFile.Range.Text & vbCr
txtFile.Close SaveChanges:=True
strFile = Dir()
Wend
Set txtFile = Nothing: Set wdDoc = Nothing
Application.ScreenUpdating = True
End Sub
Function GetFolder() As String
Dim oFolder As Object
GetFolder = ""
Set oFolder = CreateObject("Shell.Application").BrowseForFolder(0, "Choose a folder", 0)
If (Not oFolder Is Nothing) Then GetFolder = oFolder.Items.Item.Path
Set oFolder = Nothing
End Function
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
How to copy automatically data from Excel file to Word file?
|
fuchsd | Word | 6 | 10-25-2011 05:52 AM |
| Import formatted text from Word into PowerPoint | parboy | PowerPoint | 0 | 07-06-2011 08:52 AM |
extracting data from Table to text file
|
Anirudh_Dsp | Word Tables | 1 | 05-23-2010 07:48 AM |
Import Text from File - Line Spacing
|
marshalx | Word | 2 | 10-28-2009 02:37 AM |
| import multiple categories | stormin.norm | Outlook | 0 | 01-30-2006 01:36 PM |