Can I read the Version into some Buffer without opening the Version into new instance of Word?

  • Thread starter Ahmad Jalil Qarshi
  • Start date
A

Ahmad Jalil Qarshi

hi!

I have a word document. I added 2 Versions into the ActiveDocument. Now as
from the Object Model its Obvious that there are three main methods to do
something with Versions.

1. Open
2. Delete
3. Save

Now if i want to read binary data of Version 1 into some buffer. I'll have
to Open the version. and then get the path of the opened version and after
that read the files data into buffer. But i don't want to Open the Version.
I just want to read the contents of the specific Version without showing the
user that the Version is opened and then closed.

Is there any solution to this problem

Thanks in advance.

Ahmad jalil Qarshi
 
P

Phil

When you open the document that you don't want to show the user, set its
Visible property to False:

Set doc = Documents.Open(FileName:="C:\MyFiles\MyDoc.doc", Visible:=False)

By the way, don't forget to close the document when your done.
 
A

Ahmad Jalil Qarshi

Thanks Phil!

But the problem is that Version Object's Open method doesn't take any
parameter As in the following code and returns a Document Object. so it I
think that it will not work.

Dim VersionDoc as Document = ActiveDocument.Version(1).Open()

Any Other Idea?

Thanks in advance.

Ahmad Jalil Qarshi
 
P

Phil

Sorry, I didn't specifically mention the Version object. But as you
mentioned, the Open method works with the Version object too.

Also, if you run into problems opening a particular version because you
already have that version open, open it with property ReadOnly:=True.
 
P

Phil

Ok I see what you mean.

I would try starting a second instance of Word, and seeing if you can open
the document read-only and invisible, while the document is still open in the
other instance. See if it works.

As you probably know it gets a bit trickier because you have to make sure
the second instance actually does close when you think you are closing it.
 
P

Phil

And if that does not work, then replicate what Word does through the
File-Open dialog when you open a document with the 'Open As Copy' option (its
on the Open button drop-down). Then you can definately open a second copy of
a document.

So in your VBA code, copy the original file to a file with a different name
such as 'Copy of ...', open that file with visible = false, and then open the
version you want.

FileCopy syntax:
FileCopy SourceFileName, DestinationFileName


Good luck! I have to go to bed now :)
 
P

Perry

You can't FileCopy() an open file; you'll get the "Access Denied" message.

What you can do to overcome this, is open the source Open() Lock Access
Binary Read.
Look it up in Help files.

Read the content (binary) using Get()
Open a destination file For Binary Access Write and write the byte chunk
using Put()
Note: you'll have to set a buffersize!
Read the Help files.

This technique is utilized for rapid filecopying because of the ability to
buffersize ...
(Note: as stated, this technique will include copying open files)

-------------------------------------
Krgrds.
Perry

System parameters:
POS: WinXP x64
MSO: MSOffice System
DEV: VS7 (dotnet)
-------------------------------------
 

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