Solved

Retrieving the Excel file detail "Version number"

Posted on 2016-08-04
15
51 Views
Last Modified: 2016-09-26
I have a spreadsheet that gets updated when features are added or comparison data gets changed. Each time, the "Version number" field in the file properties details gets changed to reflect its configuration. I'd like to put the value of that field in a cell, so that when the spreadsheet is printed, the current version number is on the title page, so that the reviewer can ensure that the current version of the spreadsheet was used.

I'm doing this manually, now, but sometimes I forget and they get out of sync. I could use the Workbook_Open() event to get it and put it into the cell on opening, if I could figure out how to get to the property detail. ThisWorkbook.BuiltinDocumentProperties("Revision Number") works, but it can't find "Version" or "Version number", and Revision wants an integer, not the major.minor string that we're using.

Is there a method/property that does this?
0
Comment
Question by:jtrawick
  • 7
  • 5
  • 2
15 Comments
 
LVL 27

Accepted Solution

by:
Glenn Ray earned 400 total points (awarded by participants)
Comment Utility
Yes.  The example below is a subroutine in the "ThisWorkbook" object that checks for a custom property.  You'll add your own code to retrieve or insert the [LATEST VERSION NUMBER]
Private Sub Check_Version()
    Dim Ver As Object
    Set Ver = ActiveWorkbook.CustomDocumentProperties.Item("Version")
    
    If Ver < [LATEST VERSION NUMBER] Then
            MsgBox "A new version of this application is now available." & vbLf & _
                "You are running version number " & Ver & vbLf & _
                "The latest version number is " & [LATEST VERSION NUMBER],  vbCritical + vbOKOnly, "Upgrade Notice"
            Application.DisplayAlerts = False
            Application.DisplayFullScreen = False
            ActiveWorkbook.Close
        End If
    End If    
End Sub

Open in new window


Regards,
-Glenn
1
 
LVL 17

Assisted Solution

by:xtermie
xtermie earned 100 total points (awarded by participants)
Comment Utility
There is an extra End if there I think on line 12.
If you have several versions of your spreadsheet you may want to consider a SharePoint document library that will provide with proper versioning as well (minor and major).

In that case you can retrieve version info as follows:
Sub getVersions()

Dim DocVersions As DocumentLibraryVersions
Dim DVersion As DocumentLibraryVersion

Set DocVersions = ThisWorkbook.DocumentLibraryVersions

For Each DVersion In DocVersions
    Debug.Print DVersion.Index
    Debug.Print DVersion.Comments
    Debug.Print DVersion.Creator
    Debug.Print DVersion.Modified
    Debug.Print DVersion.ModifiedBy
    Debug.Print DVersion.Application
Next

End Sub

Open in new window

0
 
LVL 27

Assisted Solution

by:Glenn Ray
Glenn Ray earned 400 total points (awarded by participants)
Comment Utility
^Yes; line 12 should be removed from my example.  I was just stripping it out of some existing code.

The key code to note are lines 2-3 where one can access a custom document property with the name specified in quotes.
0
 

Author Comment

by:jtrawick
Comment Utility
When I run the "set ver" line (3), I get "Run time error 5: Invalid procedure call or argument". I get the same error with ".BuiltinDocumentProperties("Version")"

.BuiltinDocumentProperties("Revision Number") works, but it's not what I need (wrong metadata element).

It seems like it doesn't understand the "Version" index in those collections.

I can set a custom property, but I'd like to use what Excel provides.
0
 
LVL 27

Assisted Solution

by:Glenn Ray
Glenn Ray earned 400 total points (awarded by participants)
Comment Utility
If your Excel workbook does not already have a Document Property tltled "Version", yes you will get an error.

You can add new Custom Properties through the Advanced Properties menu:
  • File
  • Info page
  • Properties tab (on far right) - click drop arrow
  • Advanced Properties
  You'll see a new dialog box pop up
  • "Custom" tab
You'll see several built-in properties that you can use, but you can also add your own by typing a new name in the "Name:" field, choosing the type of data in the "Type" field, and then entering the property value in the "Value" field.  See the below example.
Excel document properties access
0
 

Author Comment

by:jtrawick
Comment Utility
<sigh...>

I can set a custom property, but I'd like to use what the OS provides.
Version.png
0
 
LVL 27

Assisted Solution

by:Glenn Ray
Glenn Ray earned 400 total points (awarded by participants)
Comment Utility
I apologize for the confusion; I didn't realize you were referring to the extended file attributes.

I'm thinking an API call will be necessary here, but am not sure which one yet.  You stated that the Version number value is changed when the file is updated.  I don't know a setting in Excel that will update that value, so is the file already using VBA?  If so, we'd just need to locate the code that updates the value and then modify it to extract the Version number.

I noted while I was experimenting with other existing code that:
1) Excel files of version 2007 or earlier (.xls) did not allow manual editing of either the Revision number or Version number in Explorer
2) The "File Version" constant (which may or may not be the same as "Version number" is dependent on the OS.  

I'm still digging; think it might be possible using Shell.Application.
0
Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

 

Author Comment

by:jtrawick
Comment Utility
Thanks.

The spreadsheet uses fairly extensive VBA, and I can count on Windows 7 as the OS and Office 2013. The spreadsheet doesn't get a new version every time, only when the logic or the reference tables are changed. I can set the version in the code, or on the "extended file attributes", but they need to stay synced, so I need to do it in one place. If a create a new variable, it still needs to end up in the "extended file attributes 'Version number'", so I either need to read it or write it, or continue to be very careful (which is not my nature).

Hadn't thought about an OS shell API (now I feel REALLY stupid...) will check in that direction, also. .GetDetailsOf looks promising.
0
 
LVL 27

Expert Comment

by:Glenn Ray
Comment Utility
Unfortunately, the .GetDetailsOf appears to only reference the internal BuiltIn or Custom document properties, not OS or NTFS data.

If you have the VBA code that writes the extended file "Version number", I'd use that as a basis for the method of writing that same value to a cell.  Plus, I'd be really interested in seeing that code... :-)
0
 

Author Comment

by:jtrawick
Comment Utility
No code - I've been using the right-click to set it (left-click in the box). No idea what that does under the covers.

I went through the first 900 of .GetDetailsOf, no success. 26 of them have data, the last being in index 269, though I can only find descriptions for about 15, Audio/video/picture files have a lot more.

Why does MS make it so hard to get metadata that THEY provide containers for?

I'll let this go for a couple more days, then I'll have to brute-force it. I think I remember liking Microsoft...
0
 
LVL 27

Assisted Solution

by:Glenn Ray
Glenn Ray earned 400 total points (awarded by participants)
Comment Utility
I had created a quick utility workbook to retrieve all metadata for a specific file that I manually updated the Revision number & Version number in Windows (to 666 and 667)
extended properties
I found that the upper limit is 292 and NONE of the items or values matched. :-(

Sub getproperties()
    Dim sFile As Variant
    Dim oShell: Set oShell = CreateObject("Shell.Application")
    Dim oDir:   Set oDir = oShell.Namespace("C:\Misc - Excel Development\Excel Tips Tools Tricks\Expert Exchange Work\Test\")
    'Need to modify this to pick a single file (or current file)
    
    Range("A2").Select
    For Each sFile In oDir.items
        If sFile.Name = "Another file (2).xlsx" Then
            For i = 0 To 292
                ActiveCell.Value = i
                ActiveCell.Offset(0, 1).Value = sFile.Name
                ActiveCell.Offset(0, 2).Value = oDir.getdetailsof(oDir.items, i)
                ActiveCell.Offset(0, 3).Value = oDir.getdetailsof(sFile, i)
                ActiveCell.Offset(1, 0).Select
            Next
        End If
    Next

End Sub

Open in new window

0
 

Author Comment

by:jtrawick
Comment Utility
Sorry. Been out with the "flu" (doc's opinion, not mine) for a couple of weeks.

This is in accord with my own test. No Joy.

Glenn Ray, thanks for the help in finding that there is no solution. Would like to give you credit for that, but it won't let me click "Assisted Solution" without a "Best Solution".
0
 
LVL 27

Expert Comment

by:Glenn Ray
Comment Utility
I believe you can close this question without awarding a solution, but you'll have to check with an admin to find out.

Sorry that I couldn't have been of more assistance.
0
 
LVL 17

Expert Comment

by:xtermie
Comment Utility
good comments and code provided by Experts
0

Featured Post

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Drop Down List with Unique/Distinct Values (enhancing the Combo-Box with a few steps and a little code) David miller (dlmille) Intro Have you ever created a data validation list from a database field or spreadsheet column (e.g., Zip Codes or Co…
Convert between Excel file formats (.XLS, .XLSX, .XLSM) with/without macro option David Miller (dlmille) Intro Over this past Fall, I've had the opportunity to see several similar requests and have developed a couple related solutions associate…
The viewer will learn how to simulate a series of coin tosses with the rand() function and learn how to make these “tosses” depend on a predetermined probability. Flipping Coins in Excel: Enter =RAND() into cell A2: Recalculate the random variable…
The viewer will learn how to create a normally distributed random variable in Excel, use a normal distribution to simulate the return on an investment over a period of years, Create a Monte Carlo simulation using a normal random variable, and calcul…

763 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

6 Experts available now in Live!

Get 1:1 Help Now