excel中的静态时间戳 [英] Static timestamp in excel

查看:320
本文介绍了excel中的静态时间戳的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望能够在点击按钮时添加一个时间戳给一个excel单元格。不幸的是,= Now()将始终更新为当前时间,因此不是静态的。

I'd like to be able to add a timestamp at the click of a button to an excel cell. Unfortunately doing =Now() will always update to the current time, and thus is not static.

我可以在记事本中做F5,然后将其传输到excel,但是

I could do F5 in notepad, and then transfer it to excel, but i'd rather cut out the middle man.

谢谢。

推荐答案

p>在单元格旁边创建一个按钮。

Create a button next to a cell.

然后对于该按钮的onclick事件中的VBA代码,请执行以下操作:

Then for the VBA code inside of that button's "onclick" event do something like this:

Sheets("Sheetname").Range("C1").value = time()

或为日期&时间

Or for date & time

Sheets("Sheetname").Range("C1").value = Now()

只有当按钮被点击时,该单元格的值才能设置为当前时间。

Either way only when the button is clicked will the value of that cell be set to the current time.

注意:

如果您从未将按钮对象插入到Excel中, - Excel 2003,2007和2010的步骤指南

If you've never inserted a button object into excel here is a step-by-step guide for Excel 2003,2007, and 2010

http://www.excel-vba-easy.com/vba-how-to-create-macro-excel.html #create-macro-excel-2003

更新:

如果您只想将时间戳添加到当前选定的单元格,请使用以下代码行:

If you only want to add the timestamp to the currently selected cell then use the following line of code:

ActiveCell.value = Now()

这篇关于excel中的静态时间戳的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆