Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/vba/15.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Vba 移动到另一文档中的下一个单元格_Vba_Ms Word_Word 2007_Word 2003 - Fatal编程技术网

Vba 移动到另一文档中的下一个单元格

Vba 移动到另一文档中的下一个单元格,vba,ms-word,word-2007,word-2003,Vba,Ms Word,Word 2007,Word 2003,在另一文档TCN.docx的范围内工作时,我在rng.MoveRight单元:=单元格位置上发现了方法错误或未找到数据成员 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.Clea

在另一文档
TCN.docx
范围内工作时,我在
rng.MoveRight单元:=单元格
位置上发现了
方法错误或未找到数据成员

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
为了更好地理解


编辑:辛迪·迈斯特编辑问题后

MoveRight
对于
Range
对象无效,而对于
Selection
对象无效

对于
unit
枚举,没有
Cell
值,而
wdCell

要将元素复制到找到的单元格的右侧,请使用

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