-
Solved: Help to solve a little mistery
I'm trying to ask for a date and provide as default today's date. I tried with the following
Date= Application.InputBox("date (month/day/year)", "date", now(), , , , , 1)
worked fine. Then since it shows also the time, which is not needed I changed now() with today() as shown below and it tells me
compile error:
Sub or Function not defined
Date= Application.InputBox("date (month/day/year)", "date", TODAY(), , , , , 1)
What am I doing wrong?
Thanks a lot
-
try this
[VBA]Date = Application.InputBox("date (month/day/year)", "date", Format(Now(), "mm/dd/yyyy"), , , , , 1)
[/VBA]
-
Tnx JKwan, it worked!!
so basically today() cannot be used in VBA...?
-
Today() is not a VBA function.
I would use Date rather than Now() in VBA since time was not needed and avoid using named functions for variable names.
If you love Today() then use Evaluate().
[VBA]
Sub test()
Dim d As Date
d = Application.InputBox("date (month/day/year)", "date", Format(Date, "mm/dd/yyyy"), , , , , 1)
MsgBox Format(d, "mm/dd/yyyy"), , "test"
End Sub
Sub test2()
Dim d As String
d = Application.InputBox("date (month/day/year)", "date", Format(Evaluate("Today()"), "mm/dd/yyyy"), , , , , 1)
MsgBox Format(d, "mm/dd/yyyy"), , "test2"
End Sub[/VBA]
-
Thanks Ken :-).
So basically one can use Evaluate ("no VBA Funct.") anytime one has a function that cannot be used directly in VBA, correct?
Thanks again :-)!
-
Normally, for a worksheet function, I use WorkSheetFunction.FunctionName(input parameters) or Application.WorksheetFunction.FunctionName(input parameters). For some functions not available via WorkSheetFunction method as in this case, use Evaluate().
Brackets, [], can be used to directly Evaluate some worksheetfunctions and useful for quick array notation.
-
Thanks a lot!! Very helpful :-)
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules