• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

VBA - WeekDay(Now) function giving Compile Error

alanj

New Member
Trying to practice using Subs with Subs.

This example isn't working, though:


Option Explicit


Sub Main()

Dim SubToCall As String

Select Case WeekDay(Now)

Case 1, 7: SubToCall = "Weekday"

Case Else: SubToCall = "Weekend"

End Select

Application.rn SubToCall


End Sub


Sub Weekend()

MsgBox "Today is a weekend"

End Sub


Sub WeekDay()

MsgBox "Today is a weekday, sucka!"

End Sub
 
Alan


Is this what you want?

[pre]
Code:
Sub Main()
Dim SubToCall As String
Select Case Application.WeekDay(Now())
Case 1, 7: SubToCall = "Weekday"
Case Else: SubToCall = "Weekend"
End Select
WeekStatus (SubToCall)
End Sub

Sub WeekStatus(SubToCall)
If SubToCall = "Weeday" Then
MsgBox "Today is a weekday"
Else
MsgBox "Today is a weekend"
End If

End Sub
[/pre]
 
Hi Alanj,


find below right code for your requirement.. will not show compile error..


Sub Main()

Dim SubToCall As String

Select Case Application.WeekDay(Now)

Case 1, 7: SubToCall = "Weekday"

Case Else: SubToCall = "Weekend"

End Select

Application.Run SubToCall


End Sub


Sub Weekend()

MsgBox "Today is a weekend"

End Sub


Sub WeekDay()

MsgBox "Today is a weekday, sucka!"

End Sub


Regards,

Krishna
 
Thanks Hui and Krishnaoptif.


Hui - your resulted in "Today is a weekend" for some reason (Today is Thursday).

Krishnaoptif's worked well.


So, the missing element was adding "Application." before the WeekDay function?

Thanks.
 
Back
Top