Click here to Skip to main content
15,893,508 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,

I could workout merge and split a multiple word document.

As I have finished the merge function, (All word document can merge with include its file name in beginning and back of its content), and I want to be able to split the merged document in previous (before merging) format.

I attach merging multiple word document.
I could use vb.net to this project.

VB
Dim arraylist(100) As String
            Dim oFals As Object = False
            Dim oTru As Object = True
            Dim obj2 As Object = WdSaveFormat.wdFormatDocument
            Dim missing As Object = System.Reflection.Missing.Value
            object1 = TextBox1.Text & "\MERGED DOCUMENT"
            Dim i As Integer
            Dim formt As Object = WdOpenFormat.wdOpenFormatDocument
            Dim obj As Object
            Dim wat1 As Object = word.WdGoToItem.wdGoToLine
            Dim wich As Object = word.WdGoToDirection.wdGoToLast
            Dim wat As Object = word.WdUnits.wdStory
            Dim moov As Object = word.WdMovementType.wdMove
            Dim str As Integer = 1
            objapp = CreateObject("word.Application")
            objapp.Visible = False
            objdoc = objapp.Documents.Add
            objdoc.SaveAs(object1, obj2)
            ''LOOPING THE LISTBOX TIEMS TO A ARRAYLIST ''
            For i = 0 To ListBox2.Items.Count - 1
                arraylist(i) = ListBox2.Items(i)
                obj = arraylist(i)
                ''OPENING A DOCUMENT IN THE ARRAY LIST(LISTBOX ITEMS)''
                objdoc = objapp.Documents.Open(obj, missing, oFals, oTru) ', "", "", oFals, "", "", formt, "", "", "", "", "", "")
                objapp.Selection.WholeStory()
                objapp.Selection.Copy()
                objdoc.Close()
                '' OPENING A NEW DOCUMENT ''
                objdoc = objapp.Documents.Open(object1, missing, oFals, oTru) ', "", "", oFals, "", "", formt, "", "", "", "", "", "")
                objapp.Selection.EndKey(wat, moov)
                ''INSERTING TAG TO THE START OF THE DOCUMENT''
                Dim s1 As String = "<filename">
                objapp.Selection.TypeParagraph()
                objapp.Selection.TypeText(s1)
                objapp.Selection.TypeParagraph()
                objapp.Selection.Paste()
                ''INSERTING TAG TO THE END OF THE DOCUMENT''
                Dim s2 As String = "
                objapp.Selection.TypeText(s2)
                objapp.Selection.TypeParagraph()
                str = str + 1
                objdoc.Save()
                objdoc.Close()
            Next i
            objapp.Quit()
Posted
Updated 24-Nov-11 23:58pm
v2
Comments
Richard MacCutchan 18-Nov-11 5:51am    
Just reverse what you have done here. However, you will need to add some markers of your own in the merged document, to indicate where each file begins.
Dalek Dave 25-Nov-11 5:59am    
Edited for Grammar and Readability.

1 solution

I done word file splitting in below coding

VB
objdoc = objapp.Documents.Open(obj, missing, oFals, oTru)
        range = objapp.ActiveDocument.Range
        range.Find.ClearFormatting()
        range.Find.Replacement.ClearFormatting()
        range.Find.Execute(regobj, missing, missing, oTru, missing, missing, oTru)
        Do While rang.Find.Found
            range.Select()
            matchcollection = Regex.Matches(tet, "^\[ITS_(.+?)\]")
            objapp.Selection.Cut()
            objdoc.SaveAs()
            objdoc.Close()
            objapp = CreateObject("word.Application")
            objapp.Visible = False
            objdoc = objapp.Documents.Add
            objapp.Selection.Paste()
            objdoc.SaveAs(obj1, obj2)
            objdoc.Close()
        Loop
 
Share this answer
 
v2
Comments
Maciej Los 25-Nov-11 16:00pm    
objapp is created as many timeS as many documents are splitting but never destroyed!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900