只需按一下按钮即可插入用户名和日期的宏 [英] Macro to insert username and date with a press of a button

查看:103
本文介绍了只需按一下按钮即可插入用户名和日期的宏的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

我已经构建了一个excel宏,只需按一下按钮,就可以在宏代码中指定的单元格中插入Windows用户名和日期。这是一个核对清单,没有一个,但有很多行,上面有一个按钮。我的
代码的问题是,如果你插入一个新的检查点(不是在最后但是在两个现有的检查点之间),新单元下面的点的代码必须改变,因为单元格数字明显改变。这不是很有效,特别是如果在插入的点之下有很多
点。有没有办法使这个代码更灵活,可以插入新行而不必更改其他行的代码?我正在考虑一个带有指定宏的按钮,它将用户名和
日期放在按钮左侧的一个单元格中。

I have build a excel macro that inserts your windows username and the date in a cell specified in the macro code with the press of a button. This is a check off list and has not one, but many lines with a button which does the above. The problem with my code is that if you insert a new check off point (not at the end but between two existing ones), the code of the points below the new one have to be altered as the cell numbers obviously change. This is not really efficient, especially if there are a lot of points beneath the one inserted. Is there a way to make this code more flexible, in a way that new lines can be inserted without having to change the code for the other lines? I was thinking about a button with an assigned macro that puts the username and date one cell to the left of the button.

所以这是我目前的情况:我有一个空单元格,右边有一个按钮。按钮具有以下分配给它的宏:

So here is my current situation: I have an empty cell with a button one cell to the right of it. Button has the following macro assigned to it:

Sub Handler_ClickC1()

范围("G7")= Environ(" Username" )& " " &安培;格式(日期,"dd-mm-yyyy")

结束子

Sub Handler_ClickC1()
Range("G7") = Environ("Username") & " " & Format(Date, "dd-mm-yyyy")
End Sub

此代码将Windows用户名和日期放在按钮左侧的单元格中。

This code puts windows username and date in the cell to the left of the button.

希望有人可以提供帮助。谢谢。

Hope someone can help. Thanks.

推荐答案

我使用一个按钮输入活动单元格中的文本:

I'd use a single button that enters the text in the active cell:

Sub Handler_ClickC1()
     ActiveCell = Environ("Username") & " " & Format(Date, "dd-mm-yyyy")
End Sub




这样,您不必添加新按钮如果插入行,则不必更改代码。


That way, you don't have to add new buttons if you insert rows, and you won't have to change the code.


这篇关于只需按一下按钮即可插入用户名和日期的宏的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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