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

喜你入骨 提交于 2020-01-13 20:30:10

问题


I want from VBA to start/stop "Track changes" functionality in 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".

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.


回答1:


For a shared workbook you can use VBA from these links (the method is ActiveWorkbook.HighlightChangesOptions)

  • HighlightChangesOptions Method Excel 2003 VBA Language Reference
  • Workbook.HighlightChangesOptions Method Office 2007
  • Workbook.HighlightChangesOptions Method (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:

  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

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

  1. certain cells, or
  2. compare versions

But if that is the case we will need more information from you as to what you are chasing.




回答2:


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



回答3:


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).

... instead of Track Changes, you can record history of changes made to the workbook (who changed what and when) - XLTools Version Control.

I use both depending on the task.



来源:https://stackoverflow.com/questions/8818076/is-there-a-way-to-trigger-track-changes-through-vba-in-excel

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!