2011-11-01 79 views
0

我有一个项目,我需要从zip中提取文件,然后打开该文件。我上周工作的代码:将文件解压缩到VBA中的远程目录

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) '*' 
+0

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

回答

相关问题