本文介绍了Contentcontrols.add错误4605,bug ??的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是b $ b我正在使用Word 2013,我正在尝试将内容控件添加到一堆表格单元格中。我不想在添加时使用当前选择,因为我听说最好使用范围。

Hi,
I'm using Word 2013 and I'm trying to add content controls to a bunch of table cells. I don't want to use current selection when adding since I've heard that it's preferable to use ranges instead.

我使用的代码基本上是:

The code that I use is basically:

Set oRng = oTbl.Rows(RowIdx).Cells(1).Range
Set oCC = ActiveDocument.Contentcontrols.Add(wdContentControlText, oRng)

一段时间内工作得很好,但后来偶尔开始表现得很奇怪,抱怨"错误4605"。此方法不可用,因为当前选择部分涵盖了纯文本内容Control。

This worked just fine for a while, but then sporadically started behaving weird, complaining about "error 4605" This method is not available because the current selection partially covers a plain text content Control.

我使用oRng.Select调查我的范围但看起来很好,范围只是一个空单元格。

I used oRng.Select to investigate my range but it seemed fine, the range was only a single empty cell.

过了一会儿,我弄明白是什么导致了这个错误。似乎如果我当前的选择在已经包含任何类型的内容控件的单元格内,它将给我这个错误,即使我将新的内容控件添加到定义为
的范围作为oRng。这是一个错误,还是我做错了什么?

After a while I figured out what caused the error. It seems that if my current selection is within a cell already containing a content control of any type, it will give me this error, even though I'm adding the new content control to the range defined as oRng. Is this a bug, or am I doing something wrong?

最好的问候,

David

Best regards,
David




推荐答案

 设置oRng = oTbl.Rows(RowIdx)。细胞(1)。范围

  oRng.End = oRng.End - 1

  oRng.Collapse wdCollapseEnd

 设置oCC = ActiveDocument.ContentControls.Add(wdContentControlText,oRng)

  Set oRng = oTbl.Rows(RowIdx).Cells(1).Range
  oRng.End = oRng.End - 1
  oRng.Collapse wdCollapseEnd
  Set oCC = ActiveDocument.ContentControls.Add(wdContentControlText, oRng)

这将可靠地在单元格中插入新的内容控件,无论是否已包含任何内容控件。新控件将是单元格中的最后一项。

This will reliably insert new content controls in a cell, whether or not is already contains any. The new control will be the last item in the cell.


这篇关于Contentcontrols.add错误4605,bug ??的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-18 11:56