【问题标题】:Unzipping a file to a remote directory in VBA将文件解压缩到 VBA 中的远程目录
【发布时间】:2011-11-01 17:18:22
【问题描述】:

我有一个项目,我需要从 zip 中提取文件,然后打开该文件。上周我用代码让它工作了:

 With CreateObject("Shell.Application")
        .Namespace("" & UnZippedFolder).copyhere .Namespace("" & ZipFolder & _ 
                       ZipFile).Items
 End With

当我这周尝试运行它时,我在尝试调试它时遇到了一堆错误。

我已经从“简单”(上图)转变为“尽可能明确”(下图)。我目前收到错误消息“对象变量或未设置块变量”。选择最后带有“*”的行。我不知道为什么会抛出这个错误,或者如何解决它。

Dim WeekNum As Integer
Dim ZipFolder As String
Dim ZipFile As String
Dim UnZippedFile As String
Dim UnZippedFolder As String
Dim objShell
Dim UZipFold
Dim ZipFoldAndFile
If Proceed = False Then Exit Sub

WeekNum = Workbooks("personal.xlsb").Sheets("Dates").Range("WeekNum").Value
ZipFolder = "\\server\path\" ' obfuscated because I must, sorry
ZipFile = "Prefix" & "Week" & WeekNum & " (xlsx 07 format).zip" ' change the 11 to the last 2 digits of the year! 
UnZippedFolder = "\\server\path\" ' obfuscated, again, because I must
UnZippedFile = "Logging_11" & "Week" & WeekNum & " (xlsx 07 format).xlsx"

Set objShell = New Shell
UZipFold = objShell.Namespace("" & UnZippedFolder)
ZipFoldAndFile = objShell.Namespace("" & ZipFolder & ZipFile)

UZipFold.copyhere (objShell.Namespace("" & ZipFolder & ZipFile).Items) '*'

【问题讨论】:

  • 尝试将所有“as String”声明更改为“as Variant”。我似乎记得有这个完全相同的问题,这是因为传递给 Shell 的变量类型是字符串......

标签: vba zip unzip


【解决方案1】:

您必须将路径或传递给 shell 对象的任何内容声明为变体,而不是字符串。

请看这里:http://www.rondebruin.nl/windowsxpunzip.htm

【讨论】:

    猜你喜欢
    • 2018-11-15
    • 1970-01-01
    • 2015-12-26
    • 2013-12-29
    • 1970-01-01
    • 1970-01-01
    • 2023-03-18
    • 2012-10-06
    • 1970-01-01
    相关资源
    最近更新 更多