Reputation: 351
When I was running office 2007, my SAS DDE script populated, saved and closed the excel file just fine.
I recently updated to office 2010 and the population works fine...but excel stops at the save dialog box. I have to manually click on Save which I did not have to do before.
Anyone know how to fix this issue?
Codes I am using:
filename commands DDE 'EXCEL|SYSTEM';
data _null_;
file commands;
put '[OPEN("pathtoexcelfile.xls")]';
run;
data _null_;
file commands;
put "[Save.as(""&saveas_Path.&saveas..xls"")]";
put "[Close]";
run;
Upvotes: 3
Views: 4522
Reputation: 8513
You need to add a (0)
to your close statement. This tells it not to prompt.
data _null_;
file commands;
put "[Save.as(""&saveas_Path.&saveas..xls"")]";
put "[Close(0)]";
run;
This is my full macro (explains some of the doc type parameters):
/******************************************************************************
** PROGRAM: MACRO.DDE_SAVE_AS.SAS
**
** DESCRIPTION: SAVES THE CURRENT EXCEL FILE. IF THE FILE
** ALREADY EXISTS IT WILL BE OVERWRITTEN.
**
** PARAMETERS: iSAVEAS: THE DESTINATION FILENAME TO SAVE TO.
** iType : (OPTIONAL. DEFAULT=BLANK).
** BLANK = XL DEFAULT SAVE TYPE
** 1 = XLS DOC - OLD SCHOOL! PRE OFFICE 2007?
** 44 = HTML - PRETTY COOL! CHECK IT OUT...
** 51 = XLSX DOC - OFFICE 2007 ONWARDS COMPATIBLE?
** 57 = PDF
**
** NOTES: IF YOU ARE GETTING A DDE ERROR WHEN RUNNING THIS MACRO THEN DOUBLE
** CHECK YOU HAVE PERMISSIONS TO SAVE WHERE YOU ARE TRYING TO SAVE THE
** FILE.
**
*******************************************************************************
** VERSION:
** 1.0 ON: 01APR10 BY: RP
** CREATED.
******************************************************************************/
%macro dde_save_as(iSaveAs=,iType=);
%local iDocTypeClause;
%let iDocTypeClause=;
%if "&iType" ne "" %then %do;
%let iDocTypeClause=,&iType;
%end;
filename cmdexcel dde 'excel|system';
data _null_;
file cmdexcel;
put '[error(false)]';
put "%str([save.as(%"&iSaveAs%"&iDocTypeClause)])";
put '[error(true)]';
run;
filename cmdexcel clear;
%mend;
/*%dde_save_as(iSaveAs=d:\rrobxltest, iType=44);*/
Upvotes: 4
Reputation: 1696
I've used the following before:
put '[save.as("' "&savepath\&savename..&save_ext" '",1,,false,,false)]';
I can't say what the parameters "1" and "false" achieve as I haven't got the DDE documentation to hand and can't find it online (it's called macrofun.hlp and you'll find references to it in many SUGI papers, e.g. http://www2.sas.com/proceedings/sugi26/p011-26.pdf)
In any case, it might be worth investigating alternatives to DDE which is fairly old at this stage.
Upvotes: 1