Microsoft Office Forums

Go Back   Microsoft Office Forums > >

 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
  #3  
Old 09-14-2023, 04:59 AM
knpaddac knpaddac is offline How to import multiple text file data into word Windows 10 How to import multiple text file data into word Office 2016
Novice
 
Join Date: Jan 2018
Posts: 13
knpaddac is on a distinguished road
Default

Quote:
Originally Posted by macropod View Post
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
Is there a way to add to this code so that the filenames would be included in the content that is put into the document to which all the content is being put? So that it would look something like:

'DOC1-FILENAME'
"DOC1-CONTENT"

'DOC2-FILENAME'
"DOC2-CONTENT"

'DOC3-FILENAME'
"DOC3-CONTENT"

'DOC4-FILENAME'
"DOC4-CONTENT"

And on and on based on the folder chosen
Reply With Quote
 



Similar Threads
Thread Thread Starter Forum Replies Last Post
How to import multiple text file data into word 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
How to import multiple text file data into word extracting data from Table to text file Anirudh_Dsp Word Tables 1 05-23-2010 07:48 AM
How to import multiple text file data into word 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

Other Forums: Access Forums

All times are GMT -7. The time now is 10:05 AM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2025, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2025 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft