VBA中奇怪的问题
我有以下的代码
Set objShell = CreateObject( "Shell.Application ")
Set objFolder = objShell.BrowseForFolder(0, "select folder ", 0, 0)
Set myFolders = objFolder.Items()
Dim i As Integer
For i = 1 To myFolders.Count
MsgBox myFolders.Item(i).Path
Next i
当我写myFolders.Item(i).Path时抱错,但写myFolders.Item(1).Path时却没有问题,不知道是怎么回事?
哪位指导一下,谢了!
[解决办法]
不太清楚,不过下面的代码是可以正常执行的:
Sub Test()
On Error Resume Next
Dim objFolder As Folder
Set objShell = CreateObject( "Shell.Application ")
Set objFolder = objShell.BrowseForFolder(0, "select folder ", 0, 0)
Dim i As Integer
For i = 1 To objFolder.Items.Count
Debug.Print objFolder.Items.Item(i).Path
Next i
End Sub
[解决办法]
Set objShell = CreateObject( "Shell.Application ")
Set objFolder = objShell.BrowseForFolder(0, "select folder ", 0, 0)
Set myFolders = objFolder.Items()
Set myFolder = myFolders.Item
For Each myFolder In myFolders
MsgBox myFolder.Path
Next