VBA处理压缩文件示例
(2018-05-23 18:03:37)
标签:
excelvbaword代码 |
分类: VBA专区 |
01.Sub
Unzip_Ex()
02. Dim
FSO As
Object03. Dim
oApp As
Object04. Dim
Fname As
Variant05. Dim
FileNameFolder As
Variant06. Dim
DefPath As
String07. Dim
strDate As
String08. 09. Fname
= Application.GetOpenFilename _10. (filefilter:="Zip
Files (*.zip), *.zip", _11. MultiSelect:=False)12. If
Fname = False
Then13. '
do nothing14. Else15. '
新文件夹的根目录16. '
你也可以使用 DefPath = "C:\Users\HUP\test\"17. DefPath
= Application.DefaultFilePath18. If
Right(DefPath, 1) <> "\"
Then19. DefPath
= DefPath & "\"20. End
If21. 22. '
创建新的文件夹名称23. strDate
= Format(Now, " dd-mm-yy
h-mm-ss")24. FileNameFolder
= DefPath & "MyUnzipFolder " &
strDate & "\"25. 26. '
在DefPath下创建文件夹27. MkDir
FileNameFolder28. 29. '
将文件解压到新创建的文件夹下30. Set
oApp =
CreateObject("Shell.Application")31. 32. oApp.Namespace(FileNameFolder).CopyHere
oApp. Namespace(Fname).items33. 34. '
如果你只需要解压一个文件,可以使用:35. 'oApp.Namespace(FileNameFolder).CopyHere
_36. 'oApp.Namespace(Fname).items.Item("test.txt")37. 38. MsgBox
"You find the files here: " &
FileNameFolder39. 40. On
Error Resume
Next41. Set
FSO =
CreateObject("scripting.filesystemobject")42. FSO.deletefolder
Environ("Temp") &
"\Temporary Directory*",
True43. End
If44.End
Sub
加载中…