运行后,会弹出一个窗口,在里面输入你想按多少页导出。如果你想每5页存一个文档,那么就写5,如果是按1页,就写1。
Sub 多页导出()
Dim MyPath As String, PageCount As Integer
Dim StartRange As Long, EndRange As Long, MyRange As Range
Dim Fn As String, MyDoc As Document, i As Integer
Dim q%, a%
On Error Resume Next
Application.ScreenUpdating = False
MyPath = ActiveDocument.Path
PageCount = Selection.Information(wdNumberOfPagesInDocument)
Selection.HomeKey unit:=wdStory
q = InputBox("一闪流溢让我问问你,你想分几页导出,如5页,填写5")
For i = 1 To PageCount / q + (PageCount Mod q)
StartRange = Selection.Start
Selection.EndKey unit:=wdLine
Fn = i & "." & ActiveDocument.Name
If i * q >= PageCount Then
EndRange = ActiveDocument.Content.End
Else
For a = 1 To q
Selection.GoToNext (wdGoToPage)
Next a
EndRange = Selection.Start
End If
Set MyRange = ActiveDocument.Range(StartRange, EndRange)
MyRange.Copy
Set MyDoc = Documents.Add
With MyDoc
.Content.Paste
.Content.Paragraphs.Last.Range.Delete
.Content.Paragraphs.Last.Range.Delete
.SaveAs FileName:=MyPath & "/" & Fn
.Close
End With
Next
Application.ScreenUpdating = True
End Sub
代码借鉴改编自excelhome的雨雪霏霏和守柔,雨雪霏霏。守柔
如果答案对你有帮助,记得留言点赞。
2024-07-20 广告