Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
291 views
Welcome To Ask or Share your Answers For Others

1 Answer

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...