格式化公共函数的输出

时间:2014-12-04 00:11:08

标签: excel vba excel-vba

如何以日期格式获取IsMonday()的输出?当前函数的值为true或false。我试图将公共变量dt作为其他两个子程序的参数传递。

Option Explicit
Public dt As Date

Sub test2()
MsgBox Date

MsgBox dt

MsgBox IsMonday(dt)

End Sub

Public Function IsMonday(inputdate As Date) As Boolean

    Select Case Weekday(inputdate)
        Case vbMonday
            dt = Date - 3              
            'dt = Format(dt, "mmddyyyy")
        Case Else
            dt = Date - 1
            'dt = Format(Date - 1, "mmddyyyy")          
            'dt = Format(dt, "mmddyyyy")
    End Select

End Function

1 个答案:

答案 0 :(得分:0)

如果您尝试将值作为日期从函数传递,则必须将结果声明为Date ...

Public Function IsMonday(inputdate As Date) As Date

    Select Case Weekday(inputdate)
        Case vbMonday
            dt = Date - 3              
            'dt = Format(dt, "mmddyyyy")
        Case Else
            dt = Date - 1
            'dt = Format(Date - 1, "mmddyyyy")          
            'dt = Format(dt, "mmddyyyy")
    End Select
IsMonday = dt
End Function