问题
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:
- 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
- certain cells, or
- 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