![]() |
|
#1
|
||||
|
||||
|
This code (https://www.msofficeforums.com/word-...ple-files.html) is great and it get the files from a directory ( strFile = Dir(strFolder & "*.txt", vbNormal) ) all the text file in this specific folder\directory . . . great . . . can someone give me code where instead of getting the file from a directory, I want to read a text file that contains the names of the file that I want to insert into the document.
For example: File = filenames.txt contains the following rows/data: C:\user\rpothen\departments.txt D:\data\regions.txt L:\EMEA\country.txt I want to ready Filename.txt and insert the contents of the three files into my document. How do I do that? Last edited by macropod; 08-27-2014 at 03:16 PM. Reason: Split post to new thread |
|
#2
|
||||
|
||||
|
You could use a macro like:
Code:
Sub InsertFiles()
Application.ScreenUpdating = False
Dim i As Long, strFile As String, DocTgt As Document, DocSrc As Document
Set DocTgt = ActiveDocument
Set DocSrc = Documents.Open("SourceDocumentpath & Name", ReadOnly:=True, AddToRecentFiles:=False)
With DocTgt.Content
For i = 0 To UBound(Split(DocSrc.Content.Text, vbCr)) - 1
strFile = Split(DocSrc.Content.Text, vbCr)(i)
.Collapse wdCollapseEnd
.InsertAfter strFile & vbCr
.InsertFile FileName:=strFile, ConfirmConversions:=False, Link:=False
.InsertAfter vbCr & vbCr
Next
End With
DocSrc.Close SaveChanges:=False
Application.ScreenUpdating = True
End Sub
PS: Please don't post multiple questions about the same issue.
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
|
| Tags |
| file content, import from text |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Easiest Way to Produce a Report/List of Tagged Text from Multiple Word Files | bxchk | Word | 5 | 04-29-2014 03:23 PM |
Insert multiple files
|
weamish | Word VBA | 16 | 12-27-2013 05:25 PM |
| The powerpoint icon on the task bar hides pptx files in the recent files list | Innovationgame | PowerPoint | 0 | 11-13-2013 09:03 AM |
find files and insert filepaths
|
userman | Excel Programming | 3 | 05-11-2012 02:53 PM |
convert multiple csv files to multiple excel files
|
mit | Excel | 1 | 06-14-2011 10:15 AM |