Microsoft Office Forums

Go Back   Microsoft Office Forums > >

 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
  #30  
Old 02-23-2020, 12:28 AM
Jennifer Murphy's Avatar
Jennifer Murphy Jennifer Murphy is offline Macro to highlight alternating sections of a table Windows XP Macro to highlight alternating sections of a table Office 2007
Competent Performer
Macro to highlight alternating sections of a table
 
Join Date: Aug 2011
Location: Silicon Valley
Posts: 234
Jennifer Murphy is on a distinguished road
Default

Quote:
Originally Posted by macropod View Post
As coded, the macro requires the heading row parameter to be present, to make it optional, it needs to be the last parameter:
Parms: Col=3, RGB=215,199,244, Hdrs=0
I'm not sure which code you are referencing. In the code I am working on, the keyword parameters can be written in any order. That's the whole purpose of keyword parameters, no?. If they must be in a specific order, there is little need for the keywords. They can just be coded as values:

Parms: 3, 215, 199, 244, 0

And in my code, all of them have defaults, so none of them are required. I loop through them one by one using a Case statement to determine which keyword it is and then process the value. I have actually come up with a couple more parameters as well, all of which can be coded in any order.

Code:
ParmStr = Trim(Selection.Tables(1).Range.Previous.Paragraphs.last.Range.Text)
ParmStr = Left(ParmStr, Len(ParmStr) - 1)
Tokens = Split(ParmStr, " ")
If UBound(Tokens) < 1 Then GoTo NoInDocParms
If UCase(Tokens(0)) <> ParmKW Then GoTo NoInDocParms
For i = 1 To UBound(Tokens)
  If Tokens(i) = "" Then
    GoTo Continue_i: End If
  KwVal = Split(UCase(Tokens(i)), "=")
  If UBound(KwVal) <> 1 Then
    msg = "Invalid keyword parameter (" & Tokens(i) & ")"
    MsgBox msg, vbOKOnly, MyName: GoTo ErrExit: End If
  Select Case Trim(KwVal(0))
    Case "COLUMN"
      ... process the Column value
    Case "Headers"                  'If it's a Headers parameter,
      ... process the Headers value
    Case "RGB1"
      ... process the RGB1 values
    Case "RGB2"
      ... process the RGB2 values
    Case "MATCHCASE"
      ... process the MatchCase value
    Case Else
      msg = "Invalid keyword parameter (" & Tokens(i) & ")"
      MsgBox msg, vbOKOnly, MyName: GoTo ErrExit
  End Select
Continue_i:
Next i
This is working as far as I have gotten. I'll post my complete code when it's ready.

Quote:
The macro can then be recoded as:
Code:
 . . .
For i = 0 To UBound(Split(StrParms, "="))
   Select Case i
     i = 0: C = Trim(Split(Split(StrParms, "=")(1), ",")(0))
     i = 1: StrRGB = Trim(Split(Split(StrParms, "=")(2), ",")(0))
     i = 2: Hdr = Trim(Split(StrParms, "=")(3))
   End Select
Next
 . . .
That's an interesting and clever way to do that. At first it looked odd to me, but I see that it avoids having to test for i > UBound at each step and then having a label to Go To or messy nested If statements.

But I've never seen a Case statement coded like that. It's always:
Code:
   Select Case i
      Case 0: C = Trim(Split(Split(StrParms, "=")(1), ",")(0))
      Case 1: StrRGB = Trim(Split(Split(StrParms, "=")(2), ",")(0))
      Case 2: Hdr = Trim(Split(StrParms, "=")(3))
   End Select
Reply With Quote
 



Similar Threads
Thread Thread Starter Forum Replies Last Post
Macro to highlight alternating sections of a table Macro to highlight a list of words bakerkr Word VBA 4 10-19-2017 02:23 PM
Macro to highlight alternating sections of a table Word 2010 VBA Print Macro - Specified Sections Benbon Word VBA 3 03-30-2017 02:31 PM
Macro to highlight alternating sections of a table Macro Question: Need help making a macro to highlight the first word in every sentence LadyAna Word 1 12-06-2014 10:39 PM
Macro to highlight alternating sections of a table Macro to highlight words bertietheblue Word VBA 9 07-01-2013 12:39 PM
find - reading highlight - highlight all / highlight doesn't stick when saved bobk544 Word 3 04-15-2009 03:31 PM

Other Forums: Access Forums

All times are GMT -7. The time now is 11:32 PM.


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