Link to home
Start Free TrialLog in
Avatar of pdvsa
pdvsaFlag for United States of America

asked on

Update Date - On Print?

Experts,

I have a hard coded date on a sheet.
I would like for the date to be updated upon print.
How can I do this?  

Not sure if there is something "canned" inside of Excel for this.  
I am using 2k7.

thank you
Avatar of kgerb
kgerb
Flag of United States of America image

Put this in the workbook code module.  Replace "Sheet1" and "A1" with appropriate sheet name and range.

Private Sub Workbook_BeforePrint(Cancel As Boolean)
Sheets("Sheet1").Range("A1") = Now()
End Sub

Open in new window

Kyle
Avatar of pdvsa

ASKER

Hi Kyle, sorry for not getting back earlier.   Was jam packed with work from real job.   Getting back to the question.  If i have a range set in the sheet and within that range there is a cell with a date then i think you are saying the cell with a date will be updated?   Thank you...  Do you happen to know hiw to do this without code?  I ask because i believe i would have to save as a macro enabled file.
Without macros there is really no way to make sure the update ONLY happens before a print event.  You have several other options though.  You could use a formula like

=Today()

in your cell.  Then just make sure the workbook has recalculated before you print.  Or you could put a date in header/footer.  This will auto-update.

Other than that there aren't many other options.  How exactly are you trying to update the cell?  I'm going on the assumption that you want the current date before the document is printed.  Even if this is not the case we might be able to come up with a formula to suit your needs.

Kyle
Avatar of pdvsa

ASKER

Kyle, I forgot about this question.  Sorry.  past few days have been very busy.

Is it true that if I put =Today() then once I open the file the date will be overridden?  If I dont save the file then there will be no changes.  I am looking for no update of the date unless I print.  

Example:  if I have a file with a lable such as "Date Printed" and open the file, the date printed would be changed to the current date if I use Today().

Not sure if I am making sense or you already covered it.  

thank you...
pdvsa,
The code provide in my first post will insert static text into the cell.  It will not update, ever, unless you print.  That's what the BeforePrint Event does.  It only fires when you print.  So you can do anything you want to the workbook, the date will not change until you print.  Let me know if you have further questions.

Kyle
Avatar of pdvsa

ASKER

Hi Kyle, my only issue with vba is that the other users if the file will not know what to do once they get the security message to enable macros.  

I was thinking that there could be fields much like in ms word that you can insert and apply a sort of code within excel without vba.  

Do you know what i am talking about?  

Thank you
ASKER CERTIFIED SOLUTION
Avatar of kgerb
kgerb
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of pdvsa

ASKER

Ok thank you.  It wasnt exactly what I was looking for but I will tell the other users to enable the macros on open or make a trusted area to avoid having to enable them each time you open teh file.  thank you Kyle.  I didnt mean to be difficult.
No problem.  I'm sorry I wasn't able to come up with a better solution for you.  If you want to take the time, you may want to ask another question and link to this one.  I am by no means the final authority on Excel.  There are plenty of MVP's that frequent this TA.  One of them might be able to give you exactly what you want.  If that happens I will be happy to get a mod to refund your points and withdraw this Q from the knowledge base.

Kyle