View Single Post
 
Old 11-26-2023, 07:56 PM
knpaddac knpaddac is offline Windows 10 Office 2016
Novice
 
Join Date: Jan 2018
Posts: 13
knpaddac is on a distinguished road
Default Merging word documents containing tables

I frequently have to merge many (even hundreds of them) Word documents into one. Recently many of these have included content that is in tables within the documents. In the resulting doc, I am getting line breaks (enters) between the content from each cell but I want it to be tabs. Can anybody help me with this? I have included the code below as I am currently using it:


Code:
Sub Import_Text()
Application.ScreenUpdating = False
Dim strFolder As String, strFile As String, wdDoc As Document, rtfFile As Document
strFolder = GetFolder
If strFolder = "" Then Exit Sub
strFile = Dir(strFolder & "\*.rtf", vbNormal)
Set wdDoc = ActiveDocument
While strFile <> ""
  Set rtfFile = Documents.Open(FileName:=strFolder & "\" & strFile, AddToRecentFiles:=False, Visible:=False, ConfirmConversions:=False)
  wdDoc.Range.InsertAfter rtfFile & vbCr & rtfFile.Range.Text & vbCr
  rtfFile.Close SaveChanges:=True
  strFile = Dir()
Wend
Set rtfFile = 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
Reply With Quote