Removing the line where a content control is

﹥>﹥吖頭↗ 提交于 2019-12-13 09:47:58

问题


I want to remove a line where my content control is.

Currently the document has this following text:

t1
t2


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

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

I have a variable controlff which is a reference to the control. No matter how I get a range from it I always ended up by deleting the full text.

This other questions didn't quite help me:

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

How can I remove the Released by line?

EDIT

All the text that I showed before is inside of a single row on a table.


回答1:


Here is a small example how to do this in a table. First get the Content Control, Exctend the selection to the previous line in the table cell and delete the selection.

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

Hope it helps



来源:https://stackoverflow.com/questions/35605776/removing-the-line-where-a-content-control-is

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!