Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 08-27-2014, 08:44 AM
rpothen's Avatar
rpothen rpothen is offline Insert Multiple files - from a list Windows 7 64bit Insert Multiple files - from a list Office 2013
Novice
Insert Multiple files - from a list
 
Join Date: Aug 2014
Location: Philadelphia
Posts: 1
rpothen is on a distinguished road
Default Insert Multiple files - from a list

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
Reply With Quote
  #2  
Old 08-28-2014, 02:35 AM
macropod's Avatar
macropod macropod is offline Insert Multiple files - from a list Windows 7 64bit Insert Multiple files - from a list Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,963
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

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
Simply replace 'SourceDocumentpath & Name' with the source file's name.

PS: Please don't post multiple questions about the same issue.
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
Reply

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 - from a list 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
Insert Multiple files - from a list find files and insert filepaths userman Excel Programming 3 05-11-2012 02:53 PM
Insert Multiple files - from a list convert multiple csv files to multiple excel files mit Excel 1 06-14-2011 10:15 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 08:39 PM.


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