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?
 

Excel Facts

Select a hidden cell
Somehide hide payroll data in column G? Press F5. Type G1. Enter. Look in formula bar while you arrow down through G.

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.
 

Forum statistics

Threads
1,141,427
Messages
5,706,380
Members
421,446
Latest member
rena jhon

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Top