将 table 从一个 word 文档复制并粘贴到另一个 SAS DDE

Copy and paste a table from one word document to another SAS DDE

我正在使用 SAS v9.4,运行 通过 DDE 连接到 Word 2010。

我想将整个 table 从一个 word 文档复制并粘贴到另一个文档。 table 已添加书签 "IDX",我可以使用以下代码 select table:

options noxsync noxwait xmin;
filename sas2word dde 'winword|system';
data _null_;
  file sas2word;
  put '[EditGoTo.Destination = "IDX"]';
  put '[TableSelectTable]';
run;

我已经尝试了 put '[ctrl+c]';put '[copy]';put '[TableCopy]';put '[SelectionCopy]';,但似乎没有任何效果,而且代码崩溃了。有谁知道复制整个 table,然后将其粘贴到不同文档的语法?

这是 SAS 9.4M4 示例代码,它使用实验性 ODS WORD 目标创建两个 Word 文档,并将 table 从一个复制到另一个。 YMMV,您可能还有关于 table 包装和锚定等问题的额外工作。

filename one "c:\temp\one.docx";
filename two "c:\temp\two.docx";

ods _all_ close;

title; footnote;

options nocenter nonumber nodate;

ods word file=one;
  proc print data=sashelp.class (obs=5);
  proc print data=sashelp.cars (obs=5);
  proc print data=sashelp.demographics (obs=5);
  proc print data=sashelp.class (obs=5);
  run;
ods word close;

ods word file=two;
  proc print data=sashelp.cars (obs=10);
  run;
ods word close;

* start WORD;
options noxsync noxwait xmin;
%sysexec start "Yada yada yada" winword;
%let rc = %sysfunc(sleep(5,1));
%put NOTE: &=rc;

* define channel for sending commands;
filename word_cmd dde 'winword|system';

* put will send the commands to WORD;
data _null_;
  file word_cmd;
  cmd = cats ( "[FileOpen.Name=", quote(trim(pathname("One"))), "]");
  put cmd;

  put '[EditBookmark name:="IDX3", goto:=1]';
  put '[NextObject]';
  put '[GoToNextSection]';
  put '[TableSelectTable]';
  put '[EditCopy]';

  cmd = cats ( "[FileOpen.Name=", quote(trim(pathname("Two"))), "]");
  put cmd;
  put '[Selection.Goto(wdGotoLine, wdGotoLast)]';
  put '[EditPaste]';
run;

Word 命令 ListCommands 将创建一个包含所有 Word 命令和活动键映射的 table 的文档。

data _null_;
  file word_cmd;
  put '[ListCommands]';
run;

此列表在 Word 2016 中有 10 页。Word 命令也可以从 dde ​​连接调用。不幸的是 ListCommands 列出了一个描述性的命令名称,而不是 dde ​​实际需要的命令,并且实际上并没有列出所有命令。 WordMVP 站点 (https://wordmvp.com) has assembled a list - "Word for Windows commands"

Word has a built-in command ListCommands, which produces a table of all the Word commands with their current key and menu assignments. However, it does not list the commands using their actual names; nor does it include descriptions of what the commands actually do.

WordCmndsPDF.zip contains a list of all interceptable Word commands (Word 97 and above), using their correct English names

可在 "Visual Basic Equivalents for WordBasic Commands",2014 年 6 月 13 日找到有关 Word 命令的另一个参考。

搜索 "WORD DDE" 的 SAS 会议论文还将提供额外的 material。