WORD邮件合并文档自动拆分每节为一个文档

WORD邮件合并文档自动拆分每节为一个文档
Sub 自动拆分每节为一个文档()
   Dim mySec As Section, i As Long, myDoc As Document, SourceDoc As Document                             '定义变量
   Set SourceDoc = ActiveDocument                                                                        '设置源文档为当前活动文档
   For Each mySec In SourceDoc.Sections                                                                 '设置当前文档每节循环
      If mySec.PageSetup.SectionStart = wdSectionNewPage And mySec.Index > 1 Then
         Set myDoc = Application.Documents.Add
         myDoc.Content.FormattedText = SourceDoc.Range(i, mySec.Range.Start - 1)
         myDoc.Content.Sections.Last.PageSetup.SectionStart = _
                  SourceDoc.Range(i, mySec.Range.Start - 1).Sections.Last.PageSetup.SectionStart
         i = mySec.Range.Start
      End If
      
      If mySec.Index = SourceDoc.Sections.Count Then                                                    '最后一节的处理
         Set myDoc = Application.Documents.Add
         myDoc.Content.FormattedText = SourceDoc.Range(i, SourceDoc.Content.End)
         myDoc.Content.Sections.Last.PageSetup.SectionStart = _
                  SourceDoc.Range(i, SourceDoc.Content.End).Sections.Last.PageSetup.SectionStart
      End If
   
   Next
End Sub
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值