Thread: [Solved] Insert multiple files
View Single Post
 
Old 12-25-2013, 11:46 PM
macropod's Avatar
macropod macropod is offline Windows 7 32bit Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 22,382
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

OK, you could use a macro like:
Code:
Sub InsertFiles()
Application.ScreenUpdating = False
Dim strFolder As String, strFile As String
strFolder = GetFolder
If strFolder = "" Then Exit Sub
strFile = Dir(strFolder & "\*.txt", vbNormal)
With Selection
  While strFile <> ""
    .InsertAfter strFile & vbCr
    .InsertFile FileName:=strFolder & "\" & strFile, ConfirmConversions:=False, Link:=False
    .InsertAfter vbCr & vbCr
    .Collapse wdCollapseEnd
    strFile = Dir()
  Wend
End With
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
Simply run the macro and select the folder containing the text files. All such files in that folder will be inserted at wherever you selection/insertion point happens to be.

Note: As coded, the macro also inserts the file names. If you don't want that, comment-out or delete the '.InsertAfter strFile & vbCr' line. For the pre-defined number of 'blank lines, simply add or delete ' & vbCr' entries in the '.InsertAfter vbCr & vbCr' line.

For macro installation & usage instructions, see: http://www.gmayor.com/installing_macro.htm
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote