A Microsoft Office (Excel, Word) forum. OfficeFrustration

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.

Go Back   Home » OfficeFrustration forum » Microsoft Word » Tables
Site Map Home Register Authors List Search Today's Posts Mark Forums Read  

How do I get a macro to repeat itself?



 
 
Thread Tools Display Modes
  #1  
Old August 15th, 2004, 12:45 AM
Preacherman
external usenet poster
 
Posts: n/a
Default 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  
Old August 15th, 2004, 01:16 AM
Shauna Kelly
external usenet poster
 
Posts: n/a
Default

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  
Old August 15th, 2004, 01:53 AM
Greg Maxey
external usenet poster
 
Posts: n/a
Default

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.



  #4  
Old August 15th, 2004, 02:06 AM
Greg Maxey
external usenet poster
 
Posts: n/a
Default

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


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

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


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  
Old August 15th, 2004, 03:27 AM
Preacherman
external usenet poster
 
Posts: n/a
Default

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  
Old August 15th, 2004, 03:29 AM
Preacherman
external usenet poster
 
Posts: n/a
Default

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

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump

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


All times are GMT +1. The time now is 05:42 PM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 OfficeFrustration.
The comments are property of their posters.