如何在VBA中将变量指定给对象属性

如何在VBA中将变量指定给对象属性,vba,excel,ole,Vba,Excel,Ole,我正在尝试从Shell.Application对象动态设置namespace属性 With CreateObject("Shell.Application").Namespace(FolderName) ExtendProperty = .GetDetailsOf(.Items.Item(FileName), 143) End With 当FolderName和FileName的值固定(硬编码)时,代码段工作。但是当我试图把它们作为变量传递进来时;错误运行时错误91-对象变量或未设置块

我正在尝试从
Shell.Application
对象动态设置
namespace
属性

With CreateObject("Shell.Application").Namespace(FolderName)
    ExtendProperty = .GetDetailsOf(.Items.Item(FileName), 143)
End With

FolderName
FileName
的值固定(硬编码)时,代码段工作。但是当我试图把它们作为变量传递进来时;错误
运行时错误91-对象变量或未设置块变量。
正在返回。我还需要将返回值分配给变量,以供以后使用<代码>扩展属性。我对VBA有点陌生,在internet上找不到关于这个特定情况的任何东西(范围、局部变量等)。

为了避免提到的错误,将变量作为变量传递

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

为避免上述错误,请将变量作为变量传递

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