【发布时间】:2015-06-30 01:44:58
【问题描述】:
我正在尝试使用 Excel VBA 提取 .CAB 文件,但出现以下错误:
运行时错误“91”:对象变量或未设置块变量
当我忘记将 Set 与 Object 一起使用时,我通常会得到这个,但我已经检查过了。
我能找到的所有例子都是这个主题的变体:
Private Function DeCab(vSource, vDest) As Long
Dim objShell, objFileSource, objFileDest As Object
Set objShell = CreateObject("Shell.Application")
Set objFileSource = objShell.Namespace(vSource)
Set objFileDest = objShell.Namespace(vDest)
Call objFileDest.MoveHere(objFileSource.Items, 4 Or 16) 'Fails here
Decab = objFileDest.Items.Count
End Function
Set 行没有失败,但它会将 objFileSource 和 objFileDest 设置为 Nothing,即使我已经确认 vSource 和 vDest 存在。
为了确认它与 .CAB 文件无关,我也尝试过不设置 objFileSource 并在设置后检查 objFileDest 的值。它仍然返回Nothing。为什么会这样?我使用的是 64 位 Windows 7,运行 Office 2010。
【问题讨论】:
-
vSource 和 vDest 都是字符串变量吗?尝试变体。