Microsoft Office Forums

Go Back   Microsoft Office Forums > >

 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
  #1  
Old 09-14-2023, 08:28 AM
knpaddac knpaddac is offline Add filename to imported text Windows 10 Add filename to imported text Office 2016
Novice
Add filename to imported text
 
Join Date: Jan 2018
Posts: 13
knpaddac is on a distinguished road
Default Add filename to imported text

I frequently need to import the content from hundreds of files into a single document. I would like to have the filename included as text above each file's content in the final document. Is there a way to do this by adding it into the code I use (listed below):




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.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
 



Similar Threads
Thread Thread Starter Forum Replies Last Post
Add filename to imported text formatting of imported text philh Word 4 03-23-2020 02:56 PM
Add filename to imported text Convert Imported picture to text Baldeagle Excel Programming 2 03-23-2019 01:51 PM
filename field not displaying correct filename when that name starts with # plrsmith Word 1 07-06-2018 03:10 AM
How to merge text boxes in a large imported document boatfly Word 3 04-20-2016 06:15 AM
Add filename to imported text Save Filename using Document Text Knawl Word 11 10-10-2011 03:00 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 03:11 PM.


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