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

Moving to next cell in another document

在另一个文档 Range 中工作时 TCN.docx 我在 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

为了更好地理解

已编辑:由 Cindy Meister 编辑问题后

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
    ...