2
votes

I have the following code:

Dim todaysDate

todaysDate = Day(Now)

Select Case todaysDate

    Case 1 to 5
        Msgbox("1 to 5")

    Case 23 to 31
        Msgbox("23 to 31")
    End Select

When I put it in a VBS file and run it, i get "Expected Statement" for Line 9 Char 10.

If i copy and paste the code into Excel's VBA editor, it runs fine with no errors.

Any ideas why it isnt working in a VBS file?

2

2 Answers

3
votes

In VBScript, the Case statement doesn't allow the x To y syntax. You're only allowed to use a single value or a comma-delimited list of values. You'll have to use an If/ElseIf statement instead.

0
votes

Try the following:

Select Case TRUE 'this is important, HT to Cheran

    Case todaysDate >= 1 And todaysDate <=5
        Msgbox("1 to 5")

    Case todaysDate >=23 And todaysDate <=31
        Msgbox("23 to 31")

    Case else
        'However you want to handle this
End Select