如何在excel工作表的页眉或页脚中显示最后修改时间
时间:2023-11-21 17:08:39
有时需要在工作表的页眉或页脚中显示最后修改的日期和时间,在Excel中可以用下面的VBA代码来实现,步骤如下:
例如在页眉的中部显示工作簿最后保存时间,按Alt+F11打开VBA编辑器,双击“工程”窗口中的“ThisWorkbook”,然后在代码窗口中粘贴下列代码:
Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean)
ActiveSheet.PageSetup.CenterHeader = "最后修改时间:" + Format(Now, "yyyy-mm-dd hh:mm:ss")
End Sub
这样,每次保存工作簿,该代码会在当前活动工作表的页眉中显示最后修改的日期和时间。
如果要在单元格中显示最后修改时间,可用下面的自定义函数,方法是在VBA编辑器中单击菜单“插入→模块”,在代码窗口中输入下面的代码:
Function LST()
Application.Volatile
LST = Format(Now, "yyyy-mm-dd hh:mm:ss")
End Function
然后保存工作簿,在单元格中输入公式:
=LST()
将返回最后保存的日期和时间。Application.Volatile语句将该自定义函数标记为易失性函数,其作用是当任意单元格进行计算时,该自定义函数都将重新进行计算。
标签:函数,时间,自定义,页眉,Excel函数
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
怎么在Word2010中启用或禁用Office加载项
2023-01-09 00:38:00
![](https://img.aspxhome.com/file/2023/5/21995_0s.jpg)
excel中插页码的教程
2023-05-09 17:26:22
Win10系统如何进行瘦身优化?Win10系统优化流畅设置
2022-10-29 12:22:22
![](https://img.aspxhome.com/file/2023/7/53047_0s.png)
Excel怎么预防数据错误
2022-05-09 11:48:35
![](https://img.aspxhome.com/file/2023/1/35981_0s.gif)
excel中按降序进行排列的教程
2022-04-28 08:23:11
Excel中2010版使用自定义名称简化计算公式的操作技巧
2022-05-29 09:21:07
excel如何找出普通鼠标、光电鼠标的单元格
2022-06-13 20:04:12
![](https://img.aspxhome.com/file/2023/7/a156957_0s.png)
excel表格怎么设置打印选定区域
2023-02-09 23:30:00
Word中编号一(一)1(1)1)①怎么分级
2023-07-20 19:51:23
![](https://img.aspxhome.com/file/2023/0/31680_0s.png)
怎么让WPS文字并排显示两页
2023-11-30 18:33:18
![](https://img.aspxhome.com/file/2023/9/a163889_0s.jpg)
win10比win7占内存大吗
2023-11-08 10:53:13
![](https://img.aspxhome.com/file/2023/7/48347_0s.jpg)
如何使用Word 2016辅助功能检查?
2022-10-25 20:12:38
![](https://img.aspxhome.com/file/2023/9/23519_0s.jpg)
07版的excel的桌面图标怎么改回来
2023-07-30 07:41:52
![](https://img.aspxhome.com/file/2023/3/36563_0s.jpg)
Excel表格输入身份证数字就变了乱码怎么办?
2023-09-23 06:54:50
![](https://img.aspxhome.com/file/2023/3/a156933_0s.jpg)
iOS 16 中相册重复项目功能使用方法
2023-06-14 12:13:46
![](https://img.aspxhome.com/file/2023/8/45088_0s.png)
word中如何插入excel表格
2022-10-26 18:55:41
![](https://img.aspxhome.com/file/2023/7/33657_0s.jpg)
Excel输入人名时使用分散对齐
2023-09-14 05:00:58
![](https://img.aspxhome.com/file/2023/7/37147_0s.png)
Excel中如何冻结第一行.第一列的技巧
2023-12-02 00:53:53
![](https://img.aspxhome.com/file/2023/4/38144_0s.jpg)
Win10提示systemserviceexception蓝屏代码怎么办?
2023-02-05 01:39:11
![](https://img.aspxhome.com/file/2023/7/52947_0s.png)
确保Excel中的数据导入数据库不要出错
2023-03-21 15:34:48