【问题标题】:Moving to next cell in another document移动到另一个文档中的下一个单元格
【发布时间】:2016-08-17 15:15:59
【问题描述】:

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

为了更好的理解

【问题讨论】:

    标签: vba ms-word word-2007 word-2003


    【解决方案1】:

    已编辑:经过 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
        ...
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2018-03-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-04-22
      • 2018-07-29
      • 1970-01-01
      相关资源
      最近更新 更多