Finding file format of a Visio document

J

John

Hello Peter,

I'm afraid I mis-read your original post and have since had a go with Paul's
suggestion (which I think is the correct approach). I can also confirm what
you've found that Document.Version does return the current app version (in
my case 2007) even if it is a 2002 doc.

Interestingly if you you save a document in 2002 format and then do
Document.Version this does return the 2002 id.

Anyway, whilst writing this I see that June has come up with the answer:
See Help for Document.FullBuildNumberCreated. This behaves as expected and
returns the version 10 for a 2002 doc.

One last point is that this only work for 2002 docs onwards.

Best regards

John
 
J

JuneTheSecond

How would you like to use Document.FullBuildNumberCreated property or
Document.FullBuildNumberEdited property?
There are examples inHelp.
Next code is from Help, and edited a little to get a file not opened.

Public Sub FullBuildNumberCreated_Example()

Dim lngFullBuildCreated As Long
Dim lngFullBuildEdited As Long
Dim doc As Visio.Document

Set doc = GetObject("Full Path File Name")

lngFullBuildCreated = doc.FullBuildNumberCreated
lngFullBuildEdited = doc.FullBuildNumberEdited
ParseFullBuildNumberCreatedProperty (lngFullBuildCreated)
ParseFullBuildNumberCreatedProperty (lngFullBuildEdited)
Set doc = Nothing
End Sub
 
P

Peter Smithson

Anyway, whilst writing this I see that June has come up with the answer:
See Help for Document.FullBuildNumberCreated. This behaves as expected and
returns the version 10 for a 2002 doc.

I've not had much luck with June's solution (which I'd tried before).
I will try and knock up a stand-alone test app and see what happens.
So far I've been adding to an existing application which might be
doing something "clever".

Thanks.

Peter.
 
P

Peter Smithson

I've not had much luck with June's solution (which I'd tried before).
I will try and knock up a stand-alone test app and see what happens.
So far I've been adding to an existing application which might be
doing something "clever".

Right - got to the bottom of this problem now.

If I use the FullBuildNumberCreated it does return the correct values
for normal Visio documents. ("Normal" as in, I bring up Visio, create
a drawing and do File->Save).

But - with documents that I normally use, they have been created by
calling the automation method "Save" or "SaveAs" (from a Visio
AddOn). These have been created in a system that had Visio 2002
installed followed by 2003 - so they are both on the system. With
these documents, you always get the build number coming back as 2003.

I'm not sure why this happens but even if it worked, it does not solve
my initial problem which I will re-word to try and avoid any
ambiguity.

How do I tell if a given vsd file can be loaded in Visio 2002?
(without trying to open it in 2002) i.e. was it saved in 2002 format
or not - I don't care if it was created by Visio 2003, just want to
know if it's in 2002 format.

To give this some background. Customers send us their collection of
vsd files, we open it in 2003 and get no warning that it's a 2002
project. Since the Tools->Options Save tab settings do not apply to
automation, we can't control the prompting on a save (which we do
automatically at various points). We're using SaveAs so there is no
prompting. We send the documents back to the customer who then can't
open them.

The build number used would be a clue but we have some customers that
use 2003, but save in 2002 format so they can support their 2002
sites.

Thanks.

Peter.
 
J

John

Hello Peter,

I've read from Help that:

"When Visio opens a document that was saved in an earlier version format, it
converts the document's in-memory representation to the current version."

This, I guess, gives us the results we're seeing, ie the current app
version.

Help goes on:

"However, when closing the document, Visio recognizes that the document was
saved in an earlier version format and allows the user to choose the version
in which to save the document"

So I've tried a couple of things. Firstly:

Set vTestDoc = Application.ActiveDocument
vTestDoc.Version = visVersion100
vTestDoc.Save

This doesn't help and the doc still gets saved in as a 2007 version (in my
case).

However, if you use the SaveAs method instead of Save in the above code the
resulting file is indeed saved in 2002 format. This can be confirmed by
opening the document, make a change (eg adding a rectangle) and then trying
to Save the doc again. At this point (as Help suggests) a dialog offers you
the choice of whether to save in the current version or it's original
(2002).

In my tests, I've found that this only works manually and not via code. The
default or at least the button that has focus in the dialog is "Current
Visio Format" and my assumption is that's what you're getting via code, the
default. A further message in the dialog says "Saving in the Visio 2002
format may result in the loss of attributes unique to the current format"
suggesting that Visio hasn't check the doc itself and only warns that there
'might' be some lost functionality.

So where does this leave you? Well, if you know that the file being sent to
you IS in 2002 format then presumably you can just ensure that you don't add
any 2003/7 functions or objects in your processing and then use the SaveAs
code above. If you can't be sure what version the doc is then you'll need
to do some pre-processing to check that 2003/7 functions don't exist in the
doc and then SaveAs as before. If this does turn out to be your only option
then it could be quite a hit on performance depending on the file sizes
involved, in which case it might make sense to "batch process" them first of
all and then add your own User.Version cell to the doc shapesheet.

Not a perfect answer I'm afraid, but unless somebody else comes up with
something more robust then hopefully this will help.

Best regards

John
 
P

Peter Smithson

Not a perfect answer I'm afraid, but unless somebody else comes up with
something more robust then hopefully this will help.

I'm going to go for the FullBuildNumberCreated option. It may not be
100% but, the way our application works, it's very unlikely that the
customer will have used 2003 to save as 2002 as they don't have the
"SaveAs" option enabled when running with our addon. I hadn't
realised that before. There's still this strange problem when you
have 2003 & 2002 installed but again, not likely at the customers
site.

Thanks for all your help everyone.

Peter.
 
J

JuneTheSecond

How would you like to use Document.FullBuildNumberCreated property or
Document.FullBuildNumberEdited property?
There are examples inHelp.
Next code is from Help, and edited a little to get a file not opened.

Public Sub FullBuildNumberCreated_Example()

Dim lngFullBuildCreated As Long
Dim lngFullBuildEdited As Long
Dim doc As Visio.Document

Set doc = GetObject("Full Path File Name")

lngFullBuildCreated = doc.FullBuildNumberCreated
lngFullBuildEdited = doc.FullBuildNumberEdited
ParseFullBuildNumberCreatedProperty (lngFullBuildCreated)
ParseFullBuildNumberCreatedProperty (lngFullBuildEdited)
Set doc = Nothing
End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top