BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
chetan3125
Obsidian | Level 7

I want to force close word file if it is open in windows before running my code. 

Found following code with DDE on SAS site but its not working and I am unable to close "myfile.rtf" 

Can someone please clarify ?

https://support.sas.com/kb/40/191.html 

 


/* Create a sample table routing to RTF using ODS */

ods rtf file="myfile.rtf";

proc tabulate data=sashelp.class;
   class age sex;
   table age,sex;
run;

ods rtf close;


/* Use DDE to make the request to Microsoft Word */
filename word dde 'winword|system';

data _null_;
   file word;

/* The following PUT statements execute Microsoft Word commands */
   put '[FileClose 2]'; 
   put '[FileExit 2]'; 
run; 
1 ACCEPTED SOLUTION

Accepted Solutions
SASKiwi
PROC Star

DDE won't work at all if you are using SAS on a remote server. It will only possibly work if you use SAS installed on your PC and even then it is not recommended.

View solution in original post

3 REPLIES 3
japelin
Rhodochrosite | Level 12

In my environment, I was able to close the rtf file with the code using DDE.
However, in the case of the code you presented, the rtf file should not have been opened at the time the DDE session was established, so there is an error.
Are there any errors in the log?

 

Also, instead of using dde to close the file, you can prevent the ods output result (rtf file) from being opened by writing the following code before ods statement.

ods noresults;

 

ballardw
Super User

Please note that DDE is not really advocated by Microsoft and there are other applications that you might have installed that use the communication channels that DDE uses and may well interfere with them. So DDE approaches are extremely fragile and may well not work, not because of the SAS code but the operating system environment.

 

At least one application that interferes is Cisco Jabber. If the Jabber service is running then DDE, at least the limited amount that I used, would not work. If you have Jabber the service must be KILLED, as in kill process in task manager not just close an active window, before DDE may work.

SASKiwi
PROC Star

DDE won't work at all if you are using SAS on a remote server. It will only possibly work if you use SAS installed on your PC and even then it is not recommended.

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 3 replies
  • 1463 views
  • 2 likes
  • 4 in conversation