Welcome to Dream.In.Code
Getting VB.NET Help is Easy!

Join 131,496 VB.NET Programmers for FREE! Get instant access to thousands of VB.NET experts, tutorials, code snippets, and more! There are 1,805 people online right now. Registration is fast and FREE... Join Now!




MS-Word Automation (interop) question

 
Reply to this topicStart new topic

MS-Word Automation (interop) question, Collating documents into one new document.

ericdevet
post 10 Oct, 2008 - 01:27 AM
Post #1


New D.I.C Head

*
Joined: 11 Sep, 2008
Posts: 2

Hello all.

I'm making some software that uses a base of separate MS-Word documents that have to be collated into one new document. I have found some about the Word Interop, but not what i need.

Here is the code i have. What i need is the part that copies all the text from the Source document and append it to the target document.

CODE

Sub DocCreate()
        Dim oWord As Word.Application = Nothing
        Dim oSourceWord As Word.Application = Nothing
        Dim oDoc As Word.Document = Nothing
        Dim oSourceDoc As Word.Document = Nothing
        Dim oTable As Word.Table = Nothing
        Dim oPara(100) As Word.Paragraph
        Dim oRng As Word.Range = Nothing
        Dim oShape As Word.InlineShape = Nothing
        Dim oChart As Object = Nothing
        Dim oBookmark As Word.Bookmark = Nothing
        Dim Pos As Double = Nothing
        Dim X As Integer = 0, Max As Integer = 0
        Dim TMP As String = Nothing
        Dim intNumberOfPages As Integer = 0
        Dim intNumberOfChars As String = 0
        Dim intPage As Integer = 0
        oWord = New Word.Application
        oSourceWord = New Word.Application
        oSourceWord.Visible = False
        oWord.Visible = True
        oDoc = oWord.Documents.Add
        oWord.Caption = OffCaption
        Max = SelectedDocs.Items.Count
        For X = 0 To Max - 1
            TMP = SPath & SelectedDocs.Items.Item(X)
            oSourceDoc = oSourceWord.Documents.Open(TMP)
[color=#33CC00]            'oSourceDoc.Select()
            'oPara(X) = oDoc.Content.Paragraphs.Add(oDoc.Bookmarks.Item("\endofdoc").Range)
            'oPara(X).Range.Text = " "
            'oPara(X).Format.SpaceAfter = 6
            'oPara(X).Range.InsertParagraphAfter()[/color]
        Next
    End Sub


A short description of the software and its function.
The software has 2 listboxes. The left one contains the possible Word Documents, the right will contain the by the user selected Word Documents. When done the user clicks on the "Generate Button" and the software creates a new Word Document that contains all the text from the documents in the right listbox, in the order that they show in the right listbox.

As one picture says more than thousend words.....
IPB Image

So i need help with the code to select text from one Word Document and copy i to the end of another Word document.

This post has been edited by ericdevet: 10 Oct, 2008 - 01:29 AM
User is offlineProfile CardPM

Go to the top of the page


Bort
post 10 Oct, 2008 - 05:44 AM
Post #2


D.I.C Regular

Group Icon
Joined: 18 Sep, 2006
Posts: 388



Thanked 4 times

Dream Kudos: 350
My Contributions


I'd probably recommend using StreamReader to read the documents, then either StreamWriter or automation to write the documents into one file.
User is offlineProfile CardPM

Go to the top of the page

ericdevet
post 14 Oct, 2008 - 11:02 PM
Post #3


New D.I.C Head

*
Joined: 11 Sep, 2008
Posts: 2

QUOTE(Bort @ 10 Oct, 2008 - 06:44 AM) *

I'd probably recommend using StreamReader to read the documents, then either StreamWriter or automation to write the documents into one file.


I don't think that that wil work. This because WORD documents are so much more than just plain text.
<edit>
Did as a test a binary copy of 2 WORD documets into one file. The resulting file had the size of the two files together, but only the content of the first file was visible.
As streamwriting would have the same effect as a binary copy of two files into one, this will not work.
</edit>

This post has been edited by ericdevet: 14 Oct, 2008 - 11:13 PM
User is offlineProfile CardPM

Go to the top of the page

Fast ReplyReply to this topicStart new topic
Time is now: 11/20/08 12:16AM

Live VB.NET Help!

VB.NET Tutorials

Reference Sheets

VB.NET Snippets

Bye Bye Ads

Free DIC T-Shirt

T-Shirt Example

Related Sites

Monthly Drawing

Thumb Drive

Partners

Top Contributors

Top 10 Kudos This Month