Results 1 to 8 of 8

Thread: the replace function in word

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Dec 2005
    Posts
    88

    the replace function in word

    Hi guys,

    just wondering if i could create a macro which replaced a word with another word, which were stored in a macro. For example when the user types in Hello it checks the databse and then replaces it by another word lets say Bye.

    Caz

  2. #2
    Frenzied Member cssriraman's Avatar
    Join Date
    Jun 2005
    Posts
    1,465

    Re: the replace function in word

    It is possible to do that. For example you can achieve the same thing by using another document. You create a new document with a table with 2 column one for find string and another for replace string. Using VBA code search the first column string in your document and replace it with the 2nd column.

    This is just an idea. if you need more help on that please reply.

    Regards,
    CS

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Dec 2005
    Posts
    88

    Re: the replace function in word

    yeh that sounds excellent, how would i refernce it to the table in the other word document?

    would the other document have to be open?>

    thanks for the help.

    caz

  4. #4
    Lively Member New2vba's Avatar
    Join Date
    Sep 2005
    Location
    UK
    Posts
    95

    Re: the replace function in word

    This might sound a little simple, but can you not achieve your objective using Word's built in find and replace feature or, for replacement as you type, autocorrect feature?
    "Those things we must learn to do, we must learn by doing" (or hope somebody else will take pity and help out )

  5. #5

    Thread Starter
    Lively Member
    Join Date
    Dec 2005
    Posts
    88

    Re: the replace function in word

    well not really cos there will be quite a few entries to change so i would keep on having to use the find and replace function, i think.

    And in the end i would like it (if possible) to be at real time, so once you enter a word the program checks the database and then replaces it.

    caz

  6. #6
    Frenzied Member DKenny's Avatar
    Join Date
    Sep 2005
    Location
    on the good ship oblivion..
    Posts
    1,171

    Re: the replace function in word

    Have a look at post #4 here on how to parse a textstream

    The effort here was to change HTML tags, but the same approach can be used for your requirement, basically saving the list of find and replace values in a text file.
    Declan

    Don't forget to mark your Thread as resolved.
    Take a moment to rate posts that you think are helpful

  7. #7
    Lively Member New2vba's Avatar
    Join Date
    Sep 2005
    Location
    UK
    Posts
    95

    Re: the replace function in word

    To do the intial find and replace then maybe a separate table would be better than using Word's built-in function if there are a lot of Words to replace. However, I would think that you could use code in conjunction with find and replace to modify your document in one sweep - maybe an array would help?

    As for real time modifications - this is exactly what Word's autocorrect feature does. Maybe the following post will be useful.

    http://www.vbforums.com/showthread.php?t=237685

    The test document posted by Opus may be the sort of thing you are looking for?

    EDIT: Look's like DKenny solved your problem while I was busy typing
    "Those things we must learn to do, we must learn by doing" (or hope somebody else will take pity and help out )

  8. #8

    Thread Starter
    Lively Member
    Join Date
    Dec 2005
    Posts
    88

    Re: the replace function in word

    cheers guys I am looking threw them.

    I have kinda found a way just expanding on a previous example I had, but I cant get it working. COuld you please look at the code and see if you can spot anyhting. cheers


    VB Code:
    1. Private Sub Text2_KeyUp(KeyCode As Integer, Shift As Integer)
    2. Dim Word As String
    3. Dim Prts() As String
    4. Dim NewWord As String
    5.  
    6.     If KeyCode = vbKeySpace Then
    7.         Prts = Split(Text2.Text, " ")
    8.        
    9.         Word = Prts(UBound(Prts) - 1)
    10.        
    11.         Do While Not MyRecordSet.EOF
    12.             If LCase(Word) = MyRecordSet.Fields("SearchText") Then
    13.                 Text1.Text = Replace(Text2.Text, Word, MyRecordSet.Fields("ReplacementText"))
    14.                 Text1.SelStart = Len(Text2.Text)
    15.                 Exit Sub
    16.             End If
    17.         MyRecordSet.MoveNext
    18.         Loop
    19.        
    20.     End If
    21. End Sub

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