有没有办法通过 Excel 中的 VBA 触发“跟踪更改”?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/8818076/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Is there a way to trigger "track changes" through VBA in Excel?
提问by Martin Dimitrov
I want from VBA to start/stop "Track changes" functionality in Excel.
我想从 VBA 开始/停止 Excel 中的“跟踪更改”功能。
Searching thru the Net I saw a property called TrackRevisions
of ActiveDocument
object. Supposedly in MS Word writing ActiveDocument.TrackRevisions = True
should turn on "Track changes".
搜索通净,我看到了一个名为属性TrackRevisions
的ActiveDocument
对象。据说在 MS Word 写作中ActiveDocument.TrackRevisions = True
应该打开“跟踪更改”。
But in MS Excel this line gives 424 Object required
run-time error. Same error is returned when trying with ThisWorkbook
. Changing it to ActiveSheet
brings 438 Object doesn't support this property or method
error.
但是在 MS Excel 中,这一行会出现424 Object required
运行时错误。尝试使用时返回相同的错误ThisWorkbook
。改变它会ActiveSheet
带来438 Object doesn't support this property or method
错误。
采纳答案by brettdj
For a shared workbookyou can use VBA from these links (the method is ActiveWorkbook.HighlightChangesOptions
)
对于共享工作簿,您可以从这些链接使用 VBA(方法是 ActiveWorkbook.HighlightChangesOptions
)
- HighlightChangesOptions Method Excel 2003 VBA Language Reference
- Workbook.HighlightChangesOptions Method Office 2007
- Workbook.HighlightChangesOptions Method (Excel) Office 2010
- HighlightChangesOptions 方法 Excel 2003 VBA 语言参考
- Workbook.HighlightChangesOptions 方法 Office 2007
- Workbook.HighlightChangesOptions 方法 (Excel) Office 2010
This doesn't offer the same depth of tracking as available in Word, for example from the first link in my post,in Excel:
这不提供与 Word 中可用的相同深度的跟踪,例如来自我帖子中的第一个链接,在 Excel 中:
- Change tracking differs from undo and backup
- Some types of changes are not tracked Changes that you make to cell contents are tracked, but other changes, such as formatting changes, are not tracked.
- Change history is kept only for a specific interval
- Change history is periodically deleted
- 更改跟踪不同于撤消和备份
- 不跟踪某些类型的更改 跟踪您对单元格内容所做的更改,但不跟踪其他更改,例如格式更改。
- 更改历史仅保留特定时间间隔
- 定期删除更改历史记录
If that isn't what you were chasing you may be able to employ specific VBA to track
如果这不是你想要的,你可以使用特定的 VBA 来跟踪
- certain cells, or
- compare versions
- 某些细胞,或
- 比较版本
But if that is the case we will need more information from you as to what you are chasing.
但如果是这种情况,我们将需要您提供更多有关您所追求的信息的信息。
回答by user1143192
You can use the following code. You will see this code when you record a macro.
您可以使用以下代码。当您录制宏时,您将看到此代码。
With ActiveWorkbook
.HighlightChangesOptions When:=xlAllChanges
.ListChangesOnNewSheet = False
.HighlightChangesOnScreen = True
End With
回答by eriklind
The questions is really what do you want to achieve. If you want to track changes in a spreadsheet, I assume you have some other users editing the workbook, and you want to record who changed what, as well as review/approve any modifications later on. Well, you don't actually need a triggering macros for that.
问题实际上是您想要实现的目标。如果您想跟踪电子表格中的更改,我假设您有其他一些用户正在编辑工作簿,并且您想记录谁更改了什么,以及稍后查看/批准任何修改。好吧,您实际上并不需要触发宏。
... instead of Track Changes, try comparing two workbooks using the Microsoft's Spreadsheet compare (application is limited to Excel 2013, Excel 2016 , Office 365 Professional).
...而不是跟踪更改,尝试使用 Microsoft 的电子表格比较来比较两个工作簿(应用程序仅限于 Excel 2013、Excel 2016、Office 365 Professional)。
... instead of Track Changes, you can record history of changes made to the workbook (who changed what and when) - XLTools Version Control.
...而不是跟踪更改,您可以记录对工作簿所做更改的历史记录(谁更改了什么以及何时更改)- XLTools 版本控制。
I use both depending on the task.
我根据任务使用两者。