View Single Post
  #5   Report Post  
Posted to microsoft.public.excel.programming
Gordo Gordo is offline
external usenet poster
 
Posts: 4
Default using now() function not in a cell

Yes, used code exactly as shown.

tried first in a Sub and then a Function as follows:

Function Mygettime() As String
Dim S As String
S = Format(now, "dd-mmm-yyyy hh:mm:ss")
Debug.Print S

End Function

I get the compile error when I try and run it.

I'm using Excel 2003, and Microsoft Visual Basic 6.3, if that makes any
difference..

Best regards,

Gord




Chip Pearson wrote:
The code works fine for me. Did you use the code exactly as shown? Just to
be sure, did you put the code within a Sub or Function procedure?


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com
(email address is on the web site)

"Gordo" wrote in message
ups.com...
Thanks for your response Chip, I get a compile error when I try to run
that though. the now is highlighted and the error message is 'Expected
Function or variable'
I've tried it with the function brackets as well with the same result.

Best regards,
Gord

Chip Pearson wrote:
I'm not quite clear on what question is, but you can get the current time
in
a formatted string with code like

Dim S As String
S = Format(Now, "dd-mmm-yyyy hh:mm:ss")
Debug.Print S


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com
(email address is on the web site)


"Gordo" wrote in message
ups.com...
Hi there,

I'm trying to use the Now() function without accessing a cell in the
spreadsheet. Trying to assign the datetime to a string for a log file,
but I don't want to have to access the worksheet when doing it. Any
ideas?

Cheers