有2万多个WORD文档,每个文档里第一叶是张表格,第二页是空白的,怎么统一删掉空白页?
发布网友
发布时间:2022-04-30 17:57
我来回答
共4个回答
热心网友
时间:2023-10-09 08:41
用vba批量删除空白页
1、Alt+F11启动VBA窗口,
2、F7插入模块
3、复制代码
4、F5运行代码
具体代码如下:
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追问大神,怎么把这么多文档全部插入啊?第2步插入模块怎么做按F7没效果,望指教。
追答
你可以把它保存为模版。
热心网友
时间:2023-10-09 08:41
没办法,只能一个一个的来!
热心网友
时间:2023-10-09 08:41
2W多文档。。。。兄弟你是干嘛的,,,,让开发的做个程序就好了
热心网友
时间:2023-10-09 08:42
10没人要