excel - 如何让 Excel VBA 在继续之前等待解压缩所有文件
问题描述
我正在尝试从一个 .zip 文件中解压缩 589 个 PDF 文件,但在检查目标文件夹中的解压缩文件后,只有 100 多个文件被解压缩。我猜代码不会等待。
我想我从 Ron de Bruin 那里得到了这段代码,但我找不到关于如何让我的脚本等待所有文件被提取后再继续下一步的代码。
Sub UnzipFile_Click()
Dim FSO As Object
Dim oApp As Object
Dim Fname As Variant
Dim FileNameFolder As Variant
Dim DefPath As String
Dim strDate As String
Application.ScreenUpdating = False
Fname = Application.GetOpenFilename(filefilter:="Zip Files (*.zip), *.zip", _
MultiSelect:=False)
If Fname = False Then
'Do nothing
Else
'Root folder for the new folder.
'You can also use DefPath = "C:\Users\Ron\test\"
DefPath = Application.DefaultFilePath
If Right(DefPath, 1) <> "\" Then
DefPath = DefPath & "\"
End If
'Create the folder name
strDate = Format(Now, " mm-dd-yy")
FileNameFolder = DefPath & "DFM Invoices " & strDate & "\"
'Make the normal folder in DefPath
MkDir FileNameFolder
'Extract the files into the newly created folder
Set oApp = CreateObject("Shell.Application")
oApp.Namespace(FileNameFolder).CopyHere oApp.Namespace(Fname).Items
MsgBox "You may find the unzipped files here: " & FileNameFolder
TextBox1.Value = FileNameFolder
On Error Resume Next
Set FSO = CreateObject("scripting.filesystemobject")
FSO.deletefolder Environ("Temp") & "\Temporary Directory*", True
End If
End Sub
解决方案
推荐阅读
- python - 将时间增量添加到天空时间
- go - reflect.TypeOf 是 *string 并返回 0xc0001ae4a8 - 如何打印
- mysql - 我应该如何在 RDS MySQL 表中存储 s3 文件位置?
- typescript - 如何在打字稿中覆盖合并命名空间中的函数
- javascript - 函数参数类型的 Sphinx-js 警告
- python - 使用 pyPDF2 创建多个列表或字典以保存 PDF 对象?
- php - 如何检查会话是否已启动并重定向用户?
- python - 键盘记录器扩展
- python - 芹菜改变 content_encoding
- node.js - 在nginx + bitnami上设置无误后无法访问nodebb