Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Word / Tables / August 2004

Tip: Looking for answers? Try searching our database.

How do I get a macro to repeat itself?

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Preacherman - 15 Aug 2004 00:45 GMT
In Microsoft Word table I want to find a letter combination XX, shade that
cell, move to the next XX, shade it, etc. to the end of the table.  It works
beautifully in Word Perfect, and there should be a way to do it in Word.
Shauna Kelly - 15 Aug 2004 01:16 GMT
Hi Preacherman

You can achieve what you want without a macro, if you have Word 2002 or
2003. To do that, select the whole table. Use Edit > Find. In the Find What
box, type your "XX" text. Tick the "Highlight all items found in" box (which
should say "Current selection"). Click Find All, and then Close. You'll see
that Word has selected all cells containing "XX". Now, use Format > Borders
and Shading to shade the cells.

However, if you need a macro to do this, you could use the following code.
You'll need to change XX to the text you need to find.

Sub FindTextInATableAndShadeCell()
' Posted to microsoft.public.word.tables newsgroup
' Shauna Kelly 15/8/2004.

Dim oCell As Cell
Dim sTextToFind As String

If Selection.Information(wdWithInTable) = False Then
   MsgBox "Cursor is not currently in a table"
Else

   sTextToFind = "XX"

   'Find cells in the current table that contain
   'sTextToFind, and shade the cell
   Selection.Tables(1).Select
   With Selection.Find
       .ClearFormatting
       .Text = sTextToFind
       .Wrap = wdFindStop
       Do While .Execute
           Selection.Cells(1).Shading.BackgroundPatternColorIndex =
wdGray25
       Loop
   End With
End If
End Sub

If you're not sure what to do with the macro, see

http://www.gmayor.com/installing_macro.htm and

http://www.mvps.org/word/FAQs/MacrosVBA/CreateAMacro.htm

Hope this helps.

Shauna Kelly.  Microsoft MVP.
http://www.shaunakelly.com/word

> In Microsoft Word table I want to find a letter combination XX, shade that
> cell, move to the next XX, shade it, etc. to the end of the table.  It
> works
> beautifully in Word Perfect, and there should be a way to do it in Word.
Preacherman - 15 Aug 2004 03:27 GMT
Shauna Kelly,
Thanks for the idea.  I haven't tried it yet, but it sure sounds like it
will work.
Preacherman

> Hi Preacherman
>
[quoted text clipped - 51 lines]
> > works
> > beautifully in Word Perfect, and there should be a way to do it in Word.
Greg Maxey - 15 Aug 2004 01:53 GMT
Peacherman,

My code is likely rough, because I am just learning.  Something like this
might work

Sub ShadeDesigCells()
Selection.HomeKey wdStory
Selection.Find.ClearFormatting
With Selection.Find
 .Text = "XX"
 .Forward = True
 .Wrap = wdFindContinue
Do While Selection.Find.Execute = True
  Selection.EndKey
  With Selection.Cells.Shading
     .Texture = wdTextureNone
     .ForegroundPatternColor = wdColorAutomatic
     .BackgroundPatternColor = wdColorGray30
  End With
Loop
End With
End Sub

Signature

Greg Maxey
A peer in "peer to peer" support
Rockledge, FL
To e-mail, edit out the "w...spam" in gmaxey@whamspammvps.org

> In Microsoft Word table I want to find a letter combination XX, shade
> that cell, move to the next XX, shade it, etc. to the end of the
> table.  It works beautifully in Word Perfect, and there should be a
> way to do it in Word.
Greg Maxey - 15 Aug 2004 02:06 GMT
PM,

As I suspected, Shauna's appears far better.

Here is a slight adaptation with a input box for identifying the the find
text.
Sub FindTextInATableAndShadeCell()

Dim oCell As Cell
Dim fText As String

If Selection.Information(wdWithInTable) = False Then
   MsgBox "Cursor is not currently in a table"
Else

fText = InputBox$("Enter text to find.", "Find")

Selection.Tables(1).Select
 With Selection.Find
   .ClearFormatting
   .Text = fText
   .Wrap = wdFindContinue
   Do While .Execute
   Selection.Cells(1).Shading.BackgroundPatternColor = wdColorGray10
   Loop
 End With
End If
End Sub

Signature

Greg Maxey
A peer in "peer to peer" support
Rockledge, FL
To e-mail, edit out the "w...spam" in gmaxey@whamspammvps.org

> Peacherman,
>
[quoted text clipped - 23 lines]
>> table.  It works beautifully in Word Perfect, and there should be a
>> way to do it in Word.
Preacherman - 15 Aug 2004 03:29 GMT
Greg,
I think I will try Shauna's way first, but will come back for yours if I
have trouble with it.   By the way, are you related to Mark or Tibbs Maxey?
Preacherman

> Peacherman,
>
[quoted text clipped - 23 lines]
> > table.  It works beautifully in Word Perfect, and there should be a
> > way to do it in Word.
Greg Maxey - 15 Aug 2004 04:39 GMT
Shauna's

Suggestion to use the FIND dialog works great and her macro works well also.
I don't know Mark or Tibbs.  Unlike a Smith or Jones, there isn't that awful
many of us and I suppose going back far enough there could be relation some
way:-)

Signature

Greg Maxey
A peer in "peer to peer" support
Rockledge, FL
To e-mail, edit out the "w...spam" in gmaxey@whamspammvps.org

> Greg,
> I think I will try Shauna's way first, but will come back for yours
[quoted text clipped - 34 lines]
>>> the table.  It works beautifully in Word Perfect, and there should
>>> be a way to do it in Word.
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.