2012-05-13 68 views
1

可以使用刪除命令刪除頁眉和頁腳。但我想刪除除Shapes以外的所有頁眉/頁腳。有兩個範圍:TextRange和ShapesRange。 ShapeRange可以像下面那樣訪問。如何刪除頁眉和頁腳除了形狀範圍

For Each sec In worddoc.Sections 
     For Each hdr In sec.Headers 
      For Each sh In hdr.Shapes 
       If sh.Left > 200 Then 
        'Do something 
       End If 
      Next sh 
     Next hdr 
    Next sec 

如何刪除TextRange?

通過設置.TextRange =「」將刪除表格,文本框? 這很緊急。您的幫助將非常感謝!

+0

我要刪除所有文字,字段(文本框),從頭部表,除了形狀。 – Jan2012

回答

2

這是你想要的嗎?

Option Explicit 

Sub Sample() 
    Dim ctl As ContentControl 
    Dim tbl As Table 
    Dim i As Long 

    With ActiveDocument.Sections(1).Headers(wdHeaderFooterPrimary).Range 

     On Error Resume Next 
     '~~> Delete all controls like textbox label etc 
     For Each ctl In .ContentControls 
      ctl.Delete 
     Next 

     '~~> Delete all tables 
     For Each tbl In .Tables 
      tbl.Delete 
     Next 
     On Error GoTo 0 

     '~~> Delete all printable/non printable characters 
     For i = 0 To 255 
      With .Find 
       .ClearFormatting 
       .Replacement.ClearFormatting 
       .Text = Chr(i) 
       .Replacement.Text = "" 
       .Forward = True 
       .Wrap = wdFindContinue 
       .Execute Replace:=wdReplaceAll 
      End With 
     Next i 
    End With 

    MsgBox "Done" 

End Sub 

快照

enter image description here

相關問題