Recent

Author Topic: [SOLVED] Word: search and replace (again)  (Read 3048 times)

w click

  • Full Member
  • ***
  • Posts: 180
[SOLVED] Word: search and replace (again)
« on: May 06, 2016, 01:45:34 pm »
I've solved the search-and-replace in Microsoft Word problem (thanks to wp), but his a snag trying to search-and-replace in a particular style.

Code: Pascal  [Select][+][-]
  1.   WordApp.Selection.Find.ClearFormatting;
  2.   WordApp.Selection.Find.Text := s;
  3. // wordapp.selection.find.font.italic:=true;
  4.   WordApp.selection.find.replacement.clearformatting;
  5.   WordApp.Selection.Find.Replacement.Text := t;
  6.   WordApp.Selection.Find.Forward := True;
  7.   WordApp.Selection.Find.MatchAllWordForms := False;
  8.   WordApp.Selection.Find.MatchCase := False;
  9.   WordApp.Selection.Find.MatchWildcards := False;
  10.   WordApp.Selection.Find.MatchSoundsLike := False;
  11.   WordApp.Selection.Find.MatchWholeWord := False;
  12.   WordApp.Selection.Find.MatchFuzzy := False;
  13.   WordApp.Selection.Find.Wrap:=1;
  14.   WordApp.Selection.Find.Format:=False;
  15.  

I'm guessing it's something like 'wordapp.selection.find.style' or 'wordapp.selection.find.format', but what do I set it to?

Also, specifying headers and also user created styles.
« Last Edit: May 07, 2016, 11:17:37 am by w click »

wp

  • Hero Member
  • *****
  • Posts: 11858
Re: Word: search and replace (again)
« Reply #1 on: May 06, 2016, 02:04:18 pm »
In Word, record a macro doing the kind of search you need, and look at the macro code?

w click

  • Full Member
  • ***
  • Posts: 180
Re: Word: search and replace (again)
« Reply #2 on: May 06, 2016, 03:57:55 pm »
I can do it with a Word macro, but I need to do it from a program.

wp

  • Hero Member
  • *****
  • Posts: 11858
Re: Word: search and replace (again)
« Reply #3 on: May 06, 2016, 04:21:28 pm »
No, you don't understand me: I mean to use a macro only to learn what Word expects to be called and to be in the parameter list. After recording the macro, open the macro, and in the macro editor you'll see the commands it is using. Then you can copy these commands into your Lazarus source code. Some adaption will be required here and there, but you'll get at least the names of the commands, of the parameters and and their values.

w click

  • Full Member
  • ***
  • Posts: 180
Re: Word: search and replace (again)
« Reply #4 on: May 06, 2016, 06:32:00 pm »
You are a genius.  As with all great ideas, obvious once you know it - brilliant, utterly brilliant.

Thank you.

Worked second time (typos wrecked the first attempt), except that the replacement text is all in CAPITALS, not lower case.  I can live with that, but it irks as it's not perfect.

w click

  • Full Member
  • ***
  • Posts: 180
Re: [SOLVED] Word: search and replace (again)
« Reply #5 on: May 07, 2016, 11:18:57 am »
The style I was trying to change was set to 'small caps', so, of course, it came across as capitals - silly me.

wp, thanks again, if you are in the Birmingham, UK, area, do come and claim the pint I owe you.

 

TinyPortal © 2005-2018