200頁的Word文檔如何分割成每4頁一個的50個文檔


http://zhidao.baidu.com/question/143381141.html

打開要處理的WORD文檔,然后ALT+F8調出宏處理窗口,新輸入宏名稱為MyPg。
點擊右側的編輯按鈕,輸入如下內容,完成后鍵盤F5即可。

但完成后最后2個文件也會會有問題,手動修改一下就行了。


Sub MyPg()

    Dim oWord As Word.Application
    Dim oDoc As Word.Document
    Dim oNewDoc As Word.Document
    Dim oRange As Word.Range
    Dim lCurrentStart As Long
    Dim lCurrentEnd As Long
    Dim lDocumentEnd As Long
    Dim lOutputCount As Long
   
    lOutputCount = 0
   
    Set oWord = GetObject(, "Word.Application")
    Set oDoc = ActiveDocument
   
    oDoc.Select
    lCurrentStart = oWord.Selection.Start
    lCurrentEnd = lCurrentStart
    lDocumentEnd = oWord.Selection.End
   
    oWord.Selection.Collapse wdCollapseStart
   
    Do While (lCurrentEnd < lDocumentEnd)
        oWord.Browser.Target = wdBrowsePage
        oWord.Browser.Next
        oWord.Browser.Next
        oWord.Browser.Next
        oWord.Browser.Next
        lCurrentEnd = oWord.Selection.End
       
        If (lCurrentStart = lCurrentEnd) Then
            lCurrentEnd = lDocumentEnd
        End If
       
        Set oRange = oDoc.Range(lCurrentStart, lCurrentEnd)
       
        Set oNewDoc = oWord.Documents.Add
        oRange.Copy
        oNewDoc.Range(0, 0).Paste
       
        lOutputCount = lOutputCount + 1
        oNewDoc.SaveAs FileName:="d:\" & lOutputCount & ".doc"
        oNewDoc.Close
       
        lCurrentStart = lCurrentEnd
    Loop


End Sub


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM