Foreach Word Revision - “请求的对象不可用”错误 [英] Foreach Word Revision - "Requested object is not available" error

查看:136
本文介绍了Foreach Word Revision - “请求的对象不可用”错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,


我遇到了一个问题,我真的不明白为什么会这样。请记住,在我的代码测试中,这是第一个发生这种情况的文档(不幸的是,我不能共享该文档,因为它是保密的)。


所以,我正在做一个关于几个word文档的每个修订版以及"格式化"文件时的foreach。发现版本我只是命令接受它。


我的代码是:

 foreach(Word.Revision wr in doc。修订)
{
if(wr.FormatDescription.Contains(" Formatted"))
{
wr.Accept();
}
}


我认为这可能是这个特定文件的一个问题执行51次,在52上触发异常(文档总共有59次修订)。


现在,因为我没有控制数量将在foreach上执行的循环,因为它是"doc.Revisions"。说明循环数,这是怎么回事?



有什么想法吗?


提前感谢。


解决方案

您好JEstevao,


根据我的测试,我无法重现您的问题,因为您的代码基于您的特定文档。但是你提到你有一个错误说:"请求的对象不可用"。


我认为你可以使用
修订
(索引),其中index是索引号,返回单个
Revisions 
对象。索引号表示范围或文档中修订的位置。


有关详细信息,请查看以下链接:  修订版界面


最好的问候,


由贵


Hello to you all,

I'm facing a problem that I really don't understand why this is happening. Keep in mind that in my code testing this is the first document that this is happening (unfortunatelly I can't share the document since it is confidential).

So, I'm doing a foreach on each revision on several word documents and when a "formatting" revision is found I just command to accept it.

My code is:

foreach (Word.Revision wr in doc.Revisions)
{
	if (wr.FormatDescription.Contains("Formatted"))
	{
		wr.Accept();
	}
}

I consider that it could be a problem with this specific document however the foreach is performed 51 times and on the 52 the exception is triggered (document has 59 revisions in total).

Now, since I'm not controlling the number of loops that will be performed on the foreach since it is "doc.Revisions" that states that loop number, how is this happening?

Any ideas?

Thank in advance.

解决方案

Hi JEstevao,

Base on my test, I can't reproduce your problem since your code is based on your specific document. But you have mentioned that you got an error says:"Requested object is not available".

I think you can use Revisions(index), where index is the index number, to return a single Revisions object. The index number represents the position of the revision in the range or document.

For more information, please review the following link: Revision Interface

Best Regards,

Yuki


这篇关于Foreach Word Revision - “请求的对象不可用”错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆