T
Hallo
Ich habe ein kleines Problem mit der Steuerung von Word... Ich möchte bestimmte Zeichenketten suchen und ersetzen. Ich habe 2 Möglichkeiten wobei beide leider nicht funktionieren. Wäre nett wenn mir einer den passenden Hint geben würde
Vielen Dank im vorraus !
MfG
Thorsten
OleVariant Template = EmptyParam;
OleVariant NewTemplate = False;
OleVariant ItemIndex = 1;
try
{
WordApplication->Connect();
}
catch (Exception &exception)
{
MessageDlg("Word may not be installed", mtError, TMsgDlgButtons() << mbYes, 0);
Abort;
}
WordApplication->Visible = True;
Rechnung->ConnectTo(WordApplication->Documents->Open(OleVariant(AnsiString("Z:\\DOKUMENTE\\R&J VORLAGEN\\RECHNUNG.DOT"))));
Rechnung->Activate();
WordApplication->Selection->Find->ClearFormatting();
WordApplication->Selection->Find->Replacement->ClearFormatting();
WordApplication->Selection->Find->Text=AnsiString("Max Mustermann").WideChar(NULL,15);
WordApplication->Selection->Find->Replacement->Text=AnsiString("{KdAnschrift}").WideChar(NULL,14);
WordApplication->Selection->Find->Forward=True;
WordApplication->Selection->Find->Wrap=1;
WordApplication->Selection->Find->Format=False;
WordApplication->Selection->Find->MatchCase=False;
WordApplication->Selection->Find->MatchWholeWord=False;
WordApplication->Selection->Find->MatchWholeWord=False;
WordApplication->Selection->Find->MatchSoundsLike=False;
WordApplication->Selection->Find->MatchAllWordForms=False;
WordApplication->Selection->Find->Execute();
oder 2)
Variant Word;
AnsiString AppName="Word.Application" ;
HWND hPrevApp = FindWindow(NULL,"Microsoft Word");
if(!hPrevApp)
{
Word=CreateOleObject(AppName);
}
else
{
Word=GetActiveOleObject(AppName);
}
Word.OlePropertySet("Visible",true);
Variant NewDocument;
NewDocument=Word.OlePropertyGet("Documents");
NewDocument.OleFunction("Open","Z:\\DOKUMENTE\\R&J VORLAGEN\\RECHNUNG.DOT");
NewDocument.OleFunction("Activate");
//Variant ActiveDocument;
//ActiveDocument=Word.OlePropertyGet("ActiveDocument");
Variant Result;
Result=Word.OlePropertyGet("Selection").OlePropertyGet("Find");
Result.OleFunction("ClearFormatting");
Result.OlePropertyGet("Replacement").OleFunction("ClearFormatting");
Result.OlePropertySet("Text","{KdAnschrift}");
Result.OlePropertyGet("Replacement").OlePropertySet("Text","Max Mustermann");
Result.OlePropertySet("Forward",true);
Result.OlePropertySet("Wrap",1);
Result.OlePropertySet("Format",false);
Result.OlePropertySet("MatchCase",false);
Result.OlePropertySet("MatchWholeWord",false);
Result.OlePropertySet("MatchWildcards",false);
Result.OlePropertySet("MatchSoundsLike",false);
Result.OlePropertySet("MatchAllWordForms",false);
Result.OleFunction("Execute",2);