Я получаю некоторые неожиданные результаты от имени типа и в тупике. Надеюсь, некоторые могут указать мне в правильном направлении.
Private Sub T()
Dim d As Word.Document
Dim s As String
Dim c As Collection
Dim i As Long
Dim o As Object
Set d = ActiveDocument
s = "X"
Set c = New Collection
Debug.Print "d is a " & TypeName(d)
Debug.Print "s is a " & TypeName(s)
Debug.Print "c is a " & TypeName(c)
c.Add (d)
c.Add (s)
For i = 1 To c.count
Debug.Print "Item " & i & " of the collection is a " & " " & TypeName(c.Item(i))
Next i
End Sub
Из чего я получаю следующий вывод:
d is a Document
s is a String
c is a Collection
Item 1 of the collection is a String
Item 2 of the collection is a String
Я ожидал получить следующее:
d is a Document
s is a String
c is a Collection
Item 1 of the collection is a Document
Item 2 of the collection is a String
Любые идеи, почему я получаю «String» вместо «Document» для первого элемента в коллекции?