The problem of this code is that if there is no word document opened then i have to used this program, i get an error "ActiveX component can't create object" Run-time error '429'. I want to trap this error using error handling if there is no word document opened but the problem is how to code this.

This is my code:

VB Code:
  1. Private Sub Command1_Click()
  2.  
  3. Dim objWdRange As Word.Range
  4. Dim objWdDoc As Word.Document
  5. Dim count As Integer
  6. Dim wdText As String
  7.  
  8. count = 0
  9. wdText = Text1.Text
  10.  
  11. Set objWdDoc = Application.ActiveDocument
  12. Set objWdRange = objWdDoc.Content
  13.  
  14. With objWdRange.Find
  15.      
  16.  Do While .Execute(FindText:=wdText, Format:=False, _
  17.  MatchCase:=True, MatchWholeWord:=False, MatchAllWordForms:=False) = True
  18.     count = count + 1
  19.  
  20.  Loop
  21.  
  22. End With
  23. MsgBox "There are " & count & " words found in this document", vbInformation
  24. Set objWdRange = Nothing
  25. Set objWdDoc = Nothing
  26.  
  27.  
  28. End Sub

please solve my problem... i need your help... i want to trap this error if there is no document opened. all i need is if i clicked the commandbutton and there is no document opened... there is a message "you cannot start the counting operation, please opened a document"... but the problem.. how i am going to code that... please help...