Separate Word documents into smaller ones

I want the user to be able to download a Word document, and my program then analyzes the document into separate text documents. The problem is that splitting must be manual, since all dictionary documents are not formatted the same way. My initial thought is that before the user downloads, the user places sections with the start and end tags (maybe maybe a comment), that my program can parse and split the document into separate documents. (This is also necessary for .doc and .docx to work, so a common solution is desirable)

Ex. Input data:

doc1

Chapter 1

Blah blah blah

Chapter 2

Blah blah

/ end Doc1

Ex. Output:

doc1

Chapter 1

Blah blah blah

/ end Doc1

Doc 2

Chapter 2

Blah blah

/ end Doc2

Any ideas? I struggled with this for a while

+3
5

, ! , , DOCX , - , .:

http://openxmldeveloper.org/

, .

"" -? , , COM-!

+4

, VSTO VBA . .

0

-, , HTML Transit. , . Word (, HTML). , - . Google "HTML Transit" .

0
0

VBA Macro

Sub UpdateDocuments()

    Application.ScreenUpdating = False
    Dim strFolder As String, strFile As String, wdDoc As Document
    strFolder = GetFolder
    If strFolder = "" Then Exit Sub
    strFile = Dir(strFolder & "\*.doc", vbNormal)
    While strFile <> ""
        Set wdDoc = Documents.Open(FileName:=strFolder & "\" & strFile,      AddToRecentFiles:=False, Visible:=False)
        With wdDoc
            'Call your other macro or insert its code here
            'BreakOnSection
            wdDoc.Activate

        ActiveDocument.ActiveWindow.View.Type = wdOutlineView
            Selection.WholeStory
        Selection.Copy
            ActiveDocument.Subdocuments.AddFromRange Range:=Selection.Range
            ActiveDocument.SaveAs "C:\Data\Split\" & ActiveDocument.Name

            ActiveDocument.Close SaveChanges:=True
    End With
    strFile = Dir()
    Wend
    Set wdDoc = Nothing
    Application.ScreenUpdating = True
End Sub

Function GetFolder() As String
    Dim oFolder As Object
    GetFolder = ""
    Set oFolder = CreateObject("Shell.Application").BrowseForFolder(0,     

"Choose a folder", 0)
    If (Not oFolder Is Nothing) Then GetFolder = oFolder.Items.Item.Path
    Set oFolder = Nothing
End Function
0

Source: https://habr.com/ru/post/1733430/


All Articles