|
-
Nov 20th, 2005, 01:23 AM
#1
Thread Starter
Lively Member
Counter Problem....
good day guys, i need your assistance on this matter. i am planning to add optionbutton or checkbox to my form. This optionbutton or checkbox is used when i am going to Highlight the text that i am inputted in Text1.Text. When optionbutton becomes true or checkbox becomes true, the text that i am inputted in Text1.text will automatically highlight in the microsoft word application.
here is my existing code, please modify my code to complete my project.
VB Code:
Private Sub Command1_Click()
On Error Goto ErrTrap
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
Exit Sub
ErrTrap:
If Err.Number = 429 Then
Msgbox "You cannot start the counting operation, please open a document", vbOKOnly + vbExclamation, "No document opened"
Else
Msgbox "An error of " & Err.Number & " " has occured. This means " & Err.Description
End If
End Sub
i am a starter of any programming language... but i try my best to learn more... and this is my new start, to learn more visual basic... my current job is word processor, and i made my macro just to automate my work.... thanks for the help guys... hope you can help me for this.
Last edited by neo_phyte; Nov 29th, 2005 at 05:39 AM.
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
|