[mso] Re: Help with some Code in Word

  • From: "Chinell, David F \(GE Indust, Security\)" <David.Chinell@xxxxxx>
  • To: <mso@xxxxxxxxxxxxx>
  • Date: Tue, 24 Apr 2007 17:25:56 -0400

Geoff and all:

Okay, here's another iteration of the subroutine. I can't remember what
the table is supposed to look like, so I've just assumed there's a
MacroButton in a cell that the user clicks.

This is just one way of doing it, but I'm using an array and the Split
statement to extract and isolate the displayed color name, since it can
be any number of characters long.

I then test the value of this color name (which lands in the third slot
of the array, thoughtfully indexed "2") using the existing Select Case
structure. I don't DO anything to the document in that select case, I
just save the next color name in the ring and the desired cell color.

I don't color the text any more. Rather, I rely on Word's built-in
smarts about when to reverse out the text color.

I recreate the entire macrobutton field code using the new color name
and the Join statement. I then change the color of the cell.

In the Split and Join statements, I've been sloppy and just relied on
the default delimiter being a space character. I haven't used the
argument names either. Being less sloppy, I'd have written things like:

aryCode() =3D Split(Expression:=3DSelection.Fields(1).Code.Text,
Delimiter:=3D" ")

Bear

~~~~~~~~~~

Sub SymbolCarousel()

' SymbolCarousel Macro
' Macro created 19/04/2007 by Geoff Culbertson

Dim aryCode() As String
Dim strName As String
Dim lngColor As Long

' Split the MacroButton code to isolate the
' color name being displayed

aryCode() =3D Split(Selection.Fields(1).Code.Text)

' Test the color name

' Ring to the next color name and set the
' desired cell color

Select Case aryCode(2)
  Case "Color"
    strName =3D "Red"
    lngColor =3D wdColorRed
  Case "Red"
    strName =3D "Amber"
    lngColor =3D wdColorGold
  Case "Amber"
    strName =3D "Green"
    lngColor =3D wdColorBrightGreen
  Case "Green"
    strName =3D "Color"
    lngColor =3D wdColorWhite
  Case Else
End Select

' Recreate the MacroButton code using the new
' color name, then set the cell color

aryCode(2) =3D strName
Selection.Fields(1).Code.Text =3D Join(aryCode)
Selection.Cells.Shading.Texture =3D wdTextureNone
Selection.Cells.Shading.BackgroundPatternColor =3D lngColor

End Sub

*************************************************************
You are receiving this mail because you subscribed to mso@xxxxxxxxxxxxx or 
MicrosoftOffice@xxxxxxxxxxxxxxxx

To send mail to the group, simply address it to mso@xxxxxxxxxxxxx

To Unsubscribe from this group, visit the group's homepage and use the dropdown 
menu at the top.  This will allow you to unsubscribe your email address or 
change your email settings to digest or vacation (no mail).
//www.freelists.org/webpage/mso

To be able to share files with the group, you must join our Yahoo sister group. 
 This group will not allow for posting of emails, but will allow you to join 
and share problem files, templates, etc.:  
http://tech.groups.yahoo.com/group/MicrosoftOffice . This group is for FILE 
SHARING ONLY.

If you are using Outlook and you see a lot of unnecessary code in your email 
messages, read these instructions that explain why and how to fix it:
http://personal-computer-tutor.com/abc3/v28/greg28.htm
*************************************************************

Other related posts: