View Single Post
 
Old 12-10-2015, 09:54 PM
gmayor's Avatar
gmayor gmayor is offline Windows 7 64bit Office 2010 32bit
Expert
 
Join Date: Aug 2014
Posts: 4,137
gmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud of
Default

If this is Word VBA, the you don't have to get or create the Word object. You are already in Word. If the aim is to find the row number of the first instance of a cell containing the upper case letter 'H', then
Code:
Sub Macro1()

Dim wDoc As Document
Dim oRng As Range
Dim i As Integer
    Set wDoc = wApp.Documents.Open("C:\Users\alex.olczak\Document s\Proposal Automation\ERS Proposal\ERS Proposal Template Edit\PeopleParagraphMacro\TableTest.docx")
    Set oRng = wDoc.Range
    With oRng.Find
        Do While .Execute(FindText:="H", MatchCase:=True)
            If oRng.Information(wdWithInTable) Then
                oRng.HighlightColorIndex = wdYellow
                i = oRng.Rows(1).Index 'This line is not required to copy the row
                MsgBox i 'This line is not required to copy the row
                oRng.Rows(1).Range.Copy 'The row is copied to the clipboard
                Exit Do        'Find only the first instance
            End If
        Loop
    End With
    'Do something with the copied row e.g.
    Set oRng = wDoc.Range 'set a range to the document
    oRng.Collapse 0 'collapse the range to its end
    oRng.Paste 'Paste the found row at then end of the document
lbl_Exit:
    Exit Sub
End Sub
__________________
Graham Mayor - MS MVP (Word) (2002-2019)
Visit my web site for more programming tips and ready made processes www.gmayor.com
Reply With Quote