Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: VB.NET
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.
 
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 17-Nov-11 20:59pm
Edited 24-Nov-11 23:58pm
Dalek Dave432.6K
v2
Comments
Richard MacCutchan at 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 at 25-Nov-11 5:59am
   
Edited for Grammar and Readability.

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

I done word file splitting in below coding

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
  Permalink  
v2
Comments
losmac at 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)

  Print Answers RSS
0 Sergey Alexandrovich Kryukov 9,935
1 OriginalGriff 6,987
2 CPallini 5,845
3 George Jonsson 4,015
4 Gihan Liyanage 3,266


Advertise | Privacy | Mobile
Web01 | 2.8.140926.1 | Last Updated 25 Nov 2011
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100