vba - MS Word vba 重新排列页面顺序
问题描述
如何反转所有页面顺序,因此第 1、2、3、4、5 页变为 5、4、3、2、1,因为这在打印时执行 Option.Reverse。
作为
Sub test()
Dim WA As Object, WD As Object
Dim rngDoc As Word.Range, rngInsert As Word.Range
Set WA = CreateObject("Word.Application")
Set WD = WA.Documents.Add(TemplatesName)
Set rngDoc = WD.Content
Set rngInsert = rngDoc.Duplicate
For i = 1 To 100
With rngInsert
.InsertBreak Type:=wdSectionBreakNextPage
.MoveEnd Unit:=wdCharacter, Count:=-1 ' this one reversing pages
.InsertFile TemplatesName
End With
Next i
WD.SaveAs PdfFile, 17
WD.Close False: Set WD = Nothing
WA.Quit False: Set WA = Nothing
End Sub
以相反的顺序插入页面,我需要把它们倒过来
Option.reverse 与
WA.PrintOut OutputFileName:=PdfFile, Range:=wdPrintAllDocument, Item:= _
wdPrintDocumentWithMarkup, Copies:=1, Pages:="", PageType:= _
wdPrintAllPages, Collate:=True, Background:=True, PrintToFile:=True, _
PrintZoomColumn:=0, PrintZoomRow:=0, PrintZoomPaperWidth:=0, _
PrintZoomPaperHeight:=0
做我需要的,但这里会警告错误的margings,所以如果我将displayalert设置为False,那么文档不会保存。
解决方案
如果这是您所追求的,您可以通过以下方式反转打印顺序:
Options.PrintReverse = True
但是,如果问题是您以错误的顺序插入页面,则需要如下代码:
Sub Demo()
Dim wdApp As New Word.Application, wdDoc As Word.Document
Dim wdRng As Word.Range, i As Long
Const TemplatesName As String = "Template Path & name"
Set wdDoc = wdApp.Documents.Add(TemplatesName)
Set wdRng = wdDoc.Range
For i = 1 To 10
With wdRng
.InsertAfter vbCr
.Start = wdDoc.Range.End
.InsertBreak Type:=wdSectionBreakNextPage
.Collapse wdCollapseEnd
.InsertFile TemplatesName
End With
Next i
End Sub
推荐阅读
- flutter - Flutter 将列表排序到 TreeNode 的嵌套小部件中
- python - 如何更改 .flair 缓存文件夹位置 (https://github.com/flairNLP/flair)?
- c++ - 如何编译和运行使用 fltk 的程序?
- python - Python:导入文件 .tgz
- javascript - How to Parse a String in Java Script language which contains "color code change" numericals into the string such as 32m+ or 31m-
- arrays - laravel 数组 groupBy 特定列值
- angular - 如何将一个组件选择器传递给另一个组件?
- node.js - 使用 Puppeteer 抓取 AWS 在本地运行,但在 Heroku 上失败
- python - 计算字符串的 CRC32 校验和
- odoo - Odoo 服务器错误,因为基本字段 resource_calendar_id 不存在