![]() |
#1
|
|||
|
|||
![]()
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 |
Tags |
find, table, vba |
Thread Tools | |
Display Modes | |
|
![]() |
||||
Thread | Thread Starter | Forum | Replies | Last Post |
Data validation,force cell to be filed with number if respective cell is not empty | nicholes | Excel Programming | 0 | 08-01-2015 09:08 AM |
![]() |
Bill Martz | Excel | 1 | 04-23-2015 07:57 PM |
Setting a particular table cell background color when an option button is selected in Word 2007 | a888 | Word VBA | 11 | 03-25-2015 05:33 AM |
Pivot Table Question- Can the table display in the order the boxes were checked/selected? | blackjack | Excel | 0 | 09-13-2014 08:57 PM |
![]() |
andrewballem | Word Tables | 2 | 11-12-2013 05:18 AM |