View Single Post
 
Old 11-27-2023, 07:32 PM
knpaddac knpaddac is offline Windows 10 Office 2016
Novice
 
Join Date: Jan 2018
Posts: 13
knpaddac is on a distinguished road
Default

This does pull all the content in BUT it does not put the filenames in the resulting document like the previous version did.


Quote:
Originally Posted by Guessed View Post
Try this version
Code:
Sub Import_Text()
  Dim strFolder As String, strFile As String, wdDoc As Document
  Application.ScreenUpdating = False
  strFolder = GetFolder
  If strFolder = "" Then Exit Sub
  strFile = Dir(strFolder & "\*.rtf", vbNormal)
  ChangeFileOpenDirectory strFolder
  Set wdDoc = ActiveDocument
  
  While strFile <> ""
    wdDoc.Range.Paragraphs.Last.Range.InsertFile FileName:=strFolder & "\" & strFile, ConfirmConversions:=False, Link:=False, Attachment:=False
    strFile = Dir()
  Wend
  Set wdDoc = Nothing
  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
  Set oFolder = Nothing
End Function
Reply With Quote