我正在尝试从namespace
对象动态设置Shell.Application
属性。
With CreateObject("Shell.Application").Namespace(FolderName)
ExtendProperty = .GetDetailsOf(.Items.Item(FileName), 143)
End With
当FolderName
和FileName
的值固定(硬编码)时,代码片段正常工作。但是当我尝试将它们作为变量传递时;错误Run-time error 91 - Object variable or With Block variable not set.
返回。另外,我需要将返回值分配给变量以供以后使用; ExtendProperty
。我对VBA有点陌生,对于这种特定情况,我在Internet上找不到任何内容(范围,本地人等)。
答案 0 :(得分:3)
为避免上述错误,请将变量作为变量传递
Sub TEST2()
Dim ExtendProperty As Variant
Dim folderName As Variant, FileName As Variant
folderName = "C:\Users\User\Desktop\TestFolder"
FileName = "Test.xlsx"
With CreateObject("Shell.Application").Namespace(folderName)
ExtendProperty = .GetDetailsOf(.Items.item(FileName), 143)
End With
End Sub