why am i getting "object required" error message

B

BRC

I tried the following code to try to populate a listbox with spelling
errors. I found the code on the web.
I am getting an "object required" error at the " For n = 0 To
UserForm1.ListBox1.ListCount - 1" line.
using word 2003

Sub mySpelling()
Dim mySpellingError
Dim n As Long
Dim myFlag As Boolean
For Each mySpellingError In ActiveDocument.Range.SpellingErrors
myFlag = False
For n = 0 To UserForm1.ListBox1.ListCount - 1
If UserForm1.ListBox1.List(n) = mySpellingError.Text Then
myFlag = True
Next
If myFlag = False Then
UserForm1.ListBox1.AddItem mySpellingError.Text
End If
Next
UserForm1.Show
End Sub



Thanks for any help
 
P

Perry

I presume y're trying to run the macro without UserForm1 being active (or
loaded) right?
If so, the VBA compiler doesn't recognize Userform1.
Kindly correct me, if the above assumption isn't right.

If it is, place a button on UserForm1, and use the macro code under Click()
event code of the button
on you userform.
run UserForm1 and see whether the Listbox gets populated.

--
Krgrds,
Perry

System:
Vista/Office Ultimate
VS2005/VSTO2005 SE
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top