Blank line after deleting contentControl in word

六眼飞鱼酱① 提交于 2019-12-20 04:56:10

问题


I'm trying to write in a word document via VB.net and for this I'm using contentControls in my Word Document but sometimes I have to delete a contentControl or another via VB code.

It's kind of easy with contentcontrol.delete but when this contentControl contains multipleline and I want to delete it then it leaves a blank line. How can I avoid this?


回答1:


I will give you some tips based on VBA which I hope you could easily convert to vb.net and your solution.

You need to cover complete range of ContentControl including beginning and end of the object. You could do it in this way (VBA code for first CC in activedocument):

With ActiveDocument.ContentControls(1)
    'just to make a presentation- let's select range to be deleted
    ActiveDocument.Range(.Range.Start - 1, .Range.End + 2).Select
    'and we delete selection
    Selection.Delete
End With

Obviously you could combine .Select and .Delete lines into one to avoid selection in this way:

With.... and so on
    ActiveDocument.Range(.Range.Start - 1, .Range.End + 2).Delete
End with


来源:https://stackoverflow.com/questions/17450713/blank-line-after-deleting-contentcontrol-in-word

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