谁能帮我如何在vba中初始化对象文件夹

问题描述 投票:0回答:1

我有一个问题

案例1:

downloadFolder = "C:\Users\ACER\AppData\Local\Temp\"
If Not shellApp.Namespace(downloadFolder) Is Nothing Then
   
    MsgBox "Success"
Else
    MsgBox "Error: " & downloadFolder
End If`

===>>>> 输出:“错误:C:\Users\ACER\AppData\Local\Temp”

案例2:

If Not shellApp.Namespace("C:\Users\ACER\AppData\Local\Temp\") Is Nothing Then
   
    MsgBox "Success"
Else
    MsgBox "Error: " & downloadFolder
End If`

===>>>> 输出:“成功”

.net vba ms-word
1个回答
0
投票

shellApp.Namespace 需要一个变体作为参数。 如果“downloadFolder”定义为字符串,则会发生此“错误”。

例如:

Dim downloadFolder as String 
downloadFolder = "C:\Users\ACER\AppData\Local\Temp\"

If Not shellApp.Namespace(downloadFolder) Is Nothing Then   
    MsgBox "Success"
Else
    MsgBox "Error: " & downloadFolder
End If

将返回“错误:C:\Users\ACER\AppData\Local\Temp”

为了避免这种情况,您可以将“downloadFolder”定义为 Variant:

Dim downloadFolder as Variant

或者将“downloadFolder”放在括号之间,如下所示:

If (Not shellApp.Namespace((downloadFolder)) Is Nothing) Then
© www.soinside.com 2019 - 2024. All rights reserved.