1

在处理Range另一个文档TCN.docx时,我得到了错误的method or data member not found位置rng.MoveRight unit:=Cell

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

为了更好地理解

在此处输入图像描述

4

1 回答 1

1

编辑:经过 Cindy Meister 的问题编辑

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

并且没有枚举Cell价值,而是unitwdCell

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

    ...
    rng.Find.Execute
    If rng.Find.Found = True Then
        rng.Select
        Selection.MoveRight unit:=wdCell
        Selection.Copy
    Else
    End If
    ...
于 2016-04-24T09:01:50.073 回答