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.
最近我一直在研究vba中的一个应用程序,它依赖于文件的.docm文件中包含的一些文件。最初,我使用Windows XP压缩文件夹功能以编程方式提取docm的内容。这是一个最佳解决方案,因为它将内置于所有Windows XP中,并且不需要安装。但是,我遇到了一个障碍:似乎在我提取docm一定次数之后,它开始错误地说“错误,该文件已经存在”。最初,我认为我破坏了一些东西并挖得更深一些,事实证明我的代码中没有错误,而是压缩文件夹中的错误。
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?
如果您的系统上某个zip文件出现“文件已存在”错误,则压缩文件夹不再适用于任何同名文件,如果重命名该文件,它将再次开始工作。所以这是我的问题:如何在没有压缩文件夹的情况下在VBA中实现zip功能?奖金问题:如何修复压缩文件夹?
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.
更新:目前我使用压缩文件夹工作,我正在解决这个错误,每次错误发生时将文件重命名为新的。这工作正常,但我正在寻找更多的修复而不是解决问题。
3 个解决方案
#1
This may be able to help you. It looks like he's using the scripting filesystem object...
这可能可以帮到你。看起来他正在使用脚本文件系统对象......
#2
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.
也许是一个关于奖金问题的想法:在将它与VBA应用程序一起使用之前,你不能将文件重命名2次吗?首先给它一个临时名称,然后将其重命名为原始名称。
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.
编辑:我只是在这里猜测,但似乎不太可能从你的应用程序中解决这个问题,而是将其修复为一种Windows补丁。这意味着您的应用程序应运行的每台计算机都必须安装此修补程序才能正常运行。这不是你可以依赖的东西。所以我认为你应该坚持一个解决方法。
#3
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.
似乎没有好的方法直接在Windows中访问zip功能。似乎唯一可行的方法是使用在其他答案中链接的zip文件夹复制方法。至于我遇到的问题,我每次都会使用一个新的文件名解决它。
#1
This may be able to help you. It looks like he's using the scripting filesystem object...
这可能可以帮到你。看起来他正在使用脚本文件系统对象......
#2
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.
也许是一个关于奖金问题的想法:在将它与VBA应用程序一起使用之前,你不能将文件重命名2次吗?首先给它一个临时名称,然后将其重命名为原始名称。
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.
编辑:我只是在这里猜测,但似乎不太可能从你的应用程序中解决这个问题,而是将其修复为一种Windows补丁。这意味着您的应用程序应运行的每台计算机都必须安装此修补程序才能正常运行。这不是你可以依赖的东西。所以我认为你应该坚持一个解决方法。
#3
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.
似乎没有好的方法直接在Windows中访问zip功能。似乎唯一可行的方法是使用在其他答案中链接的zip文件夹复制方法。至于我遇到的问题,我每次都会使用一个新的文件名解决它。