1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
| Sub SplitWordFile() Dim pageCount As Integer Dim splitWordNum As Integer Dim rngPage As Range Dim splitDoc As Document Dim targetFolder As String pageCount = ActiveDocument.BuiltInDocumentProperties(wdPropertyPages) splitWordNum = pageCount / 3 currentPage = 1 targetFolder = "C:\Users\jzhout1\Downloads\CopyTest\Result\" Set rngPage = ActiveDocument.Range Application.ScreenUpdating = False For Index = 1 To 3 Selection.GoTo What:=wdGoToPage, Which:=wdGoToAbsolute, Count:=currentPage rngPage.Start = Selection.Range.Start Selection.GoTo What:=wdGoToPage, Which:=wdGoToAbsolute, Count:=Index * splitWordNum Selection.MoveEnd rngPage.End = Selection.Range.End rngPage.Copy Set splitDoc = Documents.Add splitDoc.Select Selection.WholeStory Selection.PasteAndFormat (wdFormatOriginalFormatting) newDocName = targetFolder & Right$("000" & Index, 4) & ".docx" splitDoc.SaveAs newDocName splitDoc.Close currentPage = Index * splitWordNum + 1 Next Index Application.ScreenUpdating = True End Sub
|