Combining Multiple Documents In a Folder

C

css

I am a beginner, using VB 2005 for word automation to combine several
documents in a directory into a single document?

Not sure is it a good idea? I open one document at a time inside that folder
, attaching them as Subdocuments to the first document opened (the Master
document).

Any help on how to do this.

Thanks in advance.
 
C

css

I have created the following sub procedure, which takes all the documents in
a directory and combine them into a new directory.

The problem is I put a page break after inserting each document so I am
ended up having a blank last page. Is there a way to delete last page?


Private Sub CombineDocument()

WordApp = New Word.Application
WordDoc = New Word.Document

Try

WordApp.Visible = True
WordDoc = WordApp.Documents.Add()

For Each foundFile As String In My.Computer.FileSystem.GetFiles _
("c:\test\",
FileIO.SearchOption.SearchTopLevelOnly)

With WordApp.Selection
.InsertFile(foundFile)
.InsertParagraphAfter()
.InsertBreak(Word.WdBreakType.wdPageBreak)
.Collapse(Word.WdCollapseDirection.wdCollapseEnd)
End With
Next

WordDoc.SaveAs("c:\MainFile.doc")


Catch ex As Exception
MessageBox.Show(ex.ToString)
Finally
WordApp.Quit(False)

WordDoc = Nothing
WordApp = Nothing
End Try

End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top