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:
Private Sub Command1_Click() Dim objWdRange As Word.Range Dim objWdDoc As Word.Document Dim count As Integer Dim wdText As String count = 0 wdText = Text1.Text Set objWdDoc = Application.ActiveDocument Set objWdRange = objWdDoc.Content With objWdRange.Find Do While .Execute(FindText:=wdText, Format:=False, _ MatchCase:=True, MatchWholeWord:=False, MatchAllWordForms:=False) = True count = count + 1 Loop End With MsgBox "There are " & count & " words found in this document", vbInformation Set objWdRange = Nothing Set objWdDoc = Nothing 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...




Reply With Quote