我正在使用Excel VBA创建并填充Word文档,我想删除该文档中的特定页面。我尝试了以下删除方法:
With wDoc
.GoTo What:=wdGoToPage, Which:=wdGoToAbsolute, Name:="20" 'Page number
.Bookmarks("\Page").Select
With Selection
.Delete
End With
End With
此代码在执行时不返回任何错误消息,但未按预期删除单词页面内容。我想念什么?
答案 0 :(得分:1)
检查以下代码。我在这里删除了名称参数中的引号(将“ 20”替换为20) 您可以使用文档参考wDoc代替我曾经使用过的Activedocument。
With ActiveDocument
.GoTo What:=wdGoToPage, Which:=wdGoToAbsolute, Name:=20 'Page number
.Bookmarks("\Page").Select
With Selection
.Delete
End With
End With
答案 1 :(得分:1)
有时您需要继续删除,直到页面完全消失为止。
Sub DeletePage(iPageNumber As Integer)
'
' DeletePage Macro
'
With ThisDocument
.GoTo(What:=wdGoToPage, name:=iPageNumber).Select
.Bookmarks("\Page").Range.Select
End With
Selection.Delete
' keep deleting until page is gone
Do
Selection.MoveLeft Extend:=wdExtend
Selection.Delete
Loop Until Selection.Information(wdActiveEndAdjustedPageNumber) < iPageNumber
结束子
答案 2 :(得分:0)
some_form[items][0][name]
或
With wdDoc
Lr = .Goto(wdGoToPage, wdGoToLast).Start
.Range(Lr - 1, wdDoc.Range.End).Delete
End with
它将找到最后一个角色/暴怒并删除