有没有办法通过 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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-11 14:54:08  来源:igfitidea点击:

Is there a way to trigger "track changes" through VBA in Excel?

excelexcel-vbaword-vbavba

提问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 TrackRevisionsof ActiveDocumentobject. Supposedly in MS Word writing ActiveDocument.TrackRevisions = Trueshould turn on "Track changes".

搜索通净,我看到了一个名为属性TrackRevisionsActiveDocument对象。据说在 MS Word 写作中ActiveDocument.TrackRevisions = True应该打开“跟踪更改”。

But in MS Excel this line gives 424 Object requiredrun-time error. Same error is returned when trying with ThisWorkbook. Changing it to ActiveSheetbrings 438 Object doesn't support this property or methoderror.

但是在 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

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 中:

  1. Change tracking differs from undo and backup
  2. 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.
  3. Change history is kept only for a specific interval
  4. Change history is periodically deleted
  1. 更改跟踪不同于撤消和备份
  2. 不跟踪某些类型的更改 跟踪您对单元格内容所做的更改,但不跟踪其他更改,例如格式更改。
  3. 更改历史仅保留特定时间间隔
  4. 定期删除更改历史记录

If that isn't what you were chasing you may be able to employ specific VBA to track

如果这不是你想要的,你可以使用特定的 VBA 来跟踪

  1. certain cells, or
  2. compare versions
  1. 某些细胞,或
  2. 比较版本

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.

我根据任务使用两者。