通过Excel VBA代码解压缩文件

团队,我正在从VBA代码中提取zip文件,但得到错误,这是我的代码

Sub Un_Zip_File() Dim flname As String Call PathCall flname = Dir(impathn & "Transactions*.zip") Call PathCall Call UnZip_File(impathn, flname) End Sub Sub UnZip_File(strTargetPath As String, fname As Variant) Dim oApp As Object, FSOobj As Object Dim FileNameFolder As Variant If Right(strTargetPath, 1) <> Application.PathSeparator Then strTargetPath = strTargetPath & Application.PathSeparator End If FileNameFolder = strTargetPath 'destination folder if it does not exist Set FSOobj = CreateObject("Scripting.FilesystemObject") If FSOobj.FolderExists(FileNameFolder) = False Then FSOobj.CreateFolder FileNameFolder End If Set oApp = CreateObject("Shell.Application") oApp.Namespace(FileNameFolder).CopyHere oApp.Namespace(fname).Items Set oApp = Nothing Set FSOobj = Nothing Set FileNameFolder = Nothing End Sub 

当我正在运行Un_zip_filemacros时,我得到错误“对象variables或块variables未设置”后debugging移动

 oApp.Namespace(FileNameFolder).CopyHere oApp.Namespace(fname).Items 

这里是另一个例子,如何解压文件。
该macros解压zip文件在一个固定的文件夹"C:\test\"

 Sub Unzip() Dim FSO As Object Dim oApp As Object Dim Fname As Variant Dim FileNameFolder As Variant Dim DefPath As String Fname = Application.GetOpenFilename(filefilter:="Zip Files (*.zip), *.zip", _ MultiSelect:=False) If Fname = False Then 'Do nothing Else 'Destination folder DefPath = "C:\test\" ' Change to your path / variable If Right(DefPath, 1) <> "\" Then DefPath = DefPath & "\" End If FileNameFolder = DefPath ' 'Delete all the files in the folder DefPath first if you want ' On Error Resume Next ' Kill DefPath & "*.*" ' On Error GoTo 0 'Extract the files into the Destination folder Set oApp = CreateObject("Shell.Application") oApp.Namespace(FileNameFolder).CopyHere oApp.Namespace(Fname).items MsgBox "You find the files here: " & FileNameFolder On Error Resume Next Set FSO = CreateObject("scripting.filesystemobject") FSO.deletefolder Environ("Temp") & "\Temporary Directory*", True End If End Sub