Insert current date into Excel template when creating

I am creating an excel template (* .xlt) for the user here, and one of the things I want to do is insert the current date when creating a new document (i.e. when double-clicking the file in Windows Explorer). How to do it?

Update: I should have added that I would prefer not to use VSB (macro). If this is the only option, let it be, but I would really like the user to remember to click the "allow macro content" button.

+3
source share
3 answers

You can use the worksheet function = TODAY (), but obviously this will be updated to the current date whenever the workbook is recounted.

, , - , 1729, Workbook_Open:

Private Sub Workbook_Open()
    ThisWorkbook.Worksheets("Sheet1").Range("A1").Value = Date
End Sub

, , ( VBA IDE Tools | Digital Signature...) , (. http://msdn.microsoft.com/en-us/library/ms995347.aspx). , , .

+4

excel -

XLSTART Book.xlt, C:\Program Files\Microsoft Office\Office\XLStart\

, Workbook_Open

Private Sub Workbook_Open()
    If ActiveWorkBook.Sheets(1).Range("A1") = "" Then
        ActiveWorkBook.Sheets(1).Range("A1") = Now
    End If
End Sub

VBA , - .

+2

To avoid VBA, and if you think your users can follow the instructions, you can ask them to copy the date and then paste in special values> to set the date so that it does not change in the future.

0
source

Source: https://habr.com/ru/post/1696648/


All Articles