Copying the contents of an internet explorer window programmatically using Ctrl-A and Ctrl-C

Here's my problem and how I solved it.

For every internet explorer window that is open on my desktop I want to be
able to activate it, select its contents and copy it (actually I'm going to
paste it into excel).

The method I have chosen uses sndkeys32.pas which is hidden away as an extra
on the Delphi install disc (see where it is below).

sndkeys32.pas has two functions which: 1. activate a window given its title
and 2. sends a specific key sequence to the active window.

So, to copy all the contents all I have to do is activate each IE window,
send Ctrl-A (select all) then Ctrl-C (copy)

For any other poor saps out there (and judging by google groups there are
hundreds) here's the code:

{*******************************************}

// This code works through the open internet explorer windows on the
desktop,
// gets each window's title, then uses this title to activate each window
using
// AppActivate, then uses SendKeys to send first Ctrl-A (to select
everything
// in the window), then Ctrl-C (to copy it to the clipboard).

interface

uses
  Windows,Messages, SysUtils, Classes, Graphics, Controls,Forms,
Dialogs,ShDocVw,
  StdCtrls,comobj,OleServer,DdeMan,Sndkey32;

type
  TForm1 = class(TForm)
    Button1: TButton;
    procedure Button1Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.DFM}

procedure TForm1.Button1Click(Sender: TObject);

var
  i : Integer;
  ShellWindows : IShellWindows;
  Browser : IWebBrowser2;
  IE : OLEVariant;
  Windowtext: array[0..255] of char;

begin
    ShellWindows := CoShellWindows.Create;
  for i := 0 to ShellWindows.Count - 1 do
    if Supports(ShellWindows.Item(i),IWebBrowser2, Browser) then
      begin
      getwindowtext(browser.hwnd,Windowtext,255);
      showmessage(windowtext);
      AppActivate(windowtext);
      SendKeys('^a 1',FALSE);
      SendKeys('^c 1',FALSE);
      end;

end;

end.
{**************************}

SendKeys and AppActivate are in Sndkey32.pas which is on the Delphi5 disc in
info\extras\SendKeys folder.