PDA

View Full Version : Array question: what am I assigning?



Peskarik
02-19-2008, 10:51 AM
:think:
Hello, everybody

I have an open Word document where I have written a sentence.
Now I want to display a message box with each word in a sentence.

Easy way:

Sub MyWords()
For Each oWord in ThisDocument.Words
MsgBox oWord.Text
Next
End Sub

But why does not the following work? :(

Sub DisplayWords()
Dim i As Integer
Dim myWords()
ReDim myWords(ThisDocument.Words.Count)
myWords = ThisDocument.Words

For i = 1 To UBound(myWords)
MsgBox myWords(i).Text
Next
End Sub

I have problems understanding what exactly I am assigning to the array myWords.:dunno

Please, explain what is wrong with this code? :mkay

Bob Phillips
02-19-2008, 10:57 AM
Because Words is a collection, not an array.

Bob Phillips
02-19-2008, 10:57 AM
And this is the Excel forum not Word.

Peskarik
02-19-2008, 11:02 AM
Yes, Excel forum, sorry.