M
Martin
I am new to VB so be nice ![Smile :) :)](data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7)
I am trying to merge a number of word documents together, and am
trying to use the master/subdocument concept.
However, the documents are appearing at the top of the master
document, instead of being added sequentially at the end of the
document (which is what I want).
I have a template document which I wish to append these subdocuments
to. This template will contain a cover sheet, table of contents,
styles, headers/footers, etc etc.
The code I have is
Dim oDoc As Word.Document
Dim oPara As Word.Paragraph
oPara =
oDoc.Content.Paragraphs.Add(oDoc.Bookmarks.Item("\endofdoc").Range)
oPara.Range.Text = "Heading 1"
oPara.Range.InsertParagraphAfter()
oDoc.Application.ActiveDocument.Subdocuments.AddFromFile("c:
\document1.doc")
oPara =
oDoc.Content.Paragraphs.Add(oDoc.Bookmarks.Item("\endofdoc").Range)
oPara.Range.Text = "Heading 2"
oPara.Range.InsertParagraphAfter()
oDoc.Application.ActiveDocument.Subdocuments.AddFromFile("c:
\document2.doc")
However, the document generated looks like
c:\document1.doc <------ these are the hyperlinks to the subdocuments
c:\document2.doc
Template document stuff
Heading 1
Heading 2
I have tried making use of the endofdoc bookmark to try to get the
subdocuments at the end using the following:
oDoc.Application.ActiveDocument.Subdocuments.Expanded = True
oDoc.Application.Selection.InsertParagraphAfter()
oDoc.Bookmarks.Item("\endofdoc").Range.Subdocuments.AddFromFile(vReports(vCount))
but this doesn't help either.
Can anyone please help me?
Thanks
Martin
I am trying to merge a number of word documents together, and am
trying to use the master/subdocument concept.
However, the documents are appearing at the top of the master
document, instead of being added sequentially at the end of the
document (which is what I want).
I have a template document which I wish to append these subdocuments
to. This template will contain a cover sheet, table of contents,
styles, headers/footers, etc etc.
The code I have is
Dim oDoc As Word.Document
Dim oPara As Word.Paragraph
oPara =
oDoc.Content.Paragraphs.Add(oDoc.Bookmarks.Item("\endofdoc").Range)
oPara.Range.Text = "Heading 1"
oPara.Range.InsertParagraphAfter()
oDoc.Application.ActiveDocument.Subdocuments.AddFromFile("c:
\document1.doc")
oPara =
oDoc.Content.Paragraphs.Add(oDoc.Bookmarks.Item("\endofdoc").Range)
oPara.Range.Text = "Heading 2"
oPara.Range.InsertParagraphAfter()
oDoc.Application.ActiveDocument.Subdocuments.AddFromFile("c:
\document2.doc")
However, the document generated looks like
c:\document1.doc <------ these are the hyperlinks to the subdocuments
c:\document2.doc
Template document stuff
Heading 1
Heading 2
I have tried making use of the endofdoc bookmark to try to get the
subdocuments at the end using the following:
oDoc.Application.ActiveDocument.Subdocuments.Expanded = True
oDoc.Application.Selection.InsertParagraphAfter()
oDoc.Bookmarks.Item("\endofdoc").Range.Subdocuments.AddFromFile(vReports(vCount))
but this doesn't help either.
Can anyone please help me?
Thanks
Martin