Row Number of Selected Cell in Table
Hi
I am trying to write a VBA program to return the row number of the current selection. This would allow me to copy and paste the entire row which is found searching for a key word.
The code I have written so far seems to return the cell that the cursor was in before the code is run, and not the cell selected using Find.
Many thanks in advanced for any help with this,
Alex
Sub RowNumber()
Dim wApp As Word.Application
Dim wDoc As Word.Document
Dim i As Integer
'OPEN WORD IF NOT OPEN
Dim wObj As Word.Application
On Error Resume Next
' Get existing instance of Word if it exists.
Set wApp = GetObject(, "Word.Application")
If Err <> 0 Then
' If GetObject fails, then use CreateObject instead.
Set wApp = CreateObject("Word.Application")
End If
wApp.Visible = True
Set wDoc = wApp.Documents.Open("C:\Users\alex.olczak\Document s\Proposal Automation\ERS Proposal\ERS Proposal Template Edit\PeopleParagraphMacro\TableTest.docx")
'wDoc.Application.Selection.Find.ClearFormatting
wDoc.Application.Selection.Find.Replacement.ClearF ormatting
wDoc.Application.Selection.Find.Replacement.Highli ght = True
With wDoc.Application.Selection.Find
.Text = "H"
.Replacement.Text = "H"
.Forward = Flase
.Wrap = wdFindContinue
.Format = True
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
wDoc.Application.Selection.Find.Execute Replace:=wdReplaceAll
wDoc.Application.Selection.Find.Execute
wDoc.Application.Options.DefaultHighlightColorInde x = wdYellow
a = wDoc.Application.Selection.Range.Information(wdEnd OfRangeRowNumber)
a = wDoc.Application.Selection.Information(wdEndOfRang eRowNumber)
'wDoc.Application.Selection.GoTo
MsgBox a
End Sub
|