Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
303 views
in Technique[技术] by (71.8m points)

vba - Removing the line where a content control is

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

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

1 Reply

0 votes
by (71.8m points)

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...