2016-02-24 119 views
-1

我想刪除內容控件所在的行。刪除內容控件所在的行

目前文檔有此以下文本:

t1 
t2 


Status:  Draft 
Valid from: 01.01.2012 
Valid for: All Emplyoees 

Created by:  a 
Released by: <content control goes here>. 

我有一個變量controlff這是控制的參考。無論我如何得到一個範圍,我總是通過刪除全文結束。

這其他問題並沒有完全幫助我:

Blank line after deleting contentControl in word

How to remove the entire line of a word doc using vba

deleting certain lines in ms word 2007

如何刪除一行已釋放?

編輯

所有我之前表現出裏面上表中的一行文本。

回答

1

下面是一個小例子,如何在表中執行此操作。首先獲取內容控制,將選擇內容擴展到表格單元格中的上一行並刪除選擇。

Sub test() 

    Dim rng As Range 

    'Get your Content Control here based on your variable reference 
    Set rng = ActiveDocument.ContentControls(1).Range 

    rng.Select 

    'Move outside the Content Control 
    Selection.MoveRight wdCharacter 
    Selection.MoveRight wdCharacter 

    'Select Line Up 
    Selection.MoveUp Unit:=wdParagraph, Count:=1, Extend:=wdExtend 

    'Include the paragraph from previous line 
    Selection.MoveLeft Unit:=wdWord, Count:=1, Extend:=wdExtend 

    'And ... Delete the selected area 
    Selection.Delete 
End Sub 

希望它可以幫助

+0

有一個5904'不能編輯range'消息。 –

+0

您的內容控制是否在表中?我用你提供的文本測試了代碼,在佔位符處插入了一個CC,並且沒有問題地工作。因此,文字中必須有一些禁止擴大範圍的內容。 –

+0

是的,抱歉沒有指出。 –