实时错误91,对象变量或with块变量未设置
vb 文件夹选择框选择桌面的时候报错:实时错误91,对象变量或with块变量未设置,代码如下:''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
'浏览文件夹按钮
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Private Sub brsFoldBtn_Click()
If shlShell Is Nothing Then
Set shlShell = New Shell32.Shell
End If
Set shlFolder = shlShell.BrowseForFolder(Me.hWnd, "请选择文件夹", BIF_RETURNONLYFSDIRS)
If Not shlFolder Is Nothing Then
foldPath.Text = shlFolder.Items.Item.Path '测试
End If
End Sub 你引用这个了么?Shell32.Shell
这个定义了么 shlShell ,shlFolder
已经引用过了,这个选择框选择其他的文件夹都是没问题的,只有选择“桌面”的时候才会报错 If Not shlFolder Is Nothing Then
foldPath.Text = shlFolder.Items.Item.Path '测试
End If
=>
If Not shlFolder Is Nothing Then
If Not shlFolder.Items Is Nothing Then
If Not shlFolder.Items.Item Is Nothing Then
If Not shlFolder.Items.Item.Path Is Nothing Then
foldPath.Text = shlFolder.Items.Item.Path '测试
End If
End If
End If
End If
应该是你没有new
补充:VB , 控件