Re: Declaring

Tech Tip: Click here to run a free scan for Windows Errors and optimize PC performance



ProofreadingErrors is actually a collection of Range objects. So while 'as
object' will work, 'as Range' would be better.

In the spirit of good discipline, when you declare object variables it is
better to be explicit about the library that defines them --

Dim oSPErrors as Word.ProofreadingErrors
Dim oSPError as Word.Range

Doesn't make any difference with ProofreadingErrors because there's unlikely
to be any ambiguity; but it can matter with objects like Range -- Excel
(amongst others) has Range objects also, and they are not interchangeable.
If you added a reference to Excel to your application, VBA would have to
guess which kind of Range you meant. In fact it uses the order in which the
references are listed.

Similarly, when you create objects --

Set oSPError as new Word.Range






"Greg Maxey" <gmaxey@xxxxxxxxxxxxxxxxxxx> wrote in message
news:OBLxoLyNFHA.1476@xxxxxxxxxxxxxxxxxxxxxxx
>I am trying to discipline myself to properly declare variable. In the
>example below it took me 15 minutes to stumble on Oject to work with
>oSpError. Is Object the right choice in this case?
>
> Sub printSpellingErrors()
> Dim oSpErrors As ProofreadingErrors
> Dim oSpError As Object
>
> Set oSpErrors = ActiveDocument.Range.SpellingErrors
>
> For Each oSpError In oSpErrors
> .......
>
>
>
>
> --
> Greg Maxey/Word MVP
> See:
> http://gregmaxey.mvps.org/word_tips.htm
> For some helpful tips using Word.
>


.