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.
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.
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
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.
Related
TL;DR: Why/How does a workbook suddenly have Trace Auditing disabled (not protected)? What causes Excel to activate this behavior?
I was working on an Excel spreadsheet that I had created a while back and wanted to use the Formula Auditing "Trace Precedent" functionality. To my surprise it was grayed out. Everything else worked fine except that feature. Neither the workbook nor the worksheet were protected.
Searching the web I was able to quickly find a solution:
File Menu>Options>Advanced>Display Options for this workbook>For Objects shown: select **"all"**
I want to know how to prevent this from popping up as an issue for employees who use my templates. Or what triggers it. I certainly didn't set this option in Excel on purpose.
I've discovered another reason why some of the formula auditing functions get disabled, even in worksheets where objects are being shown properly.
If I Ctrl+LeftClick more than one worksheet name tab at the bottom (which I do to include more than one sheet when I print), five of the six functions become greyed out, leaving only Show Formulas available. This peculiar behavior is present in Office 2010 for Windows and in Microsoft 365 (a.k.a. Office 365) for Windows.
I am trying to use an Excel workbook that has links to Bloomberg data in. The data has been pulled from Bloomberg already. I then want to ensure that when I send this workbook to someone that they can use the sheet without a Bloomberg terminal connection. The user without the Bloomberg feed has set calculations to manual in Excel however when they try and save the workbook it automatically tries to update the fields and gives #NAME errors in the fields where Bloomberg values should be.
Is there a way to stop Excel from trying to refresh the Bloomberg links when the workbook is saved? I have tried VBA Workbook_AfterSave and Workbook_BeforeSave events but that did not seem to work.
A touch embarassed to admit but in Options > Formulas > Manual there is a check box for calculating the workbook before saving. I unchecked that and it worked.
According to the license, you're not supposed to remove values obtained using the API (Excel) from the computer where the Bloomberg Terminal is installed. That being said, if cells cease being Excel formulas they will no longer attempt to update to an up-to-date value. To do this, copy the cells that currently have a BDP/BDH formula and right click -> paste special -> values. This is also useful if you don't want the values refreshing every time you open the worksheet on the same computer.
In Excel I can activate "Track changes while editing." with "Select "Highlight changes on screen.", and I get all changes visible.
Now I want to generate a complex report of all these changes, so I need a way to access this information via VBA. Unfortunatly there is no "Workbook.Changes" Property.
Does anybody know how to do it?
Kind regards,
Thomas
Depending on what you need to track changes for, you might be able to use Spreadsheet Compare to help report on changes. It's an Excel Addin with lots of options for reporting on the differences between 2 workbook.
If you save a copy of the workbook before editing it, you could use this tool to summarize the differences after edits.
Did you notice that there is a built in option that allows you to 'List changes on a new sheet' ?
The best macro is no macro. (old Excel proverb)
As far as I understand cells with formulas in Microsoft Office Excel can contain calculated values when serialized and saved in Office Open XML formats (specifically SpreadsheetML). This most likely applies to other types of dependencies and functions of values from other cells (like charts, pivot tables, etc.). I most likely do something wrong, but when processing this XML documents (SpreadsheetML) by external tools, that do not use any .Net components or similar APIs provided by MS, but just directly manipulating XML, I get into a problem that when I modify some content of one of worksheets Excel will still use last generated values in cells containing formulas. So when user opens generated spreadsheet he sees modified data but all the calculated fields are outdated. Now the only thing that I could find (these days) on internet was this:
http://openxmldeveloper.org/discussions/formats/f/14/p/1561/4164.aspx
This is really not a preferable solution especially if it applies to any kind of calculated cells and objects (charts, etc.) as it means partially reimplementing some SpreadsheetML processor when you do not know exactly the structure of all worksheets.
I would hope there would certainly be either an option in Excel or a configuration in one of the SpreadsheetML parts to force recalculations or to mark cells dirty, but I couldn't find one yet.
There is an assumption that scripting would help, but my lack of knowledge of that area didn't brought me to any successful results yet as I'm not sure how to include scripts into SpreadsheetML worksheet. Though I found quite some examples how to trigger recalculation and how to add open event listeners.
The easiest way is to remove the calculated value from the cell (as also noted in the link you provided).
You do not have to know the exact structure of worksheets. Just remove all occurrences of <v>#VALUE!</v> in worksheets/sheet1.xml (so that other functions will not be affected).
press F9 to recalculate all open workbooks
Excel Recalculation
Perhaps your Calculation Mode for the workbook is getting set to manual. Force this mode to Automatic when you open the workbook by setting it to null in the code with the following:
public void SetAutomaticCalculationMode(WorkbookPart workbookPart1)
{
Workbook workbook1 = workbookPart1.Workbook;
CalculationProperties calculationProperties1=workbook1.GetFirstChild<CalculationProperties>();
calculationProperties1.CalculationMode = null;
}
This will correspond to Automatic calculation mode as seen in the Options of Excel 2007 client:
I use VSTO Excel template based solutions frequently. One of the things I like about this project type is that I can use cached data sets in the Excel template or worksheet to handle application state that persists after the user saves the file. However, cached data sets create a problem: the schema of the document is bound to the application version.
This hasn't been a big problem, but I've realized it would be a good idea to create a mechanism that will read the version of the Excel document when it opens in order to detect and handle version incompatibilities. For example, if my 2.1 plugin opens a 1.5 document, the schema of the cached data will not match what is expected.
Is there a standard or recommended way to version stamp the Excel template or worksheet? If not, does anyone have suggestions on how to do this?
I usually use the Worksheet.CustomProperties to persist information like this into my worksheet. Any information you put into the CustomProperties collection gets saved along with the worksheet and is loaded back along with the worksheet information when you reload the worksheet.
Workbooks also support custom properties, but I think in your case Worksheet.CustomProperties is the way to go.
I don't know any standard, but you can consider:
The use of a custom document property accessible by Microsoft.Office.Core.DocumentProperties (How to: Read from and Write to Document Properties);
A protected cell in the worksheet
itself;
With the first approach the user could manually change this property or delete it. However the second approach you would have protected cells in the worksheet which, if I recall correctly, will introduce some problems if you want to sort any data in that worksheet.
I had a similar issue (how to determine the Excel version from within VSTO code). I found your question while search for a solution. What worked for me was the Version property of the Excel Application object. From within a worksheet:
Me.Application.Version
or maybe, depending on where you're at
Globals.ThisWorkbook.Application.Version
Anyway, the value is "11.0" for Excel 2003 and "12.0" for 2007.
However, on re-reading your issue, you need to know the version that created a workbook. You might try Workbook.CalculationVersion, which "Gets a number that indicates the version of Excel that the workbook was last fully recalculated by. The rightmost four digits are the minor calculation engine version number, and the other digits (on the left) are the major version of Microsoft Office Excel." as per http://msdn.microsoft.com/en-us/library/microsoft.office.tools.excel.workbook.calculationversion.aspx