Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Case statement - not getting the correct value 1

Status
Not open for further replies.

OscarPCG

Technical User
Aug 12, 2004
15
US
I am working a routine that will check the style of each paragraph in a document. I am experimenting with the following code, but the variable just is not quite right. The code drops to the case else statement.
Code:
Sub CheckStyle()
Dim mPara As Paragraph

For Each mPara In ActiveDocument.Paragraphs
    SelectWhat = mPara.Style 'mPara.Format.Style.NameLocal
    
    Select Case SelectWhat
    Case SelectWhat = "AHead" ' must have the styles named in the document
        MsgBox "Yes this is good" & SelectWhat
    Case SelectWhat = "AlphaList"
         MsgBox "Yes this is good" & SelectWhat
    Case SelectWhat = "BHead"
         MsgBox "Yes this is good" & SelectWhat
    Case SelectWhat = "Body Text"
         MsgBox "Yes this is good" & SelectWhat
'...
    Case Else
        Debug.Print "Case Else" & SelectWhat
    End Select
Next
End Sub
Any ideas?

Thanks,
Oscar
 
Try:
Code:
Sub CheckStyle()
Dim mPara As Paragraph

For Each mPara In ActiveDocument.Paragraphs
    SelectWhat = mPara.Style 'mPara.Format.Style.NameLocal
    
    Select Case SelectWhat
    Case "AHead" ' must have the styles named in the document
        MsgBox "Yes this is good" & SelectWhat
    Case "AlphaList"
         MsgBox "Yes this is good" & SelectWhat
    Case "BHead"
         MsgBox "Yes this is good" & SelectWhat
    Case "Body Text"
         MsgBox "Yes this is good" & SelectWhat
'...
    Case Else
        Debug.Print "Case Else" & SelectWhat
    End Select
Next
End Sub

[red]"... isn't sanity really just a one trick pony anyway?! I mean, all you get is one trick, rational thinking, but when you are good and crazy, oooh, oooh, oooh, the sky is the limit!" - The Tick[/red]
 
Thank you, that works well.

- Now I just need to figure out how to get 160 of those things to run *quickly*. :)

Thanks,
Oscar
 
I seem to recognize something here....hmmmm.

You may want to consider exactly what you are trying to achieve.

A suggestion may also be to look up .InUse property of Style.

Gerry
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top