在word中使用vba遍历Range对象的Characters

环境:win7 64位,vs2010,word2010

c#源码:

try 
{
    MSWord.Range rFind = rangeFind.Parent as MSWord.Range;
    for (int i = 1; i <= rFind.Characters.Count; i++)
    {
        string str = rFind.Characters[i].Text;
    }
}
catch(Exception ex)
{
}

注意:这里for循环是从1开始的,若从0开始,会报0x800a1735异常

-        ex    {"集合所要求的成员不存在。"}    System.Exception {System.Runtime.InteropServices.COMException}
+        [System.Runtime.InteropServices.COMException]    {"集合所要求的成员不存在。"}    System.Runtime.InteropServices.COMException
+        Data    {System.Collections.ListDictionaryInternal}    System.Collections.IDictionary {System.Collections.ListDictionaryInternal}
        HelpLink    "wdmain11.chm#25421"    string
        HResult    0x800a1735    int
+        InnerException    null    System.Exception
        Message    "集合所要求的成员不存在。"    string
        Source    "Microsoft Word"    string
        StackTrace    "   at Microsoft.Office.Interop.Word.Characters.get_Item(Int32 Index)\r\n   at CesClient.Base.Command.WordOperator.DoFindingByRegex(String strregex, Boolean bparabegin, streamrange srg) in D:\\source\\WordClient\\Base\\Command\\DocOperator.cs:line 214"    string
+        TargetSite    {Microsoft.Office.Interop.Word.Range get_Item(Int32)}    System.Reflection.MethodBase {System.Reflection.RuntimeMethodInfo}
+        Static members        
+        Non-Public members        
参考:http://blog.163.com/freemailforme@126/blog/static/3442753120082209425698/

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值