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

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值