delphi 用DDE控制Word


本文整理自网络,侵删。

 

DDE(Dynamic Data Exchange),称为动态数据交换。用于进程间的通讯,看看他如何来和Word交互。

在System页签下有TDdeClientConv组件,拖一个放到界面上,然后我们写如下代码:

unit Unit1;


interface


uses

  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,

  Dialogs, OleServer, StdCtrls, DdeMan;


type

  TForm1 = class(TForm)

    Button1: TButton;

    DdeClientConv1: TDdeClientConv;

    procedure Button1Click(Sender: TObject);

  private

    { Private declarations }

//执行word的宏命令

    procedure RunMacro(macname:PChar);

  public

    { Public declarations }

  end;


var

  Form1: TForm1;


implementation


{$R *.dfm}


procedure TForm1.Button1Click(Sender: TObject);

begin

//执行保存文件的宏命令

  RunMacro('[FileSave]');

end;


procedure TForm1.RunMacro(macname: PAnsiChar);

var

  macro: array [0..80] of char;

begin

  //设置于word的连接

  DdeClientConv1.SetLink('WinWord','System');

  //打开连接

  if not DdeClientConv1.OpenLink then

  begin

    ShowMessage('打开连接出错!');

  end;

  if not DdeClientConv1.ExecuteMacro(macname,False) then

  begin

    ShowMessage('执行宏命令出错!');

  end;

end;


end.

相关阅读 >>

Delphi 使控件支持鼠标滚轴消息

老外写的在桌面添加快捷方式(Delphi xe5 android)

Delphi xe10 麦克风、摄像头操作

Delphi xe 中使用正则表达式

Delphi tdictionary 泛型如何排序

Delphi firemonkey 保存图片到jpg的方法 bmp转jpg

Delphi简单判断程序30秒没有键盘和鼠标动作示例

Delphi 四舍五入含小数点函数

Delphi 更改窗体为顶层窗体不闪烁

Delphi 游戏测试call

更多相关阅读请进入《Delphi》频道 >>



打赏

取消

感谢您的支持,我会继续努力的!

扫码支持
扫码打赏,您说多少就多少

打开支付宝扫一扫,即可进行扫码打赏哦

分享从这里开始,精彩与您同在

评论

管理员已关闭评论功能...