Thread: [Solved] Merging multiple .txt's
View Single Post
 
Old 12-28-2010, 03:16 PM
macropod's Avatar
macropod macropod is offline Windows 7 32bit Office 2000
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 22,467
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

Hi Bartestokles,

Try the following 'InsertTextFiles' macro:
Code:
Sub InsertTextFiles()
Application.ScreenUpdating = False
Dim strFolder As String, strFile As String, strTxt As String
strFolder = GetFolder
If strFolder = "" Then Exit Sub
strFile = Dir(strFolder & "\*.txt", vbNormal)
While strFile <> ""
    Open strFolder & "\" & strFile For Input As #1
    strTxt = Input(LOF(1), 1)
    Close #1
    ActiveDocument.Range.InsertAfter vbCr & strTxt
    strFile = Dir()
Wend
Application.ScreenUpdating = True
End Sub
 
Function GetFolder() As String
Dim oFolder As Object
Set oFolder = CreateObject("Shell.Application").BrowseForFolder(0, "Choose a folder", 0)
If (Not oFolder Is Nothing) Then
  GetFolder = oFolder.Items.Item.Path
Else
  GetFolder = ""
End If
Set oFolder = Nothing
End Function
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote