Try the StringReplaceSubString function. John -----Original Message----- From: jawsscripts-bounce@xxxxxxxxxxxxx [mailto:jawsscripts-bounce@xxxxxxxxxxxxx] On Behalf Of romance's prince Sent: Friday, November 08, 2013 5:54 PM To: jawsscripts@xxxxxxxxxxxxx Subject: [jawsscripts] Re: search and replace using word object model hello friends I've similar task in ms-word I need your help to build macro or jaws script for it. I need to change some words to another depend on font name for example: find word hello font times-new-roman replace to: hi, font Tahoma how I do this? also can I write words in a data file cause I've many words and letters? thanks for your care. beero ----- Original Message ----- From: "Tony Hernandez" <tonyhspeaks@xxxxxxxxx> To: <jawsscripts@xxxxxxxxxxxxx> Sent: Sunday, June 09, 2013 10:25 PM Subject: [jawsscripts] Re: search and replace using word object model Hi Jim, As requested, here's the version that finally works. Let me know what you think or if you have questions. Script FixSpacing () var object oApp, object oDoc, object oSelection, object oFind, object oReplacement, object oRange let oApp = GetObject ("Word.Application") let oSelection = oApp.Selection let oFind = oSelection.Find let oReplacement = oFind.Replacement oFind.ClearFormatting() oReplacement.ClearFormatting() ;spaces between sentences, two, no more, no less. oFind.Execute("([!.][0-9a-zA-Z].) {1,}", True, False, True, False, False, True, WDFindContinue, False, "\\1 ", WdReplaceAll) ;Catch extra space between most words oFind.Execute("([a-zA-Z]) {2,}([a-zA-Z])", True, False, True, False, False, True, WDFindContinue, False, "\\1 \\2", WdReplaceAll) ;colons always followed by two spaces, no more, no less. oFind.Execute("(:) {1,}([a-zA-Z+])", True, False, True, False, False, True, WDFindContinue, False, "\\1 \\2", WdReplaceAll) ;Excuse me doctor. oFind.Execute("(Dr.) {2,}", True, False, True, False, False, True, WDFindContinue, False, "\\1 ", WdReplaceAll) ;Excuse me mister. oFind.Execute("(Mr.) {2,}", True, False, True, False, False, True, WDFindContinue, False, "\\1 ", WdReplaceAll) ;Excuse me miss. oFind.Execute("(Ms.) {2,}", True, False, True, False, False, True, WDFindContinue, False, "\\1 ", WdReplaceAll) ;Excuse me hostpital named after a saint. oFind.Execute("(St.) {2,}", True, False, True, False, False, True, WDFindContinue, False, "\\1 ", WdReplaceAll) EndScript Now, if Word would just use the .net regexps, all would be perfect. I tried accomplishing my task with the Homer regex functions, but that messed up my formatting, e.g., would bold the whole document. Oh well. I hope you find it useful. Thank you Doug for your help. This really cuts down the time I have to take to fix these errors during spellcheck. Anything that saves time when one is paid based on production volume is where it's at. Tony On 6/5/2013 10:28 PM, Jim Snowbarger wrote: > Tony, > I'd love to see the version that finally works. > Pass it along. And, I'll brush up on my reg ex. > > ----- Original Message ----- > From: "Tony Hernandez" <tonyhspeaks@xxxxxxxxx> > To: <jawsscripts@xxxxxxxxxxxxx> > Sent: Wednesday, June 05, 2013 8:54 AM > Subject: [jawsscripts] search and replace using word object model > > > Hi > > The platform I use for my job opens Microsoft Word within said > platform's window. I have had to write special scripts to make things > faster for myself as I get paid by the line, defined as 65 characters > including spaces. I have used the Word object model quite successfully > for most of the scripts except for the one below. JAWS 14 with Windows > XP SP3 32-bit and word 2003. The platform is a medical transcription > program called MScript 360. using wild cards, this script looks for an > expression and replaces it with another expression. I tried the very > same replacement in actual Microsoft Word using the regular search and > replace control+H function, and it works. However, This script seems to > do everything properly until it's time to actually execute the code. > Here it is below. > > Script SpacesBetweenSentences () > var > object oApp, object oDoc, object oSelection, object oFind, object > oReplacement, object oRange, string sText > let oApp = GetObject ("Word.Application") > let oSelection = oApp.Selection > let oFind = oSelection.Find > let oReplacement = oFind.Replacement > oFind.ClearFormatting() > oReplacement.ClearFormatting() > oFind.Text = "([0-9a-zA-Z]{2,}.) {1,}" > oReplacement.Text = "\1 " > oFind.Forward = True > oFind.Wrap = wdFindContinue > oFind.Format = False > oFind.MatchCase = False > oFind.MatchWholeWord = False > oFind.MatchAllWordForms = False > oFind.MatchSoundsLike = False > oFind.MatchWildcards = True > ;the next line is where I think the problem is. > oFind.Execute Replace:=WDReplaceAll > EndScript > > Anyone have any suggestions? Is the syntax in the oFind.Execute > statement correct for the JAWS scripting language? It does compile > without errors. > > Tony > __________� > > View the list's information and change your settings at > http://www.freelists.org/list/jawsscripts > > > > __________� > > View the list's information and change your settings at > http://www.freelists.org/list/jawsscripts > __________� View the list's information and change your settings at http://www.freelists.org/list/jawsscripts __________� View the list's information and change your settings at http://www.freelists.org/list/jawsscripts __________� View the list's information and change your settings at http://www.freelists.org/list/jawsscripts