VBAbyMBA
VBAbyMBA

Reputation: 826

Moving to next cell in another document

While working in Range of another document TCN.docx I am getting Error of method or data member not found on rng.MoveRight unit:=Cell position.

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

for better understanding

enter image description here

Upvotes: 1

Views: 64

Answers (1)

user3598756
user3598756

Reputation: 29421

edited: after question editing by Cindy Meister

MoveRight is not a valid method for Range object while it is for Selection object

and there's no Cell value for unit enumeration, while wdCell is

to copy the element one cell to the right of the found one, use

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

Upvotes: 1

Related Questions