Results 1 to 2 of 2

Thread: VBA problem....

  1. #1

    Default VBA problem....


    I am now working one project using VB 6.0 to automate word application. The project will count the occurrence of the word/s in microsoft word application. But i stop since i get a problem on how to highlight the word that i am inputted in Text1.Text. I hope you can help me to finish my project guys. All i wanted is, I have to input a string in Text1.Text and when i clicked the commandbutton, this will count the occurrence and also this will highlight to microsoft word application based on the word or words that i am inputted in Text1.text...

    Here is my code... The problem of this code, all of the text in the word application will be highlighted not the text that i am inputted in Text1.Text.. Please modified my code... There is no problem with the counting since it is correct already...

    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
    
    ' set the color
    
    objWdDoc.Range.HighlightColorIndex = wdYellow
    
    With objWdRange.Find
    
    'condition to set optionbutton to true
    
    If optHighlight.Value = True Then
     .Text = Text1.Text
     .Replacement.Text = ""
     .Execute Replace:= wdReplaceAll
    End If
       
     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

    hope you can help me....


  2. #2

    Default Re: VBA problem....

    i get a problem on how to highlight the word that i am inputted in Text1.Text
    Try these steps:
    1. Start recording a macro.
    2. Type the word "yeahbaby" and highlight it by changing the background/foreground color. If I remember correctly, highlighting multiple text won't work. It's been years since I've last played with VBA though, so I'm not so sure if it still holds true today.
    3. Stop recording the macro.
    4. Edit the macro, and make appropriate changes to generalize the steps (i.e.: change the "yeahbaby" string into a variable).

    Please modified my code...
    Sorry, but I would be taking away the joy of solving this problem. :mrgreen:

  3.    Advertisement

Similar Threads

 
  1. SGPT Problem
    By Ferl in forum Fitness & Health
    Replies: 78
    Last Post: 03-25-2013, 11:44 AM
  2. Problem with your Symbian Cellphone Software?
    By Seņor Joze in forum Gizmos & Gadgets (Old)
    Replies: 421
    Last Post: 08-28-2010, 05:15 PM
  3. Replies: 221
    Last Post: 06-02-2009, 01:22 AM
  4. Playstation 2 Problem
    By baldog in forum Gizmos & Gadgets (Old)
    Replies: 18
    Last Post: 03-02-2006, 08:28 AM
  5. m125 problem
    By eliel73173 in forum Gizmos & Gadgets (Old)
    Replies: 6
    Last Post: 04-29-2005, 01:47 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
about us
We are the first Cebu Online Media.

iSTORYA.NET is Cebu's Biggest, Southern Philippines' Most Active, and the Philippines' Strongest Online Community!
follow us
#top