Combining Word Documents

M

M.L.Srinivas

Hi,

My task is to combine word documents from a selected
folder. I do not want the formatting to be disturbed while
combining

I'm using the following code:

Set myrange = wdcombine.Range
numchar = wdcombine.Characters.count
Set EndofDoc = wdcombine.Characters(numchar)
Set myrange = EndofDoc
myrange.Collapse wdCollapseEnd
wdcombine.Range.InsertBreak
Type:=wdSectionBreakNextPage
wdcombine.Range.InsertFile lbltarget
& "\Log.doc", , ConfirmConversions:=False

this is combining the documents but there's lot of
inconsistency while doing that in regard to formatting.
can anybody suggest the changes or an alternative logic.

Any suggestion is appreciated.

M.L.Srinivas
 
J

Jonathan West

Hi M.L. Srinivas,

The problem here is that if the different documents are based on different
templates with different style definitions, combining them inevitably leads
to formatting changes. I'm not aware of any way of avoiding this.

So, you might perhaps need to consider an approach to this problem that does
not combine the files. This article might give you some ideas.

Creating a Table of Contents Spanning Multiple Documents
http://pubs.logicalexpressions.com/Pub0009/LPMArticle.asp?ID=148
 
M

M.L.Srinivas

Mr. West,

Thanks for your reply. What is surprising in my problem is
all the documents are of the same template.

but still there's inconsistency, i'm really going mad to
see the level of inconsistency.

I even tried this code:

Private Sub MergeDocs()
Dim mobjWordDoc1 As Object
Dim mobjWordDoc2 As Object

Set mobjWordDoc1 = CreateObject("Word.Basic")
Set mobjWordDoc2 = CreateObject("Word.Basic")
Dim i As Integer

Screen.MousePointer = 11

If Not fsys.FolderExists(lblsource & "\Combined") Then
fsys.CreateFolder (lblsource & "\Combined")
End If
lbltarget.Caption = lblsource & "\Combined"

'word_app.Visible = False
'On Error GoTo err_trap

For i = 1 To lvsource.ListItems.count
If i = 1 Then
mobjWordDoc1.fileopen lblsource & "\" &
lvsource.ListItems(i)
mobjWordDoc1.filesaveas lbltarget
& "\Combined.doc"
Else
mobjWordDoc2.fileopen lblsource & "\" &
lvsource.ListItems(i)
mobjWordDoc2.editselectall
mobjWordDoc2.EditCopy
mobjWordDoc1.EndofDocument
mobjWordDoc1.InsertPageBreak
mobjWordDoc1.EditPaste
mobjWordDoc1.filesave
mobjWordDoc2.fileclose
End If
nxtfile:
Next

mobjWordDoc1.fileclose
mobjWordDoc1.appclose
mobjWordDoc2.appclose
Set mobjWordDoc1 = Nothing
Set mobjWordDoc2 = Nothing

Set fld = Nothing
Screen.MousePointer = 0
MsgBox "Report generation completed",
End Sub

I'm really helpless....

M.L.Srinivas
 
J

Jonathan West

Changing the way in which one document is added to another is not likely to
affect the inconsistency. What needs to be done is to identify what the
changes are, and in what way the original documents are different from each
other. Armed with this information, you can either ensure that those
differences don't occur in future, or develop a macro that eliminates those
inconsistencies before the documents are merged.

Can you describe the specific inconsistencies you are expriencing?

--
Regards
Jonathan West - Word MVP
http://www.multilinker.com
Please reply to the newsgroup
 
J

JGM

Hi M.L.,

I do not know if this will help, but I have done something smilar before and
these two suggestions helped me a lot. Also, you have to make sure that the
paragraph sytles in each source doc were not modified.

Have you tried inerting a section break between documents instead of a page
break?
Also, have you tried NOT selecting the last paragaph mark in the each source
document before copying/Pasting them?

HTH
Cheers!
 
M

M.L.Srinivas

Mr. West,

Thanks.

The inconsistency is with the font size and bolded words. The font
size is changing and some bolded words are getting unbold. This is
what observed till now.

M.L.Srinivas
 
M

M.L.Srinivas

Hi JGM,

Thanks for your time.

I have tried both Page Break and Section Break, but there's no
difference.
As I'm using insertfile method in first method, i think there's no way
i can eliminate the last paragraph mark.

And in the second method where I used 'editselectall', I do not know
how to leave the last paragraph mark. Please suggest any method for
doing that.

M.L.Srinivas
 
J

Jonathan West

M.L.Srinivas said:
Mr. West,

Thanks.

The inconsistency is with the font size and bolded words. The font
size is changing and some bolded words are getting unbold. This is
what observed till now.

I would recommend that you define some additional character styles within
your template to cover these font variations, and use the character styles
to format the document. If you strictly avoid using manual formatting at
all, you will have a much better chance of getting the import to work
correctly.

If you are using Word 2003, then you can use the Document Protection feature
to enforce the use of only a prescribed set of styles and prevent the use of
manual formatting.

I suggest you do some experimentation on a few sample files and see if this
has any effect before trying to apply this to a large document set.
 
E

Ed

To select everything in a document but the last paragraph mark, you can use:
ActiveDocument.Content.Select
Selection.MoveLeft Unit:=wdCharacter, Count:=1, Extend:=wdExtend

As I understand, Word "hides" formatting information in the paragraph marks.
The last mark in the document contains all kinds of info for the doc, as
well as for the last paragraph. This is why sometimes a Word doc opened in
advertently in another program will show "garbage" characters - it's that
program's interpretation of the formatting code. If you leave off the last
mark from your copy selection, you leave of that document formatting. (If
I'm wrong, someone please bail me out!)

I work with multiple docs. What I use many times is Edit>Paste
Special>Unformatted Text. The text pasted into the doc then picks up the
underlying format of the document. It loses any overlaid formatting - bolds
won't stay bold, and neither will italics - but it won't change the text
already in the "receiving" doc by imposing its formatting over the other.

HTH
Ed
 

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