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
Printable View
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
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,
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
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?
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
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.
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 :)
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:
Private Sub Text2_KeyUp(KeyCode As Integer, Shift As Integer) Dim Word As String Dim Prts() As String Dim NewWord As String If KeyCode = vbKeySpace Then Prts = Split(Text2.Text, " ") Word = Prts(UBound(Prts) - 1) Do While Not MyRecordSet.EOF If LCase(Word) = MyRecordSet.Fields("SearchText") Then Text1.Text = Replace(Text2.Text, Word, MyRecordSet.Fields("ReplacementText")) Text1.SelStart = Len(Text2.Text) Exit Sub End If MyRecordSet.MoveNext Loop End If End Sub