[jawsscripts] Re: search and replace using word object model

  • From: Csaba Godo <arpadhazi68.jawsul@xxxxxxxxx>
  • To: jawsscripts@xxxxxxxxxxxxx
  • Date: Sat, 09 Nov 2013 16:59:44 +0100

Hi Pero,

I propose you to use the record macro feature of Word. You should record 
one simple find and replace operation and a simple font type changing 
operation. If you have recorded it, you can study the recorded VB macro 
and you can write our own find and replace script based on it. I suggest 
you to use the built-in VBA than JAWS Basic, because the VBA has a reach 
object modell and you can write much simpler the macro for Word, than in 
JAWS Basic, wich is not object oriented and has a very poor command set. 
By the way, if you write your find and replace macro in VBA, you can 
call it from JAWS Basic, too, using CreateObject or CreateObjectEx 
commands. In VBA you can create, if you have installed MS Access or 
Excel, a database and you can write the words into it, too.

HTH

Csaba


2013.11.09. 1:54 keltezéssel, romance's prince írta:
> 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

Other related posts: