跳到主要內容

如何在Excel頁眉或頁腳中插入上次修改日期?

在Excel中,我們可以快速輕鬆地將工作簿信息(例如文件名,文件完整路徑,當前日期等)插入頁眉或頁腳。 但是,您是否嘗試過將工作表的最後修改日期和時間插入其中? Excel不提供此功能,我們無法在頁眉或頁腳中插入上次修改的日期,在這裡,我將向您介紹一種方便的解決方法。

使用VBA代碼在Excel頁眉或頁腳中插入上次修改日期

使用Kutools for Excel插入上次修改日期/創建日期/用戶到頁眉/頁腳 好主意3


箭頭藍色右氣泡 使用VBA代碼在Excel頁眉或頁腳中插入上次修改日期

以下簡單的VBA代碼可以幫助您將工作表的上次保存的日期和時間插入頁眉或頁腳,請按以下步驟操作:

1。 激活您想要將上次修改日期插入頁眉或頁腳中的工作表。

2。 然後按住 ALT + F11 鍵打開 Microsoft Visual Basic for Applications窗口.

3。 在左邊 VBA項目 窗格,雙擊 的ThisWorkbook 打開 模塊,然後復制並粘貼以下代碼。

VBA代碼:在頁眉或頁腳中插入上次修改的日期

Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean)
ActiveSheet.PageSetup.CenterHeader = "Last saved: " & Format(Date, "mm-dd-yy") & " " & Time
End Sub

doc-insert-last-saved-date-header-1

4。 然後保存並關閉此代碼,然後單擊 瀏覽 > 頁面佈局 查看結果。 您會看到最後修改的日期和時間已插入到中心標題中。 查看屏幕截圖:

doc-insert-last-saved-date-header-2
-1
doc-insert-last-saved-date-header-3

筆記:

1.當您修改並保存Excel文件時,上次修改的日期和時間會自動更新。

2.如果您需要將最後保存的日期和時間插入到左側頁眉/頁腳,右側頁眉/頁腳或中心頁腳中,則只需將上面代碼中的CenterHeader更改為您的請求。


箭頭藍色右氣泡 使用Kutools for Excel插入上次修改日期/創建日期/用戶到頁眉/頁腳

使用Kutools for Excel,您可以使用插入工作簿信息工具將工作簿信息快速插入頁眉,頁腳或單元格。

Excel的Kutools, 與以上 300 方便的功能,使您的工作更加輕鬆。 

安裝後 Kutools for Excel,請執行以下操作:(立即免費下載Kutools for Excel!)

點擊 Kutools 加 > 工作簿 >插入工作簿信息,然後在彈出的對話框中,檢查要插入的信息,然後轉到 插入於 部分,檢查 範圍, or 頁腳 選項,並指定在左側頁眉/頁腳,中間頁眉/頁腳或右側頁眉/頁腳處插入以滿足您的需要。
doc插入工作簿信息
doc插入工作簿信息

箭頭藍色右氣泡 插入工作簿信息


相關文章:

獲取並在單元格中插入創建時間和上次修改時間

最佳辦公生產力工具

🤖 Kutools 人工智慧助手:基於以下內容徹底改變數據分析: 智慧執行   |  生成代碼  |  建立自訂公式  |  分析數據並產生圖表  |  呼叫 Kutools 函數...
熱門特色: 尋找、突出顯示或識別重複項   |  刪除空白行   |  合併列或儲存格而不遺失數據   |   沒有公式的回合 ...
超級查詢: 多條件VLookup    多值VLookup  |   跨多個工作表的 VLookup   |   模糊查詢 ....
高級下拉列表: 快速建立下拉列表   |  依賴下拉列表   |  多選下拉列表 ....
欄目經理: 新增特定數量的列  |  移動列  |  切換隱藏列的可見性狀態  |  比較範圍和列 ...
特色功能: 網格焦點   |  設計圖   |   大方程式酒吧    工作簿和工作表管理器   |  資源庫 (自動文字)   |  日期選擇器   |  合併工作表   |  加密/解密單元格    按清單發送電子郵件   |  超級濾鏡   |   特殊過濾器 (過濾粗體/斜體/刪除線...)...
前 15 個工具集12 文本 工具 (添加文本, 刪除字符,...)   |   50+ 圖表 類型 (甘特圖,...)   |   40+ 實用 公式 (根據生日計算年齡,...)   |   19 插入 工具 (插入二維碼, 從路徑插入圖片,...)   |   12 轉化 工具 (數字到單詞, 貨幣兌換,...)   |   7 合併與拆分 工具 (高級合併行, 分裂細胞,...)   |   ... 和更多

使用 Kutools for Excel 增強您的 Excel 技能,體驗前所未有的效率。 Kutools for Excel 提供了 300 多種進階功能來提高生產力並節省時間。  點擊此處獲取您最需要的功能...

產品描述


Office選項卡為Office帶來了選項卡式界面,使您的工作更加輕鬆

  • 在Word,Excel,PowerPoint中啟用選項卡式編輯和閱讀,發布者,Access,Visio和Project。
  • 在同一窗口的新選項卡中而不是在新窗口中打開並創建多個文檔。
  • 將您的工作效率提高 50%,每天為您減少數百次鼠標點擊!
Comments (9)
No ratings yet. Be the first to rate!
This comment was minimized by the moderator on the site
Why do I have to load the VB code into 'ThisWorkBook' of the VBAproject for every new workbook created? I would think that if I loaded the VB code into 'ThisWorkBook' of VBAHOME (PERSONAL.XLSB) if would be retained and available cresting new workbooks
This comment was minimized by the moderator on the site
Just tried it after moving the center header to the left footer. Didn't work. What I saved at 1:20 pm still recorded as 1:00 pm. Your help would be most appreciated. BTW, my spreadsheet was created as Excel 2007, and I made changes at the library on Excel 2016. Generally, I can go back and forth between versions with no problems.
Also, I didn't realize my name would be published. Any chance of changing it to Nancy E.?
Many thanks!
This comment was minimized by the moderator on the site
THANK YOU! That was invaluable. Who'd believe that Microsoft would exclude such an important function! What about Word? Is it done the same way now?
This comment was minimized by the moderator on the site
Thanks for the Info.
This comment was minimized by the moderator on the site
perfect.very useful ;-)
This comment was minimized by the moderator on the site
I did this and it works. I saved the file as .xlsx and closed it. Now, when I open it, I open the VBA coding window but I am not able to find this chunk of code to edit it. I would like to play with location and remove time. Thank you.
This comment was minimized by the moderator on the site
@John R. When you get to the VBA coding window, on the left section of the screen you need to double-click "ThisWorkbook" to open the right section of the screen. Then in the right section (at the top) you need to select "Workbook" and "BeforeSave". That should hopefully show you the chunk of code that you're looking for.
This comment was minimized by the moderator on the site
I tried this technique but could only get it to show up on one sheet. Help?
This comment was minimized by the moderator on the site
Thanks! I maintain an employee phone number and extension list. People get hired, quit, move to different extensions. If someone wants a copy I print it off, but it only showed the date and time it was printed -- not necessarily the most current information. It was difficult to tell if you had two different copies which one was the most up-to-date. Showing the last time the file was saved will do what I wanted!
There are no comments posted here yet
Please leave your comments in English
Posting as Guest
×
Rate this post:
0   Characters
Suggested Locations