直接上代码
Sub UnZip(ByVal myZipFile, ByVal myTargetDir)
Set fso = CreateObject("Scripting.FileSystemObject")
If NOT fso.FileExists(myZipFile) Then
Exit Sub
ElseIf fso.GetExtensionName(myZipFile) <> "zip" Then
Exit Sub
ElseIf NOT fso.FolderExists(myTargetDir) Then
fso.CreateFolder(myTargetDir)
End If
Set objShell = CreateObject("Shell.Application")
Set objSource = objShell.NameSpace(myZipFile)
Set objFolderItem = objSource.Items()
Set objTarget = objShell.NameSpace(myTargetDir)
intOptions = 256
objTarget.CopyHere objFolderItem, intOptions
End Sub
UnZip "C:\Users\Desktop.zip","C:\Users\Desktop\2"
这段代码展示了如何使用VBA(Visual Basic for Applications)来解压缩ZIP文件到目标目录。通过创建`Scripting.FileSystemObject`和`Shell.Application`对象,它首先检查ZIP文件是否存在且扩展名为ZIP,然后创建目标目录(如果不存在),最后使用`CopyHere`方法将ZIP文件内容解压到目标目录。
1605

被折叠的 条评论
为什么被折叠?



