Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 10-14-2011, 11:14 AM
cksm4 cksm4 is offline Find and Execute Windows XP Find and Execute Office 2007
Advanced Beginner
Find and Execute
 
Join Date: Aug 2010
Posts: 48
cksm4 is on a distinguished road
Default Find and Execute

Hello,

I am trying to find text in a table and then execute a command which involves focusing on a new selection/range. I know the change is my issue but I do not know how to overcome it. Any ideas??



Code:
 
With ActiveDocument
Selection.Find.ClearFormatting
With Selection.Find
   .Text = "TOC"
   .Replacement.Text = ""
   .Forward = True
   .Wrap = wdFindContinue
   .Format = False
   .MatchCase = False
   .MatchWholeWord = False
   .MatchWildcards = False
   .MatchSoundsLike = False
   .MatchAllWordForms = False
End With
While .Execute
    .MoveDown Unit:=wdLine, Count:=1
    .SelectCell
    ActiveDocument.Indexes.MarkEntry Range:=Selection.Range, _
        EntryAutoText:=SelectedText, CrossReference:="", CrossReferenceAutoText:="", _
        BookmarkName:="", Bold:=False, Italic:=False
Wend
End With
Thanks!
Reply With Quote
  #2  
Old 10-22-2011, 11:36 PM
macropod's Avatar
macropod macropod is offline Find and Execute Windows 7 64bit Find and Execute Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,956
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

Hi cksm4,

Try something along the lines of:
Code:
Sub Demo()
Dim tRng As Range
With Selection
  With .Find
    .ClearFormatting
    .Replacement.ClearFormatting
    .Text = "TOC"
    .Replacement.Text = ""
    .Forward = True
    .Wrap = wdFindContinue
    .Format = False
    .MatchCase = False
    .MatchWholeWord = False
    .MatchWildcards = False
    .MatchSoundsLike = False
    .MatchAllWordForms = False
  End With
  While .Find.Execute
    With .Range
      If .Information(wdWithInTable) = True Then
        Set tRng = .Tables(1).Cell(.Cells(1).RowIndex + 1, .Cells(1).ColumnIndex).Range
        tRng.End = tRng.End - 1
        ActiveDocument.Indexes.MarkEntry Range:=tRng, EntryAutoText:=.Text, _
          CrossReference:="", CrossReferenceAutoText:="", BookmarkName:="", Bold:=False, Italic:=False
      End If
    End With
  Wend
End With
End Sub
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
Reply

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
Find and Execute Is there a way to use "find/replace" to find italics words? slayda Word 3 09-14-2011 02:16 PM
Find and Execute VBA find or name a Table smed Word VBA 1 01-17-2011 02:18 PM
Find and Execute can Find/Replace NOT find something? Bobosmite Word 6 05-27-2010 08:09 PM
Find /Replace Help ilcaa Word 2 11-02-2009 08:41 AM
Find and Execute How do I call/execute an Excel macro from Access 2003 KramerJ Excel 2 05-11-2009 11:33 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 03:27 PM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2024 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft