2016-04-24 52 views
1

在另一个文档TCN.docxRange中工作时,我在rng.MoveRight unit:=Cell位置获得了method or data member not found的错误。移动到另一个文档中的下一个单元

Sub TNC() 
Dim odoc As Document 
Dim rng As Word.Range 

    Set odoc = Documents.Open(filename:="C:\Users\Bilal\Desktop\TCN.docx", Visible:=True) 
    Set rng = odoc.Content 
    rng.Find.ClearFormatting 
    rng.Find.Font.Bold = True 
    With rng.Find 
     .Text = "BU" 
     .Forward = True 
     .Wrap = wdFindStop 
     .Format = True 
    End With 
     rng.Find.Execute 
     If rng.Find.Found = True Then 

     rng.MoveRight unit:=Cell **ERROR position** 
     rng.COPY 
    Else 
    End If 

odoc.Close wdDoNotSaveChanges 
Selection.PasteAndFormat (wdPasteDefault) 

End Sub 

更好地理解

enter image description here

回答

1

编辑:辛迪梅斯特问题编辑后

MoveRight不是Range对象的有效方法,同时它是Selection对象

并没有Cell值为unit枚举,而wdCell

的元素一个单元格复制到发现一个右侧,使用

... 
    rng.Find.Execute 
    If rng.Find.Found = True Then 
     rng.Select 
     Selection.MoveRight unit:=wdCell 
     Selection.Copy 
    Else 
    End If 
    ... 
相关问题