2015-01-11 90 views
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 

回答

0

嘗試指定zip文件的完整路徑名。

例如,而不是隻:

FileNameZip = "report.zip" 

用途:

FileNameZip = "c:\users\" & Environ("Username") & "\documents\Appraiser_Genie\target\report.zip" 

...或者無論您report.zip文件

相關問題