尝试使用内置Windows Zip的CopyHere方法时,在VBA中接收错误代码424

时间:2017-08-21 21:39:19

标签: windows vba access-vba zip

我在接下来的行中收到了对象所需的错误,尽管fl4是已定义的变体/对象/文件: oFold.CopyHere (fl4)

任何想法都会受到赞赏。

以下是适用的代码摘录。我已经排除了递归循环和目录子文件夹迭代:

    srcpth = rs1.Fields("Src_File_Path").Value
    destpth = rs1.Fields("Zip_File_Path").Value
    var = 0

    Set FS2 = New FileSystemObject
    Set FS2 = CreateObject("Scripting.FileSystemObject")

    Set fl1 = FS2.GetFolder(srcpth)
    For Each fl2 In FS2.GetFolder(srcpth).SubFolders

        var = 2
        ZipFile = Application.CurrentProject.Path & "\tmp\" & fl2.Name & ".zip"
        Set FS3 = CreateObject("Scripting.FileSystemObject")
        FS3.CreateTextFile(ZipFile, True).Write Chr(80) & Chr(75) & Chr(5) & Chr(6) & String(18, 0)
        Set FS3 = Nothing

            Set FS4 = New FileSystemObject
            Set FS4 = CreateObject("Scripting.FileSystemObject")
            Set fl3 = FS4.GetFolder(fl2)
            For Each fl4 In FS4.GetFolder(fl2).Files
                var = 2
                GoTo Zipxchg
zipxchg_2:
            Next
        Next

Set FS1 = Nothing
Set oFld = Nothing
Set oApp = Nothing
Set oShl = Nothing

Exit Sub

Zipxchg:
If var = 2 Then
    ZipFile = Application.CurrentProject.Path & "\tmp\" & fl2.Name & ".zip"

    Set oApp = CreateObject("Shell.Application")

    Set oFld = oApp.NameSpace(CVar(ZipFile))
    Set FilestoZip = objShell.File(fl4)
    i = oFld.Items.Count
    oFold.CopyHere (fl4)

    Set oShl = CreateObject("WScript.Shell")

        GoTo zipxchg_2

End Sub

1 个答案:

答案 0 :(得分:0)

删除括号....使用oFold.CopyHere fl4 ....括号导致返回一个值,但没有变量(对象)来接收它

相关问题