【问题标题】:Change cell colour where vba has changed the value VBA更改 vba 已更改值 VBA 的单元格颜色
【发布时间】:2018-10-17 13:04:31
【问题描述】:

我是 VBA 新手,所以如果我听起来很愚蠢,请多多包涵-

背景信息: 我正在尝试自动化我们每季度更新的工作簿 - 我想通过更改这些单元格的背景颜色来显示我的 VBA 脚本更改了哪些单元格,以便我可以在开发脚本时跟踪它们。它也适用于对 VBA 知识为零的同事,他将查看数据并继续手动更新文件。

现在我注意到有一个可以使用的事件过程:

Private Sub Worksheet_Change(ByVal Target As Range)
  Target.Interior.Color = RGB(255, 253, 130)
End Sub

据我了解,即使更改是由 VBA 完成的,它也可以标记单元格,但我不知道如何使用我的 VBA 脚本来实现它。我是否以某种方式将其插入到我的一般过程中,还是必须将其嵌入到更新的目标文件中?

请注意,VBA 没有写入目标文件。由于客户端请求,该文件不能为 xlsm 格式。

提前致谢!!

【问题讨论】:

  • 当您更改原始 VBA 脚本中的单元格或范围时,请使用代码 <CELL OR RANGE HERE>.Interior.Color = RGB(255, 253, 130) 更改该单元格或范围的颜色。
  • 你为什么不简单地使用条件格式?
  • Jeffrey- 抱歉回复晚了。我不认为条件格式可以执行任务 - 或者您是否介意详细说明您的想法。
  • JNevill - 其中有很多,而且任务开始显得重复,这就是为什么我在考虑是否有更简单的方法。

标签: excel vba target byval


【解决方案1】:

我会为此创建一个 Excel 插件并将其安装到您同事的机器上。然后根据您的要求将代码从客户端文件中分离出来。

您可以使用 .bat 文件将其复制到他们的插件文件夹中。

REM
REM     /E   = Copies directories and subdirectories, including empty ones. Same as /S /E. May be used to modify /T. 
REM     /D:m-d-y = Copies files changed on or after the specified date. If no date is given, copies only those files whose source time is newer than the destination time. 
REM     /K   = Copies attributes. Normal Xcopy will reset read-only attributes. 
REM     /Q   = Does not display file names while copying. 
REM     /R   = Overwrites read-only files. 
REM     /Y   = Suppresses prompting to confirm you want to overwrite an existing destination file. 
REM

XCOPY ".\YourAddin.xlam" "%AppData%\Microsoft\AddIns\YourAddin.xlam" /E /K /Q /R /Y /D

【讨论】:

  • 感谢您的建议!从来没想过加载项。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2021-10-31
  • 2013-10-19
  • 1970-01-01
  • 1970-01-01
  • 2019-05-18
  • 1970-01-01
  • 2017-09-17
相关资源
最近更新 更多