Question

I am trying to write a VBA macro to track changes to a workbook in a separate sheet.

If you do this manually, the sequence of commands is Tools > Track Changes > Highlight Changes, taking the option Separate Worksheet. You have to do two iterations of the command, one to activate tracking inline, a second to move the tracking to a separate sheet.

Using the macro recorder, I got to this piece of code:

With ActiveWorkbook
    .Save
    .KeepChangeHistory = True
    .HighlightChangesOptions When:=xlAllChanges
    .ListChangesOnNewSheet = True
    .HighlightChangesOnScreen = False
    .Worksheets("History").Select
End With

When I run this, I get the error HighlightChangesOptions method fails. Any suggestions?

Was it helpful?

Solution

The HighlightChangesOptions method will only work if the workbook is already shared. In the UI, turning on HighlightChange will share the workbook automatically, but not so in VBA.

Application.DisplayAlerts = False
With ActiveWorkbook
    .SaveAs , , , , , , xlShared
    .KeepChangeHistory = True
    .HighlightChangesOptions When:=xlAllChanges
    .ListChangesOnNewSheet = True
    .HighlightChangesOnScreen = False
    .Worksheets("History").Select
End With

The DisplayAlerts call will prevent Excel from warning you that you are overwriting an existing workbook - itself. You may want to comment that line out just to see what's going on.

Note that this code cannot live in the shared workbook. Once you share the workbook, the code stops executing and errors. It has to live in a different workbook or add-in.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top