MS-Word Automation (interop) question

Collating documents into one new document.

Page 1 of 1

2 Replies - 3915 Views - Last Post: 15 October 2008 - 12:02 AM Rate Topic: -----

#1 ericdevet  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 11-September 08

MS-Word Automation (interop) question

Posted 10 October 2008 - 02:27 AM

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.

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.....
http://www.pc112.sohosted.com/!example.jpg

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 October 2008 - 02:29 AM


Is This A Good Question/Topic? 0
  • +

Replies To: MS-Word Automation (interop) question

#2 Bort  Icon User is offline

  • Ill-informed Mongoloid
  • member icon

Reputation: 406
  • View blog
  • Posts: 2,997
  • Joined: 18-September 06

Re: MS-Word Automation (interop) question

Posted 10 October 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.
Was This Post Helpful? 0
  • +
  • -

#3 ericdevet  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 11-September 08

Re: MS-Word Automation (interop) question

Posted 15 October 2008 - 12:02 AM

View PostBort, on 10 Oct, 2008 - 06:44 AM, said:

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: 15 October 2008 - 12:13 AM

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1