Public StartPageNum As Integer, EndPa" />
乔山办公网我们一直在努力
您的位置:乔山办公网 > word文档 > 批量删除<em>word</em>中的某一页(求<em>VBA</em>

批量删除<em>word</em>中的某一页(求<em>VBA</em>

作者:乔山办公网日期:

返回目录:word文档


没看出代码有什么问题啊,你运行的时候报告什么类型的错误啊

Public StartPageNum As Integer, EndPageNum As Integer

Sub aaa()

Dim myDialog As FileDialog, oFile As Variant, oDoc As Document
On Error Resume Next

Set myDialog = Application.FileDialog(msoFileDialogFilePicker)

myDialog.Filters.Clear '清除所有7a64e4b893e5b19e334文件筛选器中的项目
myDialog.Filters.Add "所有 WORD 文件", "*.doc", 1 '增加筛选器的项目为所有WORD文件
myDialog.AllowMultiSelect = True '允许多项选择

If myDialog.Show <> -1 Then Exit Sub

Dim SelectRange As Range
DlgDelePage.Show vbModal
If StartPageNum = 0 And EndPageNum = 0 Then
Exit Sub
End If

For Each oFile In myDialog.SelectedItems '在所有选取项目中循环

Set oDoc = Documents.Open(FileName:=oFile, Visible:=True) 'False)

Dim Pages As Integer, StartPage As Long, EndPage As Long

Pages = Selection.Information(wdNumberOfPagesInDocument)

If Not (StartPageNum > Pages) Then
If EndPageNum > Pages Then EndPageNum = Pages

If StartPageNum = 1 Then
StartPage = Selection.Range
Else
StartPage = Selection.GoTo(What:=wdGoToPage, Which:=wdGoToNext, Count:=StartPageNum - 1).Start
End If

If EndPageNum = Pages Then
EndPage = ActiveDocument.Content.End
Else
EndPage = Selection.GoTo(What:=wdGoToPage, Which:=wdGoToNext, Count:=IIf(EndPageNum - StartPageNum > 0, EndPageNum - StartPageNum + 1, 1)).End '.Start
End If

ActiveDocument.Range(StartPage, EndPage).Select
Selection.Delete

End If

'删除第3页批注
ActiveDocument.Words(1).Select '将光标移到文档开始位置
Dim myRange As Range, oComment As Comment
Set myRange = Selection.Range
StartPage = Selection.GoTo(What:=wdGoToPage, Which:=wdGoToNext, Count:=3 - 1).Start
EndPage = Selection.GoTo(What:=wdGoToPage, Which:=wdGoToNext, Count:=3 - 1).End

myRange = ActiveDocument.Range(StartPage, EndPage)

If myRange.Comments.Count > 0 Then
For Each oComment In myRange.Comments
oComment.Delete
Next
End If

oDoc.Save
oDoc.Close

Next oFile

End Sub
Sub Macro2()
   Dim r, p, r0, p0, rr, pp
    p= Selection.Information(wdActiveEndPageNumber) '当前页码
    r= Selection.Information(wdFirstCharacterLineNumber) '当前行
    
    '数e68a84e8a2ad7a64334行数
   p0 = p
   rr = r
   Do
       Selection.MoveDown Unit:=wdLine, Count:=1
       pp = Selection.Information(wdActiveEndPageNumber)
       r0 = Selection.Information(wdFirstCharacterLineNumber)
       If pp > p Then
           '退回原处
           Selection.MoveUp Unit:=wdLine, Count:=(rr - r + 1)
           Exit Do
       End If
       If rr = r0 Then
           '退回原处
          Selection.MoveUp Unit:=wdLine, Count:=(rr - r)
           Exit Do
       End If
       rr = r0
    Loop
   MsgBox "当前页码:" & p & vbCrLf & "本页总行数:" & rr
End Sub

 申请加悬赏分!!!



其实不用vba,按f5进入定位,找到页这一项,右边输入\page

相关阅读

  • <em>VBA</em>如何选中<em>Word</em>文档中的文本、

  • 乔山办公网word文档
  • ====57132899====都是直接读取到数组里的,还选择什么劲word文档中的所有表格" src="/uploads/tu/739.jpg" style="width: 400px; height: 267px;" />使用VBA来选定Word文档中的文字,可使用Select方法选定文档中
  • 用<em>vba</em>实现,在同一个<em>Word</em>文件中

  • 乔山办公网word文档
  • 1、打开word文档,这个文档有4页。2、想将来光标迅速移动到第3页,自可以点击开始,替换。百3、弹出对话框,点击定位度。4、弹出对话框,点击定位目标内容“页”问,右边输入页号
关键词不能为空
极力推荐
  • <em>Word</em> <em>分栏</em>后<em>

  • 选择标题内容>点分栏>选择分1栏>然后再选择文字居中>完成.Word排版 分成两栏后 如何使标题位置在中间?" src="/uploads/tu/321.jpg" style="width: 400px; height: 267px;" />1、除标题以外,选择选中需要

ppt怎么做_excel表格制作_office365_word文档_365办公网