tmo*_*e82 1 shell excel vba excel-vba
我正在尝试使用Excel VBA提取.CAB文件,但是我收到以下错误:
运行时错误'91':
对象变量或未设置块变量
当我忘记使用SetObject时,我通常会得到这个,但我已经检查过了.
我能找到的所有例子都是这个主题的变体:
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
Run Code Online (Sandbox Code Playgroud)
这不是失败就Set行,但它都设置objFileSource以及objFileDest到Nothing即使我已经证实vSource和vDest存在.
要确认它与.CAB文件无关,我也尝试过它而不设置objFileSource和检查设置objFileDest后的值.它仍然会回来Nothing.那为什么会这样?我在运行Office 2010的Windows 7,64位上运行.
您的参数必须以Variant而不是String的形式提交
Sub Tester()
Dim src, dest '<< works
'Dim src As String, dest As String '<< gives the error you see
src = "D:\temp\test.zip"
dest = "D:\temp\unzip"
DeCab src, dest
End Sub
Run Code Online (Sandbox Code Playgroud)
https://msdn.microsoft.com/en-us/library/windows/desktop/bb774085(v=vs.85).aspx