空间公告

Word vba分页保存文件(按节,由邮件合并生成)

上一篇 / 下一篇  2007-10-03 13:56:49



Sub BreakOnSection()
   ' Used to set criteria for moving through the document by section.
   Application.Browser.Target = wdBrowseSection

   'A mailmerge document ends with a section break next page.
   'Subtracting one from the section count stop error message.
   For i = 1 To ((ActiveDocument.Sections.Count) - 1)
  
      'Select and copy the section text to the clipboard
      ActiveDocument.Bookmarks("\Section").Range.Copy

      'Create a new document to paste text from clipboard.
      Documents.Add
      Selection.Paste

   ' Removes the break that is copied at the end of the section, if any.
      Selection.MoveUp Unit:=wdLine, Count:=1, Extend:=wdExtend
      Selection.Delete Unit:=wdCharacter, Count:=1

     ChangeFileOpenDirectory "C:\1\"
      DocNum = DocNum + 1
 
     ActiveDocument.SaveAs FileName:=Left(Trim(ActiveDocument.Paragraphs.Item(2).Range), Len(Trim(ActiveDocument.Paragraphs.Item(2).Range)) - 1) & ".doc"‘以第二段内容为文件名
     'ActiveDocument.SaveAs FileName:="a" & DocNum & ".doc"
     ActiveDocument.Close
      ' Move the selection to the next section in the document
     Application.Browser.Next
   Next i
   ActiveDocument.Close savechanges:=wdDoNotSaveChanges
End Sub

http://support.microsoft.com/kb/216201/zh-cn

TAG:

 

评分:0

我来说两句

显示全部

:loveliness: :handshake :victory: :funk: :time: :kiss: :call: :hug: :lol :'( :Q :L ;P :$ :P :o :@ :D :( :)

Open Toolbar