1
当我到线运行时错误91对象变量未设置
oApp.Namespace(FileNameZip).CopyHere oApp.Namespace(文件夹名称).items
我得到一个:
运行时错误91,对象变量未设置
拉链音响le创建并在工作文件夹以及要压缩的文件中。我检查了我的变量,并且它们已设置并正确。
Sub Zip_genie()
Dim FileNameZip, FolderName, oFolder
Dim strDate As String, DefPath As String
Dim oApp As Object
DefPath = "c:\users\" & Environ("Username") & "\documents\Appraiser_Genie\working\"
If Right(DefPath, 1) <> "\" Then
DefPath = DefPath & "\"
End If
ChDir DefPath
FileNameZip = "report.zip"
Set oApp = CreateObject("Shell.Application")
'Create empty Zip File
NewZip (FileNameZip)
FolderName = DefPath
Debug.Print (FolderName)
Debug.Print (FileNameZip)
'Copy the files to the compressed folder
oApp.Namespace(FileNameZip).CopyHere oApp.Namespace(FolderName).items
'Keep script waiting until Compressing is done
On Error Resume Next
Do Until oApp.Namespace(FileNameZip).items.count = _
oApp.Namespace(FolderName).items.count
Application.Wait (Now + TimeValue("0:00:01"))
Loop
On Error GoTo 0
'MsgBox "You find the zipfile here: " & FileNameZip
End Sub