Add date when printing a file

DSLA

Active Member
Joined
Jun 6, 2005
Messages
296
Hi,

How can i add a date to the excel page when it is printed out?

Somekind of macro?
 

Some videos you may like

Excel Facts

Does the VLOOKUP table have to be sorted?
No! when you are using an exact match, the VLOOKUP table can be in any order. Best-selling items at the top is actually the best.

onlyadrafter

Well-known Member
Joined
Aug 19, 2003
Messages
5,703
Platform
  1. Windows
Hello,

Why not add the date in the Header or Footer?

or are you asking to add a date to the spreadsheet when Print is selected.

If so, put this code into the THIS_WORKBOOK code window

Code:
Private Sub Workbook_BeforePrint(Cancel As Boolean)
Range("A1").Value = Format(Now(), "mm/dd/yy")
End Sub
 

DSLA

Active Member
Joined
Jun 6, 2005
Messages
296
Yes that is what i meen, adding the date when printing out the document.

How do i use the code you sent?
(sorry for the noob question)
 

onlyadrafter

Well-known Member
Joined
Aug 19, 2003
Messages
5,703
Platform
  1. Windows
Hello,

Select TOOLS --> MACRO --> VISUAL BASIC EDITOR (or press ALT+F11)

In the new window select VIEW --> PROJECT EXPLORER

You should see somewhere, something that looks like Windows Explorer. One of which will be VBAProject (your file name) expand this folder and you will see This Workbook, double click this and a window will appear, headed your filename, this is where you need to post the code.
 

DSLA

Active Member
Joined
Jun 6, 2005
Messages
296

ADVERTISEMENT

Thanks, i got it working. Is there a way i can add also the Hours and Minutes?
 

onlyadrafter

Well-known Member
Joined
Aug 19, 2003
Messages
5,703
Platform
  1. Windows
Hello,

Change the code to this

Code:
Private Sub Workbook_BeforePrint(Cancel As Boolean) 
Range("A1").Value = Now()
End Sub
 

DSLA

Active Member
Joined
Jun 6, 2005
Messages
296

ADVERTISEMENT

Is there a way to insert the date data a specific cell on the excel sheet?
 

DSLA

Active Member
Joined
Jun 6, 2005
Messages
296
I noticed that it enters the date to every sheet on the excel file, i would only need it only to some of the sheets, how can i do that?
 

onlyadrafter

Well-known Member
Joined
Aug 19, 2003
Messages
5,703
Platform
  1. Windows
Hello,

Which sheets do you want this to work for? i.e. what are their names, and what position are they in from the left

e.g.

SHeet1, sheet2, sheet3


please give the names as a list as shown in the spreadsheet and specify which need the date code adding.
 

Watch MrExcel Video

Forum statistics

Threads
1,112,884
Messages
5,543,023
Members
410,583
Latest member
gazz57
Top