怎么让word自动删除第3、6、9、12等3的倍数页‘

Sub kk1206190933()
Dim wNum As Integer
Dim wPag As Integer
With Selection
wPag = .Information(wdNumberOfPagesInDocument)
For wNum = Int(wPag / 3) * 3 To 3 Step -3
.GoTo wdGoToPage, , wNum
.Bookmarks("\Page").Range.Delete
Next
End With
End Sub

VBA实现检查和删除Word中的空白页

Sub GetBlankPage()
Dim IsDelete As Boolean
Dim PageCount As Long
Dim rRange As Range
Dim iInt As Integer, DelCount As Integer
Dim tmpstr As String IsDelete = True
PageCount = ThisDocument.BuiltInDocumentProperties(wdPropertyPages)
For iInt = 1 To PageCount
'超过PageCount退出
If iInt > PageCount Then Exit For '取每一页的内容
If iInt = PageCount Then
Set rRange = ThisDocument.Range( _
Start:=ThisDocument.GoTo(wdGoToPage, wdGoToAbsolute, iInt).Start)
Else
Set rRange = ThisDocument.Range( _
Start:=ThisDocument.GoTo(wdGoToPage, wdGoToAbsolute, iInt).Start, _
End:=ThisDocument.GoTo(wdGoToPage, wdGoToAbsolute, iInt + 1).Start _
)
End If If Replace(rRange.Text, Chr(13), "") = "" Or Replace(rRange.Text, Chr(13), "") = Chr(12) Then
tmpstr = tmpstr & "第 " & iInt & " 页是空页" & vbCrLf
'删除?
If IsDelete Then
DelCount = DelCount + 1
'删除空白页
rRange.Text = Replace(rRange.Text, Chr(13), "")
rRange.Text = ""
'重算页数
PageCount = ThisDocument.BuiltInDocumentProperties(wdPropertyPages)
If iInt <> PageCount Then
'页删除后,页码变化,重新检查当前页
iInt = iInt - 1
Else
'最后一个空页
Set rRange = ThisDocument.Range( _
Start:=ThisDocument.GoTo(wdGoToPage, wdGoToAbsolute, PageCount - 1).Start, _
End:=ThisDocument.GoTo(wdGoToPage, wdGoToAbsolute, PageCount + 1).Start _
)
'如果是分页符,删除上一页中的换页符
If InStr(1, rRange.Text, Chr(12)) > 0 Then
rRange.Characters(InStr(1, rRange.Text, Chr(12))) = ""
Else
'没有分页符,通过选中后删除,最好不这样做,如果判断错误,有误删除的风险
Set rRange = ThisDocument.Range( _
Start:=ThisDocument.GoTo(wdGoToPage, wdGoToAbsolute, iInt).Start)
rRange.Select
Selection.Delete
End If
Exit For
End If
End If
End If
Next If 1 = 1 Or Not IsDelete Then
If tmpstr = "" Then
MsgBox "没有空页", vbInformation + vbOKOnly
Else
MsgBox tmpstr, vbInformation + vbOKOnly
End If
Else
If DelCount > 0 Then MsgBox "删除空页 " & DelCount, vbInformation + vbOKOnly
End If
End Sub

  

Sub AA()

Dim myRange As Range

Dim wNum As Integer
Dim wPag As Integer
Dim start As Integer wPag = Selection.Information(wdNumberOfPagesInDocument)
Selection.GoTo wdGoToPage, wdGoToAbsolute, 3
MsgBox (Selection.Range.start & "+" & Selection.Range.End)
start = Selection.Range.start '.EndKey Unit:=wdStory
'myRange.End = .Range.Start
'MsgBox (myRange.Text)
'If Replace(.Range.Text, Chr(13), "") = "" Or Replace(.Range.Text, Chr(13), "") = Chr(12) Then
'.Bookmarks("\Page").Range.Delete
'End If Selection.EndKey Unit:=wdStory
Selection.Select
MsgBox (Selection.Range.start & "+" & Selection.Range.End)
'Set myRange = ActiveDocument.Range(ActiveDocument.GoTo(wdGoToPage, wdGoToAbsolute, 3).start, End:=ActiveDocument.GoTo(wdGoToPage, wdGoToAbsolute, 3).start) Set myRange = ActiveDocument.Range(start, End:=Selection.start) MsgBox (myRange.Text) End Sub

  

最新文章

  1. Java 8新特性-4 方法引用
  2. 区别 PHP 的 $_POST、$HTTP_RAW_POST_DATA 和 php://input
  3. BZOJ4657 : tower
  4. 浏览器中Javascript的加载和执行
  5. 字符串匹配的KMP算法详解及C#实现
  6. NPOI导入导出Excel (2)
  7. Linux经常使用的命令(十) - nl
  8. WinFom解决最小化最大化后重绘窗口造成闪烁的问题
  9. mysql 系统性浅聊 myisam 存储引擎【原创】
  10. SpringMvc解决Restful中文乱码问题
  11. SPOJ Coconuts 最大流 最小割
  12. HBase之Table.put客户端流程
  13. python中的__metaclass__
  14. plsql备份表---只是表---不包含表数据
  15. Delphi创建ActiveX控件,实现安全接口及无界面代码
  16. 【css】css 中文字体 unicode 对照表
  17. 用FadingActionBar实现有头图的ActionBar
  18. python 的math模块
  19. Android Studio 创建/打开项目时一直处于Building“project name”Gradle project info 的解决
  20. ORA-12560:TNS:协议器错误的解决方法

热门文章

  1. 腾讯云-搭建 .NET Core 开发环境
  2. iOS开发之复制字符串到剪贴板
  3. Linux内核配置解析 - Boot options
  4. Posix共享内存区
  5. debian更新源时找不到公钥的解决办法
  6. hdu 4961 Boring Sum(高效)
  7. django 模板使用静态文件
  8. man手册查找ascii码和运算符优先级
  9. ssh:Permissions 0644 for ‘/root/.ssh/id_rsa’ are too open
  10. 【Android】3.14 公交线路查询功能