Quantcast
Channel: Active questions tagged excel - Stack Overflow
Viewing all articles
Browse latest Browse all 88066

Activate/select a word-document and find the value of active cell in that document

$
0
0

I want to select a cell and use the value-text in that cell, to search/find in a specific word-document (xxxxxx.docx). This document is already opened, together with other word-documents.

The code underneath does what I want… almost. It OPENS the specific document, and then finds the text. But the document is already open, so it doesnt work good for the job. It just needs to be selected/activated and not opening again.

Does someone knows how to manage this: Select any cell, use the value in that cell, activate/select xxxxxx.docx, and search that value.

** It is most important the found text is shown in the document, that has to show/pop-up in the screen. All this is meant to navigate fast in this document.

Sub FindName()

    Dim wrdApp As Object
    Dim wrdDoc As Object
    Set wrdApp = CreateObject("Word.Application")
    wrdApp.Visible = True
    Set wrdDoc = wrdApp.Documents.Open("C:\xxxxxx.docx")
    Dim FindWord As String
    Dim result As String
    FindWord = ActiveCell.Value
    wrdDoc.SelectAllEditableRanges

    With wrdDoc.ActiveWindow.Selection.Find
        .Text = FindWord
        .Replacement.Text = ""
        .Forward = True
        .Wrap = 1
        .Format = False
        .MatchCase = False
        .MatchWholeWord = False
        .MatchWildcards = False
        .MatchSoundsLike = False
        .MatchAllWordForms = False
    End With

    wrdDoc.ActiveWindow.Selection.Find.Execute

End Sub

Viewing all articles
Browse latest Browse all 88066

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>