Insert current date and time into header
This tutorial shows how to insert the current date and time into a header in a specific sheet using Excel and VBA
Insert sheet > Insert tab > Text group > Header & Footer > Select header area > Design tab > Header & Footer Elements group > Current Date > Insert separation sign > Current Time > Click anywhere on the sheet
1. Select the Insert tab. |
2. Select the Text group. 3. Click on Header & Footer. |
4. Select header area in which you want to show the current date and time. Note: In this example we have selected the center header area. |
5. Select the Design tab. 6. Click on Current Date in the Header & Footer Elements group. |
7. This will insert &[Date] in the selected header area which will show the current date. 8. Add the separation sign. Note: In this example we have used " - " as the separation sign between the current date and time. |
9. Click on Current Time in the Header & Footer Elements group. |
10. This will insert &[Time] in the selected header area, after the separation sign, which will show the current time. 11. Click anywhere on the sheet. |
Sub Insert_current_date_time_header()
'declare a variable
Dim ws As Worksheet
Set ws = Worksheets("Sheet1")
With ws.PageSetup
.CenterHeader = "&D - &T"
End With
End Sub
NOTES
Note 1: This VBA code will insert the current date and time, separate by a - sign with a space before and after it, into the center header area of "Sheet1".
Note 1: This VBA code will insert the current date and time, separate by a - sign with a space before and after it, into the center header area of "Sheet1".
RELATED TOPICS
Related Topic | Description | Related Topic and Description |
---|---|---|
Insert a header | How to insert a header | |
Insert a footer | How to insert a footer in a specific sheet | |
Insert page numbers into header | How to insert page numbers into a header in a specific sheet | |
Insert current and total page numbers into header | How to insert the current page number over total number of pages into a header in a specific sheet |