How do I stop =NOW() or =TODAY() data changing when file saved and then reopened

  • Thread starter Thread starter slopey
  • Start date Start date
S

slopey

I have a form which uses =NOW() in seperate cells to set the date an
another to set the time - cells formatted accordingly - but I want th
date and time to be saved when I close and save the file so that when
open the file again to review the form contents, the date and tim
remain as set when originally opened.

I used the non-asterisked date format but it still updates when th
file is opened
 
Hi Slopey!

Ctrl + ; gives you the system date
Ctrl + : gives you the system time
Ctrl + ; <space> Ctrl + : gives your system date and time

None of these are updated when the workbook is recalculated.

You can apply format on these to taste.

--
Regards
Norman Harker MVP (Excel)
Sydney, Australia
(e-mail address removed)
Excel and Word Function Lists (Classifications, Syntax and Arguments)
available free to good homes.
 
Slopey
use this - copy it into a VB Module ALT+F11, Insert Module
then paste the function

Function mytime()
Static mt
mt = Now()
mytime = mt
End Function

to use the function type =mytime(). Format the cell as you
like

to update the function press Ctrl + alt + F9

Regards
Peter
 
Just a thought:
to update the function press Ctrl + alt + F9

or put another way, anytime you do Ctrl+Alt+F9, it will update. If you
don't use that combination, then it may not be a problem.
 
Peter & Norman
Thanks for the help

As always it is not quite that simple

I need the auto update facility of =Now() when I load the blank but
need to save the values when I save the form in another file.

The module function sets the date & time on the blank form and the
Ctrl+Alt+F9 is awkward to remember to do as I am not in that area of
the form.

Thanks
 
Hi slopey!

Is what your saying that you want to datestamp on opening but not
otherwise?

This is possible with a Workbook_Open event handling subroutine.

Or you could have a simple datestamp attached to a button.

But how do you want to treat a subsequent opening of the workbook?

I think you need to define precisely when you want the datestamping to
take place.

--
Regards
Norman Harker MVP (Excel)
Sydney, Australia
(e-mail address removed)
Excel and Word Function Lists (Classifications, Syntax and Arguments)
available free to good homes.
 
Thanks
I have a blank estimate form as a file.

When I get a call the form is opened and I then want it date stamped
with date and time in two seperate cells - =Now() works perfectly for
this.

When the caller has finished and I have quoted I save the estimate
sheet to a file so that I have a record of the prices etc quoted and
when.
I therefore need the time and date stamp to be retained as values so
that I can trace what I quoted and when - like a copy,special paste,
values.

The original form file has to remain untouched ready for the next
caller.

I tried the option of the module and now cannot get rid of the module
from the worksheet. I cannot see it to delete it anywhere albeit shows
up in list under UDF.

Hope this is clearer.

Many thanks.
 
Hi slopey!

Looks like two points here but please confirm.

1. You want to freeze the date / time when you save
2. You *only* want to do this if you are saving under a different name
than your original form.

To get rid of that worksheet_change subroutine

Right click the sheet that it operates on.
Select "View Code"
Select the code and Cut

--
Regards
Norman Harker MVP (Excel)
Sydney, Australia
(e-mail address removed)
Excel and Word Function Lists (Classifications, Syntax and Arguments)
available free to good homes.
 
Hi Slopey!

You might use this approach:

Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As
Boolean)
If Application.ActiveWorkbook.Name <> "testsave.xls" Then
If Range("Datecell").Value = "" Then
Range("Datecell").Value = Now
End If
End If
End Sub

However, this doesn't seem to fire for a Before SaveAs case and the
new workbook could be closed without the date stamp unless there is
another change.

Unless anyone has a way around this I'd use a Workbook_BeforeClose
event handler like this:

Private Sub Workbook_BeforeClose(Cancel As Boolean)
If Application.ActiveWorkbook.Name <> "testsave.xls" Then
If Range("Datecell").Value = "" Then
Range("Datecell").Value = Now
Application.ActiveWorkbook.Save
End If
End If
End Sub

I can't say I'm happy with this and I'd recommend waiting to see if
anyone comes up with a better suggestion. Very likely in my view.

--
Regards
Norman Harker MVP (Excel)
Sydney, Australia
(e-mail address removed)
Excel and Word Function Lists (Classifications, Syntax and Arguments)
available free to good homes.
 
Hi Norman
Many thanks for giving this matter so much thought.
I must admit to getting somewhat lost within the arguments but wil
take your word for it - perhaps I ought to buy the book!!

This is much the same issue as the person posted on 2/1/04 (by New t
Excel) wanting an invoice number counter - another problem I have.

As you advise I'll sit tight for now and see if any other replies com
in.

Thanks again for your help
 
Hi slopey!

Keep watching! I'm certain that my approach is not the best but can't
seem to find / think of a better one.

--
Regards
Norman Harker MVP (Excel)
Sydney, Australia
(e-mail address removed)
Excel and Word Function Lists (Classifications, Syntax and Arguments)
available free to good homes.
 
That first routine fired for me when I did File|SaveAs.

Maybe you disabled events while testing???

I would watch out for upper and lower case, though:

if lcase(me.name) <> lcase("testsave.xls") then
 
Hi Dave!

Thanks for the test. I'll give it a few more runs. Also for upper /
lower case caution.

--
Regards
Norman Harker MVP (Excel)
Sydney, Australia
(e-mail address removed)
Excel and Word Function Lists (Classifications, Syntax and Arguments)
available free to good homes.
 
was this problem resolved

i have a template which used the =now() fuction; i want to save that as a permanent date when the file is saved..

thanks

----- slopey > wrote: ----

I have a form which uses =NOW() in seperate cells to set the date an
another to set the time - cells formatted accordingly - but I want th
date and time to be saved when I close and save the file so that when
open the file again to review the form contents, the date and tim
remain as set when originally opened

I used the non-asterisked date format but it still updates when th
file is opened
 
Why, do you need to know also?

--

HTH

Bob Phillips
... looking out across Poole Harbour to the Purbecks
(remove nothere from the email address if mailing direct)

kev hancock said:
was this problem resolved?

i have a template which used the =now() fuction; i want to save that as a
permanent date when the file is saved...
 
Kev, you could use a macro in the before save event to change the =now() to
a valve, like this, with your date in A1, is this what you need?

Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As
Boolean)
Range("A1") = Range("A1").Value
End Sub

--
Paul B
Always backup your data before trying something new
Please post any response to the newsgroups so others can benefit from it
Feedback on answers is always appreciated!
Using Excel 2000 & 97
** remove news from my email address to reply by email **
kev hancock said:
was this problem resolved?

i have a template which used the =now() fuction; i want to save that as a
permanent date when the file is saved...
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top