如何在 VBA 中实现 Zip 功能?

发布于 2024-07-19 04:54:49 字数 508 浏览 9 评论 0原文

最近我一直在使用 vba 开发一个应用程序,它依赖于文档本身的 .docm 文件中包含的一些文件。 最初,我使用 Windows XP 压缩文件夹功能以编程方式提取文档的内容。 这是一个最佳解决方案,因为它内置于将使用此功能的所有 Windows XP 中,因此无需安装。 然而,我遇到了一个障碍:似乎在我提取文档一定次数后,它开始错误提示“错误,该文件已经存在”。 最初,我以为我破坏了某些东西并深入挖掘,结果发现我的代码中没有错误,而是压缩文件夹中的错误。

如果您系统上的某个 zip 文件出现“文件已存在”错误,则压缩文件夹不再适用于任何同名文件,如果您重命名所述文件,它会再次开始工作。 所以这是我的问题:如何在没有压缩文件夹的情况下在 VBA 中实现 zip 功能? 额外问题:如何修复压缩文件夹?

谢谢你的时间。

-西莫

更新: 目前我使用压缩文件夹来工作,我正在通过每次发生错误时将文件重命名为新名称来解决该错误。 这工作正常,但我正在寻找更多的解决方案,而不是解决问题的方法。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

太阳公公是暖光 2024-07-26 04:54:49

此内容可能会对您有所帮助。 看起来他正在使用脚本文件系统对象......

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

口干舌燥 2024-07-26 04:54:49

也许是额外问题的一个想法:在将文件与 VBA 应用程序一起使用之前,您不能重命名该文件 2 次吗? 首先给它一个临时名称,然后将其重命名回原来的名称。

编辑:
我只是在这里猜测,但似乎不太可能从您的应用程序中解决这个问题,而是将其作为 Windows 补丁来修复。 这意味着您的应用程序将运行的每台计算机都必须安装此补丁才能正常工作。 这不是你可以依赖的东西。 所以我认为你应该坚持使用解决方法。

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.

玻璃人 2024-07-26 04:54:49

看来没有好的方法可以直接在 Windows 中访问 zip 功能。 似乎唯一的好方法是使用其他答案中链接的 zip 文件夹复制方法。 至于我遇到的问题,我每次都会使用新的文件名来解决它。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文