|
-
Nov 17th, 2005, 09:28 AM
#1
Thread Starter
Lively Member
[RESOLVED] need assistance in debugging my program
how do i debug my program? error description "Run time error '91':" Object variable or With block variable not set
Here is my Code:
VB Code:
Private Sub Command1_Click()
Dim objWdApp As Word.Application
Dim objWdRange As Word.Range
Dim objWdDoc As Word.Document
Dim count As Integer
Dim wdText As String
count = 0
wdText = Text1.Text
Set objWdRange = objWdDoc.Content
With objWdRange.Find
Do While .Execute(FindText:=wdText, Format:=False) = True
count = count + 1
Loop
End With
MsgBox "There are " & count + "words", vbInformation
Set objWdRange = Nothing
End Sub
your help is very much appreciated. thanks in advance.
-
Nov 17th, 2005, 09:30 AM
#2
Re: need assistance in debugging my program
You have not Set the objWdDoc obect variable to anything...
Declan
Don't forget to mark your Thread as resolved.
Take a moment to rate posts that you think are helpful 
-
Nov 17th, 2005, 09:43 AM
#3
Thread Starter
Lively Member
Re: need assistance in debugging my program
how do i set the object variable, can you give me idea on this... please post your code...
-
Nov 17th, 2005, 10:01 AM
#4
Re: need assistance in debugging my program
If you want to set the objWdDoc to a new document then use
VB Code:
Set objWdDoc = objWdApp.Documents.Add
Declan
Don't forget to mark your Thread as resolved.
Take a moment to rate posts that you think are helpful 
-
Nov 17th, 2005, 10:23 AM
#5
Thread Starter
Lively Member
Re: need assistance in debugging my program
how about i am going to count the occurrence of words in the already opened document, what code i am going to use.... example instances are when certain opened documents i am going to use this program.. do i use ActiveDocument? but how?
-
Nov 17th, 2005, 10:27 AM
#6
Thread Starter
Lively Member
Re: need assistance in debugging my program
thanks for a quick reply...
how about this:
VB Code:
Set objWdDoc = objWdApp.ActiveDocument.Content
but there is a an error: This command is not available since no document is open.. it is very much confusing error since i already opened document to count the occurence.. by the way, i am using here microsoft word 2003.
-
Nov 17th, 2005, 10:36 AM
#7
Re: need assistance in debugging my program
 Originally Posted by neo_phyte
This command is not available since no document is open..
OK, in that case you need to open the document you wish to work with.
VB Code:
Set objWdDoc = objWdApp.Documents.Open(FileName:="insert your path and file name here")
Declan
Don't forget to mark your Thread as resolved.
Take a moment to rate posts that you think are helpful 
-
Nov 17th, 2005, 10:50 AM
#8
Thread Starter
Lively Member
Re: need assistance in debugging my program
thanks again, you mean everytime i opened the document i have to change my code? Changing the filename and the path of the filename? how about ActiveDocument property? I think it would be nicer and easier if it is already opened then after opening run the program. How will i do that?
-
Nov 17th, 2005, 10:55 AM
#9
Re: need assistance in debugging my program
Try this, but replace "Test.doc" with the name of the document that you wish to use.
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.Documents("test.doc")
Set objWdRange = objWdDoc.Content
With objWdRange.Find
Do While .Execute(FindText:=wdText, Format:=False) = True
count = count + 1
Loop
End With
MsgBox "There are " & count + "words", vbInformation
Set objWdRange = Nothing
Set objWdDoc = Nothing
End Sub
Declan
Don't forget to mark your Thread as resolved.
Take a moment to rate posts that you think are helpful 
-
Nov 17th, 2005, 11:06 AM
#10
Thread Starter
Lively Member
Re: need assistance in debugging my program
thanks.... i already made it..... success.....
VB Code:
Private Sub Command1_Click()
'Dim objWdApp As Word.Application
Dim objWdRange As Word.Range
Dim objWdDoc As Word.Document
Dim count As Integer
Dim wdText As String
count = 0
wdText = Text1.Text
'Set objWdApp = New Word.Application
Set objWdDoc = Application.ActiveDocument
'Set objWdDoc = objWdApp.ActiveDocument.Content
Set objWdRange = objWdDoc.Content
'objWdApp.Visible = True
With objWdRange.Find
Do While .Execute(FindText:=wdText, Format:=False) = True
count = count + 1
Loop
End With
MsgBox "There are " & count, vbInformation
Set objWdRange = Nothing
Set objWdDoc = Nothing
'Set objWdApp = Nothing
End Sub
thanks for the time that you shared to help me.... i changed to ActiveDocument Property..... but you shared a lot to me.... thanks again.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|