word分割的宏

Option Explicit

Sub SplitPagesAsDocuments()

Dim oSrcDoc As Document, oNewDoc As Document

Dim strSrcName As String, strNewName As String

Dim oRange As Range

Dim nIndex As Integer

Dim fso As Object

Set fso = CreateObject("Scripting.FileSystemObject")

Set oSrcDoc = ActiveDocument

Set oRange = oSrcDoc.Content

oRange.Collapse wdCollapseStart

oRange.Select

For nIndex = 1 To ActiveDocument.Content.Information(wdNumberOfPagesInDocument)

oSrcDoc.Bookmarks("\page").Range.Copy

oSrcDoc.Windows(1).Activate

Application.Browser.Target = wdBrowsePage

Application.Browser.Next

strSrcName = oSrcDoc.FullName

strNewName = fso.BuildPath(fso.GetParentFolderName(strSrcName), _

fso.GetBaseName(strSrcName) & "_" & nIndex & "." & fso.GetExtensionName(strSrcName))

Set oNewDoc = Documents.Add

Selection.Paste

Selection.MoveDown Unit:=wdLine, Count:=58

With Selection.PageSetup

.LineNumbering.Active = False

.Orientation = wdOrientPortrait

.TopMargin = CentimetersToPoints(1.27)

.BottomMargin = CentimetersToPoints(1.27)

.LeftMargin = CentimetersToPoints(1.27)

.RightMargin = CentimetersToPoints(1.27)

.Gutter = CentimetersToPoints(0)

.HeaderDistance = CentimetersToPoints(1.5)

.FooterDistance = CentimetersToPoints(1.75)

.PageWidth = CentimetersToPoints(21)

.PageHeight = CentimetersToPoints(29.7)

.FirstPageTray = wdPrinterDefaultBin

.OtherPagesTray = wdPrinterDefaultBin

.SectionStart = wdSectionNewPage

.OddAndEvenPagesHeaderFooter = False

.DifferentFirstPageHeaderFooter = False

.VerticalAlignment = wdAlignVerticalTop

.SuppressEndnotes = False

.MirrorMargins = False

.TwoPagesOnOne = False

.BookFoldPrinting = False

.BookFoldRevPrinting = False

.BookFoldPrintingSheets = 1

.GutterPos = wdGutterPosLeft

.CharsLine = 39

.LinesPage = 44

.LayoutMode = wdLayoutModeLineGrid

End With

WordBasic.PageSetupPaper Tab:=1, PaperSize:=0, TopMargin:="1.27", _

BottomMargin:="1.27", LeftMargin:="1.27", RightMargin:="1.27", Gutter:= _

"0", PageWidth:="29.7", PageHeight:="30", Orientation:=0, FirstPage:=0, _

OtherPages:=0, VertAlign:=0, ApplyPropsTo:=0, FacingPages:=0, _

HeaderDistance:="1.5", FooterDistance:="1.75", SectionStart:=2, _

OddAndEvenPages:=0, DifferentFirstPage:=0, Endnotes:=0, LineNum:=0, _

CountBy:=0, TwoOnOne:=0, GutterPosition:=0, LayoutMode:=2, DocFontName:= _

"", FirstPageOnLeft:=0, SectionType:=1, FolioPrint:=0, ReverseFolio:=0, _

FolioPages:=1

With Selection.ParagraphFormat

.LeftIndent = CentimetersToPoints(0)

.RightIndent = CentimetersToPoints(0)

.SpaceBefore = 0

.SpaceBeforeAuto = False

.SpaceAfter = 0

.SpaceAfterAuto = False

.LineSpacingRule = wdLineSpaceExactly

.LineSpacing = 1

.Alignment = wdAlignParagraphJustify

.WidowControl = False

.KeepWithNext = False

.KeepTogether = False

.PageBreakBefore = False

.NoLineNumber = False

.Hyphenation = True

.FirstLineIndent = CentimetersToPoints(0)

.OutlineLevel = wdOutlineLevelBodyText

.CharacterUnitLeftIndent = 0

.CharacterUnitRightIndent = 0

.CharacterUnitFirstLineIndent = 0

.LineUnitBefore = 0

.LineUnitAfter = 0

.MirrorIndents = False

.TextboxTightWrap = wdTightNone

.AutoAdjustRightIndent = True

.DisableLineHeightGrid = False

.FarEastLineBreakControl = True

.WordWrap = True

.HangingPunctuation = True

.HalfWidthPunctuationOnTopOfLine = False

.AddSpaceBetweenFarEastAndAlpha = True

.AddSpaceBetweenFarEastAndDigit = True

.BaseLineAlignment = wdBaselineAlignAuto

End With

Selection.MoveUp Unit:=wdLine, Count:=1

Selection.Delete Unit:=wdCharacter, Count:=1

oNewDoc.SaveAs strNewName

oNewDoc.Close False

Next

Set oNewDoc = Nothing

Set oRange = Nothing

Set oSrcDoc = Nothing

Set fso = Nothing

MsgBox "结束!"

End Sub

©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

  • Spring Cloud为开发人员提供了快速构建分布式系统中一些常见模式的工具(例如配置管理,服务发现,断路器,智...
    卡卡罗2017阅读 136,147评论 19 139
  • 参考 Ubuntu16.10安装Apache, MySQL, PHP7,phpmyadminUbuntu 配置 A...
    cndaqiang阅读 2,967评论 0 0
  • 一 谁,执我之手,敛我半世癫狂; 谁,吻我之眸,遮我半世流离; 谁,抚我之面,慰我半世哀伤; 谁,携我之心,融我半...
    嘿2阅读 1,841评论 0 1
  • 开始决定写点东西开始时,喜欢上了阅读,阅读各种短篇作品和一些充满正能量的话语,我们的人生应该充满正能量的,才不会迷...
    Cherry樱桃丸子阅读 1,706评论 0 3
  • 在南方某著名高校的运动场有这样的标语:我运动,我健康,我快乐。其逻辑关系想必是:因为我运动了,所以我健康了,因此我...
    Bintou老师阅读 5,034评论 4 5

友情链接更多精彩内容