首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > VBA >

VBA中奇怪的有关问题

2012-03-12 
VBA中奇怪的问题我有以下的代码SetobjShellCreateObject( Shell.Application )SetobjFolderobjShell.B

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

热点排行