Solved

Retrieving the Excel file detail "Version number"

Posted on 2016-08-04
15
143 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 7
  • 5
  • 2
15 Comments
 
LVL 27

Accepted Solution

by:
Glenn Ray earned 400 total points (awarded by participants)
ID: 41742958
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 18

Assisted Solution

by:xtermie
xtermie earned 100 total points (awarded by participants)
ID: 41753850
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)
ID: 41754188
^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
PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

 

Author Comment

by:jtrawick
ID: 41768847
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)
ID: 41768986
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
ID: 41769465
<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)
ID: 41769652
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
 

Author Comment

by:jtrawick
ID: 41770923
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
ID: 41770998
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
ID: 41771741
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)
ID: 41771932
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
ID: 41784941
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
ID: 41786912
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 18

Expert Comment

by:xtermie
ID: 41815670
good comments and code provided by Experts
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction While answering a recent question (http:/Q_27311462.html), I created an alternative function to the Excel Concatenate() function that you might find useful.  I tested several solutions and share the results in this article as well as t…
This code takes an Excel list of URL’s and adds a header titled “URL List”. It then searches through all URL’s in column “A”, looking for duplicates. When a duplicate is found, it is moved to the top of the list. The duplicate URL’s are then highlig…
This Micro Tutorial demonstrates in Microsoft Excel how to consolidate your marketing data by creating an interactive charts using form controls. This creates cool drop-downs for viewers of your chart to choose from.
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

740 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