在Word2016里,将一个文件按照单页拆分成每一个单独的文件并保存的宏代码
时间: 2024-03-13 22:44:29 浏览: 100
以下是将Word 2016文件按照单页拆分成每一个单独的文件并保存的宏代码:
```
Sub SplitDocumentIntoPages()
Dim Doc As Document
Dim i As Integer
Dim DocName As String
Dim NewDoc As Document
Set Doc = ActiveDocument
For i = 1 To Doc.Content.StoryRanges.Count
Set NewDoc = Documents.Add
DocName = Doc.FullName
DocName = Left(DocName, Len(DocName) - 5)
DocName = DocName & "_" & i & ".docx"
NewDoc.SaveAs FileName:=DocName, FileFormat:=wdFormatXMLDocument
Doc.Content.StoryRanges(i).Copy
NewDoc.Content.Paste
NewDoc.Save
NewDoc.Close
Next i
Set NewDoc = Nothing
Set Doc = Nothing
MsgBox "Splitting Complete!"
End Sub
```
请注意,在运行此代码之前,请务必备份您的Word文件以避免数据丢失。
阅读全文