【发布时间】: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 的变量类型是字符串......