I searched the archive and couldn't find how to close a WORD session
from SAS. The FileExit() vb code will close off all active WORD
sessions.
put '[FileExit()]';
The idea is to allow SAS programmers to trigger a WORD session, start
DDE data transfer, save and close that WORD session. Often times
there is another WORD session open, and I want to leave that alone,
away from the SAS dde to WORD session.
Do you know what is the right vb code to archive this? Thanks for
help.
/******************************************************************/
/* DDE needs these options turned off (Page 220 of SAS Companion)
*/
/******************************************************************/
options noxwait noxsync;
/*****************/
/* Start up Word */
/*****************/
%* Try to open Application;
options noxsync noxwait xmin;
x start winword;
/**********************************/
/* Give it a few seconds to load, */
/* otherwise the message: */
/* "Physical file does not exist" */
/* shows up and the job bombs. */
/**********************************/
data _null_;
t = sleep(5);
run;
filename wordsys dde "winword|system";
data _null_;
file wordsys;
/************************************/
/* Insert the output (*.txt) file ***/
/************************************/
put "[InsertFile ""test.txt""]";
put "[StartOfDocument]";
/*********************************************************/
/* The following 5 commands remove the page break that */
/* SAS puts at the very top of the file and inserts a */
/* blank line at the top of the 1st page. (Have not been */
/* successful in simply removing the page break -- it */
/* pulls the 1st title off center) */
/*********************************************************/
put "[LineDown]";
put "[InsertPara]";
put "[StartOfDocument]";
put "[EndOfLine]";
put "[DeleteWord]";
/**************************/
/* Select entire document */
/**************************/
put '[EditSelectAll]';
/*************************************/
/* Apply SAS monospace font, 8 point */
/*************************************/
put '[Font "SAS Monospace"]';
put '[FontSize 8]';
/************************************************/
/* Note: LineSpacing=160 translates into 8 pts. */
/************************************************/
put '[FormatParagraph .LineSpacingRule=4,.LineSpacing=160]';
/***************************************************/
/* Set page margins, paper size, orientation, etc. */
/***************************************************/
put '[FilePageSetup .Tab = "1", .PaperSize = "0", .TopMargin =
"1.5" +
Chr$(34), .BottomMargin = ".75" + Chr$(34), .LeftMargin =
"1" + Chr$(34), .RightMargin = ".75" + Chr$(34), .Gutter = "0" +
Chr$(34)]';
put '[FilePageSetup .PageWidth = "11" + Chr$(34), .PageHeight =
"8.5" +
Chr$(34),.Orientation = 1]';
put '[FilePageSetup .FirstPage = 0,.OtherPages = 0, .VertAlign = 0,
.ApplyPropsTo = 4,.FacingPages = 0, .HeaderDistance = "0.5" +
Chr$(34), .FooterDistance = "0.5" + Chr$(34)]';
put '[FilePageSetup .SectionStart = 2, .OddAndEvenPages = 0,
.DifferentFirstPage = 0,.Endnotes = 0, .LineNum=0, .StartingNum =
"",
.FromText = "", .CountBy = "0", .NumMode = -1]';
/************************************************/
/* Embed the SAS Monospace font in the document */
/************************************************/
put '[ToolsOptionsSave .EmbedFonts=1]';
put '[ViewHeader]';
put '[Font "SAS Monospace"]';
put '[FontSize 24]';
put '[Insert " DRAFT
" ]';
put '[Insert "
"]';
put '[FontSize 8]';
/************************/
/* Save it as .DOC file */
/************************/
put "[FileSaveAs "test.doc"]";
/**************/
/* Close Word */
/**************/
put '[FileExit()]';
*put '[close]'; * not working;
*put '[quit]'; *not working;
run;