Results 1 to 26 of 26

Thread: Counter Problem....

Threaded View

  1. #1

    Thread Starter
    Lively Member neo_phyte's Avatar
    Join Date
    Nov 2005
    Location
    Cebu, Philippines
    Posts
    71

    Wink 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:
    1. Private Sub Command1_Click()
    2. On Error Goto ErrTrap
    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. Exit Sub
    27. ErrTrap:
    28. If Err.Number = 429 Then
    29.    Msgbox "You cannot start the counting operation, please open a document", vbOKOnly + vbExclamation, "No document opened"
    30. Else
    31.    Msgbox "An error of " & Err.Number & " " has occured.  This means " & Err.Description
    32. End If
    33. 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
  •  



Click Here to Expand Forum to Full Width