本文介绍了在word中删除contentControl后的空白行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试通过 VB.net 编写Word文档,为此,我在Word文档中使用了 contentControls ,但有时我必须删除一个 contentControl 或通过VB代码的另一个.

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.

使用contentcontrol.delete有点容易,但是当此contentControl包含多行并且我要删除它时,它将留下一个空白行.如何避免这种情况?

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?

推荐答案

我将为您提供一些基于VBA的技巧,希望您可以轻松地将其转换为vb.net和您的解决方案.

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

您需要涵盖ContentControl的完整范围,包括对象的开始和结束.您可以通过这种方式进行操作(activedocument中第一个CC的VBA代码):

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

很明显,您可以将.Select.Delete行合并为一条,以避免通过这种方式进行选择:

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

这篇关于在word中删除contentControl后的空白行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-11 12:25