Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Working with TWordDocument...

Status
Not open for further replies.

joacir

Programmer
Oct 11, 2003
2
BR
How can I replace with a TWordDocument??
I try this:

OleVariant Search,Wrap,Replace,All;

Search="test";
Replace="ok";
Wrap=wdFindContinue;
All=wdReplaceAll;

WordDocument1->Content->Find->Execute(Search,EmptyParam,EmptyParam,EmptyParam,EmptyParam,EmptyParam,EmptyParam,Wrap,EmptyParam,Replace,All,EmptyParam,EmptyParam,EmptyParam,EmptyParam);

but msword give error...

anybody can help me?!
(sorry...inglish!)

Tks.
 
What are the Components? Office97, Office2k?

Here is an ex. for Delphi7-Office2k.

procedure TMainForm.ReplaceWordText(t, r: string; ra: boolean);
var
_text : OleVariant;
_replacement: OleVariant;
_replace : OleVariant;
begin
if (Assigned(wapp)) then begin
_text := t;
_replacement := r;
if (ra) then
_replace := wdReplaceAll
else
_replace := EmptyParam;
with wapp.Selection.Find do begin
ClearFormatting;
Replacement.ClearFormatting;
Wrap := wdFindContinue;
Format := False;
MatchCase := False;
MatchWholeWord := False;
MatchWildCards := False;
MatchSoundsLike := False;
MatchAllWordForms:= False;
ExecuteOld(_text,EmptyParam,EmptyParam,EmptyParam,EmptyParam,EmptyParam,
EmptyParam,EmptyParam,EmptyParam,_replacement,_replace);
end;
end;
end;

If interested, i try to migrate to C++ Builder.
 

The components are office2k.

i try to migrate to C++builder,
but don't work...

he not accept the procedure:
WordDocument->Content->Find->Replacement->ClearFormatting();

and not accept replace the values from properties:
WordDocument->Content->Find->Wrap=wdFindContinue;
WordDocument->Content->Find->Format=false;
WordDocument->Content->Find->MatchCase=false;
WordDocument->Content->Find->MatchWholeWord=false;
WordDocument->Content->Find->MatchWildcards=false;
WordDocument->Content->Find->MatchSoundsLike=false;
WordDocument->Content->Find->MatchAllWordForms=false;

if try execute, without this properties...
the procedure "Execute" or "ExecuteOld", returns "true",
but not replace the text and not select the text searched...

tk for help...
if you get migrate to C Builder, please help!


 
hi joacir,

the following code works for me.

//------------------------------------------Connect it
.
.
wapp->Connect();
wdoc->ConnectTo(wapp->ActiveDocument);
.
.



//------------------------------------------Change it

AnsiString s = &quot;<EMPFAENGER>&quot;;
AnsiString d = &quot;Erwin Lottermann&quot;;

OleVariant _text;
OleVariant _replacement;
OleVariant _replace;
OleVariant OleFalse;

OleFalse = false;
_text = s;
_replacement = d;
_replace = wdReplaceAll;

wapp->Selection->Find->ClearFormatting();
wapp->Selection->Find->Replacement->ClearFormatting();
wapp->Selection->Find->Wrap = wdFindContinue;
wapp->Selection->Find->Format = OleFalse;
wapp->Selection->Find->MatchCase = OleFalse;
wapp->Selection->Find->MatchWholeWord = OleFalse;
wapp->Selection->Find->MatchWildcards = OleFalse;
wapp->Selection->Find->MatchSoundsLike = OleFalse;
wapp->Selection->Find->MatchAllWordForms = OleFalse;

wapp->Selection->Find->Execute(_text,EmptyParam,EmptyParam,
EmptyParam,EmptyParam,EmptyParam,
EmptyParam,EmptyParam,EmptyParam,
_replacement,_replace);



instead of the TWordDocument (wdoc) i use a TWordApplication (wapp). It's important pass an OleVariant to the Execute/ExecuteOld function. If you pass an const &quot;<EMPFAENGER>&quot;/&quot;Erwin Lottermann&quot; there will be no changes/replaces in your Document.

greetings, sam
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top