views:

1999

answers:

2

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?

A: 

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.

Dick Kusleika
Thanks very much for your help. This effectively solved the problem, but like you say, the macro then has to be called from a different workbook.
draconis
A: 

Hi, I am trying to record a macro for 'Highlighting Track Changes' and from the above answer it is clear.

Also, now I want the macro to auto run when I open the workbook everytime. Is that possible?

Aparnaa
Call your macro from the WorkBook_Open event.
draconis