Delphi-PRAXiS

Delphi-PRAXiS (https://www.delphipraxis.net/forum.php)
-   Programmieren allgemein (https://www.delphipraxis.net/40-programmieren-allgemein/)
-   -   Delphi OleContainer Copy (https://www.delphipraxis.net/190285-olecontainer-copy.html)

danten 20. Sep 2016 07:42

OleContainer Copy
 
Please how can I copy selected text from a Word document in Edit.
The code below is not working.

Thank you

Delphi-Quellcode:
olecontainer1.OleObject.ActiveWindow.Selection.Copy;
  Edit1.Clear;
  Edit1.PasteFromClipboard;

HolgerX 20. Sep 2016 09:16

AW: OleContainer Copy
 
using COM:

Delphi-Quellcode:
uses
  ComObj;

procedure TForm1.Button1Click(Sender: TObject);
var
  WordApp : OleVariant;
  Doc : OleVariant;
  Sel : OleVariant;
begin


  WordApp := GetActiveOleObject('Word.Application'); // Connect to open Word
  try
    try
      Doc := WordApp.ActiveDocument;
      Sel := Doc.ActiveWindow.Selection;

      Edit1.Text := Sel.Text;
// or simple
      Edit1.Text := WordApp.ActiveDocument.ActiveWindow.Selection.Text;

    except
      WordApp.Visible := true;
    end;
  finally
    WordApp := Unassigned;                         // Disconnect
  end;
end;

You did't need the Clipboard!

danten 20. Sep 2016 12:20

AW: OleContainer Copy
 
[QUOTE=HolgerX;1348141]using COM:

Perfect, thank you :thumb:


Alle Zeitangaben in WEZ +1. Es ist jetzt 08:53 Uhr.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024 by Thomas Breitkreuz