Find & Replace formatting in Word

J

Jim Jackson

I have been creating and updating a Word document from my Delphi 6 program.
With Word 2002 (Office 10) I cannot figure out what my
problem is. The following code works with the previous version of Word but
not with 2002. All I am trying to do is replace one font color with
another.

procedure FinalizeWrdRange(Range: Word2000.Range);
var
v1, v2, v3, v4, v5, v6: OleVariant; // for Ole parameter passing
begin
Range.WholeStory;
Range.Find.ClearFormatting;
Range.Find.Font.Color := wdColor Pink; // <--- fails on this
line
Range.Find.Replacement.ClearFormatting;
Range.Find.Replacement.Font.Color := wdColorSkyBlue;
v1 := '';
v2 := wdFindContinue;
v3 := True;
v4 := '';
v5 := wdReplaceAll;
v6 := True;
Range.Find.Execute(v1, EmptyParam, EmptyParam, v6, EmptyParam,
EmptyParam, EmptyParam, v2, v3, v4, v5, EmptyParam, EmptyParam,
EmptyParam, EmptyParam);
end;

When tracing the code I get
Range.Find.Font = nil
and Range.Find.Replacement = nil

Do I have to start instantiating a Font and Replacement objects and assign
them? If so how?

Any ideas?

TIA,
Jim
 
G

Guest

-----Original Message-----
I have been creating and updating a Word document from my Delphi 6 program.
With Word 2002 (Office 10) I cannot figure out what my
problem is. The following code works with the previous version of Word but
not with 2002. All I am trying to do is replace one font color with
another.

procedure FinalizeWrdRange(Range: Word2000.Range);
var
v1, v2, v3, v4, v5, v6: OleVariant; // for Ole parameter passing
begin
Range.WholeStory;
Range.Find.ClearFormatting;
Range.Find.Font.Color := wdColor Pink; // <-- - fails on this
line
Range.Find.Replacement.ClearFormatting;
Range.Find.Replacement.Font.Color := wdColorSkyBlue;
v1 := '';
v2 := wdFindContinue;
v3 := True;
v4 := '';
v5 := wdReplaceAll;
v6 := True;
Range.Find.Execute(v1, EmptyParam, EmptyParam, v6, EmptyParam,
EmptyParam, EmptyParam, v2, v3, v4, v5, EmptyParam, EmptyParam,
EmptyParam, EmptyParam);
end;

When tracing the code I get
Range.Find.Font = nil
and Range.Find.Replacement = nil

Do I have to start instantiating a Font and Replacement objects and assign
them? If so how?

Any ideas?

TIA,
Jim


Hi Jim,
I'm not familiar with Delphi at all so I can't address
your specific code. However I can tell you that I have
also been experiencing problems in Word 2002, although my
problems relates to an inhouse-OLE object that is sizing
wrong only in this version of Word. Currently I am trying
to get a hold of a MS Hotfix:

822865
Word 2002 Post sp-2 Hotfix June 20, 2003

This may be a shot in the dark, but if may be worth a try.
-Mike
 
J

Jim Jackson

Hi Jim,
I'm not familiar with Delphi at all so I can't address
your specific code. However I can tell you that I have
also been experiencing problems in Word 2002, although my
problems relates to an inhouse-OLE object that is sizing
wrong only in this version of Word. Currently I am trying
to get a hold of a MS Hotfix:

822865
Word 2002 Post sp-2 Hotfix June 20, 2003

This may be a shot in the dark, but if may be worth a try.
-Mike

Hi Mike,
Your guess is right, I had gone to the MS Office updates and loaded all of
the updates for Office and my problem went away with no change to my code.
http://office.microsoft.com/home/default.aspx
Thanks for your reply,
Jim
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top