Microsoft Office Forums

Go Back   Microsoft Office Forums > >

 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
  #1  
Old 11-02-2014, 10:43 PM
tejaspareek tejaspareek is offline Combine Different Word files into one file and update Table of Content Windows 7 64bit Combine Different Word files into one file and update Table of Content Office 2010 64bit
Novice
Combine Different Word files into one file and update Table of Content
 
Join Date: Oct 2014
Posts: 13
tejaspareek is on a distinguished road
Default Combine Different Word files into one file and update Table of Content

Hi,

I was working on a word file. In the file I need to combine multiple word files from a dynamic location (means the location can changed as per the requirement).
I got a static code, which is working. But i want to convert it to a dynamic code, where i can set the folder location using a folder picker.

Please help.



Static Code
Code:
Sub MergeDocs()
Dim rng As Range
Dim MainDoc As Document
Dim strFile As String
Set MainDoc = ActiveDocument
Const strFolder = "C:\Users\A020105\Desktop\Test\" 'change to suit
strFile = Dir$(strFolder & "*.docx") ' can change to .docx
Do Until strFile = ""
Set rng = MainDoc.Range
rng.Collapse wdCollapseEnd
rng.InsertBreak
rng.InsertFile strFolder & strFile
strFile = Dir$()
Loop
ActiveDocument.TablesOfContents(1).Update

End Sub

Dynamic Code
Code:
Private Sub Document_New()
'
'
Dim rng As Range
Dim MainDoc As Document
Dim strFile As Variant
Dim strFolder As FileDialog

Set MainDoc = ActiveDocument
Set strFolder = Application.FileDialog(msoFileDialogFolderPicker)
strFolder.AllowMultiSelect = True
strFolder.Show
strFile = Dir$(STFolder & "\" & "*.docx")
Do While strFile <> ""
Set rng = MainDoc.Range
rng.Collapse wdCollapseEnd
rng.InsertBreak
rng.InsertFile STFolder & strFile
strFile = Dir$()
Loop
ActiveDocument.TablesOfContents(1).Update
End Sub
Reply With Quote
 



Similar Threads
Thread Thread Starter Forum Replies Last Post
Combine Different Word files into one file and update Table of Content Referencing + Automatic update of Shared Content in MS Word. mitucool Word 14 10-09-2013 02:08 AM
Combine Different Word files into one file and update Table of Content How to combine many word files in one file but to have correct pages numbers and tabl Jamal NUMAN Word 6 04-20-2011 02:32 PM
Combine Different Word files into one file and update Table of Content SOS - cannot update table of content properly Lee Word 5 02-04-2011 12:59 PM
A Table of Contents that Will Dictate the Content of the File ddhardy Word 0 06-23-2010 06:01 AM
Combine Different Word files into one file and update Table of Content Combine pst files? markg2 Outlook 2 04-26-2010 03:09 PM

Other Forums: Access Forums

All times are GMT -7. The time now is 08:37 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