G
Greg
Wading into new territory here. When using a collection, how should it
be declared and set?
The below example seems to work, but I was wondering if it is more
appropriate or stable to both declare and set like:
Dim oBMCol as Collection
Set oBMCol = New Collection
Sub LessonCollection1()
Dim i As Integer
Dim ItemCount As Integer
ItemCount = ActiveDocument.Bookmarks.Count
Dim oBMCol As New Collection
For i = 1 To ItemCount
If InStr(ActiveDocument.Bookmarks(i).Name, "Test") <> 0 Then
oBMCol.Add "Bookmark " & i & " name: " & _
ActiveDocument.Bookmarks(i).Name
End If
Next i
'Now read back
For i = 1 To oBMCol.Count
MsgBox oBMCol(i)
Next i
End Sub
Maybe neither method is best so I am anxious to hear from an expert.
be declared and set?
The below example seems to work, but I was wondering if it is more
appropriate or stable to both declare and set like:
Dim oBMCol as Collection
Set oBMCol = New Collection
Sub LessonCollection1()
Dim i As Integer
Dim ItemCount As Integer
ItemCount = ActiveDocument.Bookmarks.Count
Dim oBMCol As New Collection
For i = 1 To ItemCount
If InStr(ActiveDocument.Bookmarks(i).Name, "Test") <> 0 Then
oBMCol.Add "Bookmark " & i & " name: " & _
ActiveDocument.Bookmarks(i).Name
End If
Next i
'Now read back
For i = 1 To oBMCol.Count
MsgBox oBMCol(i)
Next i
End Sub
Maybe neither method is best so I am anxious to hear from an expert.