If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below. |
|
|
Thread Tools | Display Modes |
#1
|
|||
|
|||
How do I get a macro to repeat itself?
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. |
#2
|
|||
|
|||
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.BackgroundPatternColorI ndex = 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/Macros...eateAMacro.htm Hope this helps. Shauna Kelly. Microsoft MVP. http://www.shaunakelly.com/word "Preacherman" wrote in message ... 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. |
#3
|
|||
|
|||
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 -- Greg Maxey A peer in "peer to peer" support Rockledge, FL To e-mail, edit out the "w...spam" in Preacherman wrote: 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. |
#5
|
|||
|
|||
Shauna Kelly,
Thanks for the idea. I haven't tried it yet, but it sure sounds like it will work. Preacherman "Shauna Kelly" wrote: 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.BackgroundPatternColorI ndex = 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/Macros...eateAMacro.htm Hope this helps. Shauna Kelly. Microsoft MVP. http://www.shaunakelly.com/word "Preacherman" wrote in message ... 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. |
#6
|
|||
|
|||
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 "Greg Maxey" wrote: 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 -- Greg Maxey A peer in "peer to peer" support Rockledge, FL To e-mail, edit out the "w...spam" in Preacherman wrote: 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. |
#7
|
|||
|
|||
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:-) -- Greg Maxey A peer in "peer to peer" support Rockledge, FL To e-mail, edit out the "w...spam" in Preacherman wrote: 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 "Greg Maxey" wrote: 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 -- Greg Maxey A peer in "peer to peer" support Rockledge, FL To e-mail, edit out the "w...spam" in Preacherman wrote: 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. |
Thread Tools | |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
Keyboard Shortcut Only Runs Part of the Macro | Jonnyboy117 | General Discussion | 2 | July 14th, 2004 08:27 PM |
Wrote a macro in visual basic editor, can't get it to repeat the action | iomighty | General Discussion | 5 | June 15th, 2004 12:25 AM |
word error | mac | General Discussions | 1 | May 6th, 2004 08:14 AM |
Macro | Nicole | Worksheet Functions | 4 | October 9th, 2003 09:53 PM |
Macro: How Can I Repeat Macro In Other Cells?? | Cloudhopper | Worksheet Functions | 1 | October 9th, 2003 02:34 AM |