views:

622

answers:

3

Hello, recently I have been working on an app in vba which relies on some files which are contained in the .docm file of the document its self. Initially, I was using the Windows XP compressed folder functionality to programmatically extract the contents of the docm. This was an optimal solution because it is built into all Windows XP that this will be used on and therefor required no installation. However, I have hit a snag: It seems that after I extract the docm a certain number of times, it starts erroring out saying "Error, that file already exists". Initially, I thought that I broke something and dug a bit deeper, it turns out that there wasn't a bug in my code, but rather a bug in Compressed Folder.

If you get the "File Already Exists" error on a certain zip file on your system, Compressed Folder no longer works on ANY file of the same name, if you rename said file, it starts working again. So here's my question: How can I implement zip capability in VBA without compressed folders? Bonus question: How can I fix compressed folders?

Thanks for your time.

-Seamus

Update: Currently I have it working using Compressed Folders, I am working around the bug by renaming the file to something new every time the error happens. This is working OK, but I am looking for more of a fix rather than a hack around the problem.

A: 

Maybe an idea for the bonus question: can't you rename the file 2 times before you use it with your VBA app? First give it a temporary name and then rename it back to the original name.

EDIT: I'm just guessing here but it seems unlikely to fix this problem from within your app but rather to fix it as kind of windows patch. This means every computer your app shall run on would have to have this patch installed to work properly. And this isn't something you can rely on. So I think you should stick with a workaround.

DaClown
That's actually what I am doing now, but it is a bit sub optimal because I have to randomly generate the new file name, which smells bad to me.
Seamus
A completely random filename smells indeed bad. Couldn't you just extend the filename with a consecutive number while checking for an already existing file with the name?
DaClown
A: 

This may be able to help you. It looks like he's using the scripting filesystem object...

Jon Fournier
Thanks very much for the link, it contains a lot of useful information. He does however use the integrated zip capability of the computer: oShellApp.Namespace(UnzipFolder).CopyHere oShellApp.Namespace(SourceFile).itemsThere are however other things on this page wich will help me with other problems. Thanks!
Seamus
That's the Compressed Folder functionality to be exact.
Seamus
A: 

It appears that there is no good way to access zip functionality directly in windows. It seems that the only good way to do it is to use the zip folder copy method linked in other answers. As for the problem I am having, I will work around it by using a new file name every time.

Seamus