Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Merge multile word documents into a single file 1

Status
Not open for further replies.

BenTitus

Programmer
Jan 16, 2003
61
0
0
US
Hello i have been searching on the net for a way to merge multiple word documents into a single file. From there I plan on using Monarch to extract the necissary data. I created a form with a command button and used some code i found on the net. it looks like this:

Private Sub CommandButton1_Click()
Call MergeFiles
End Sub
Sub MergeFiles()
Dim files() As String
Dim num_files As Integer
Dim file_name As String
Dim dir_path As String
Dim file_ext As String
Dim i As Integer
dir_path = "S:\Information Technology\Development\Quotes\New Folder"
file_ext = "doc"

file_name = Dir(dir_path & "*." & file_ext)
Do While Len(file_name) > 0
ReDim Preserve files(0 To num_files)
files(num_files) = LCase(file_name)
file_name = Dir()
num_files = num_files + 1
Loop
Selection.EndKey Unit:=wdline
For i = 0 To num_files - 1
With Selection
.InsertFile dir_path & files(i)
.EndKey Unit:=wdline
.InsertBreak Type:=wdPageBreak
End With
Next i


End Sub

I keep getting an error at Selection.EndKey ... I am not framiliar with Selection.EndKey so i do not know how to go about solving this error. Does anyone have any suggestions?
Thanks in advance
 
Hi BenTitus,

You are falling down at the first reference to a Word Object in code which looks as though it belongs in Word, and your question is about Word Documents.

BUT ..... this is an Access Forum so are you trying to run this in Access? If you have reason to run it in Access then you must open up a Word session and address it properly in order to use the Word Objects.

Enjoy,
Tony
 
Hello,
Just to give you a heads up i have no clue about trying to open multiple files and merge them to one file. Unfortunatly i do not have VB6.0 or .Net on my computer at work so i figure to do it in VBA by using a command button on a form. This is probably an incorrect approach but like i previously said i dont know much on this topic. I am dealing with about 1000 word files so i was searching for a method to open the directory and merge all the files.
 
Hello Ben.

What does your data look like in Word? You could import all the data into a common table in Access then export it back out to Word?

Would this approach work for your situation?
 
The word documents have a template which gives customer information. So the layout is uniform. The only problem is below it there is a details section which varies in length.
 
Hi BenTitus,

If I read you right there's no real reason for doing this in Access, so why not do it in Word?

Take the code as posted with one very slight amendment and put it in a code module in Word and run it. The amendment is ..

Code:
 file_name = Dir(dir_path & "
Code:
\
Code:
*." & file_ext)

If you don't know how to run it in Word, or you really want to do it from Access, post back.

Enjoy,
Tony
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top