Microsoft Office Forums

Go Back   Microsoft Office Forums > >

 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
  #1  
Old 09-30-2015, 04:35 AM
jc491's Avatar
jc491 jc491 is offline Windows 7 64bit Office 2013
VBA Novice
 
Join Date: Sep 2015
Location: UK
Posts: 55
jc491 is on a distinguished road
Default VBA Table – Search All Tables - Find & Replace Text in Table Cell With Specific Background Color

Hi All,

I would like some help and advice on how to put this macro together.
I have searched the forum and not yet found a solution although I am sure a similar one exists.
My apologies if it's already been solved.

Situation:
I have many tables in a document.
I need to search ALL the Tables and find table cells that contain:
· A specific back ground Color
· Find and Replace text in that cell ONLY - e.g. % with CB



Code:
  Sub FindTableText()
     
   
  Dim aTable As Table, oCell As Cell
      For Each aTable In ActiveDocument.Tables
          For Each aCell In aTable.Range.Cells
   
  ' if background shading is a specific color
   
  Selection.Shading.BackgroundPatternColor = RGB( 63, 123, 196 )
   
   'Find text in the cell and replace 

  With Selection.Find
          .Text = "%"
          .Replacement.Text = " CB1"
          .Forward = True
          .Wrap = wdFindContinue
          .Format = False
          .MatchCase = False
          .MatchWholeWord = False
          .MatchWildcards = False
          .MatchSoundsLike = False
          .MatchAllWordForms = False
      End With
      Selection.Find.Execute Replace:=wdReplaceAll
   
   Next aCell
   
      Next aTable
      End Sub
I am not sure how to put this together.

If anyone can advise, I would be really grateful.

Many thanks for your time in advance
J
Reply With Quote
 



Similar Threads
Thread Thread Starter Forum Replies Last Post
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
Macro to search warning text style and replace the text color rohanrohith Word VBA 3 11-27-2014 01:08 PM
How to remove background color in a table that isn't there but is there? pintree3 Word 5 10-27-2014 10:23 AM
Word VBA Find Table Text Shading Colour and replace with another QA_Compliance_Advisor Word VBA 10 09-19-2014 08:36 AM
how to search and replace BOLD text >> font color change? dylansmith Word 4 03-12-2013 09:51 PM

Other Forums: Access Forums

All times are GMT -7. The time now is 03:51 AM.


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