Published on :
Administration INTERNAL_CREATION

Automatic Launch of Excel via DDE

This code is also available in: Deutsch Español Français
Attention : This code requires administrator privileges.
This program uses the DDE (Dynamic Data Exchange) engine to attempt to establish communication with Excel. If the stream cannot be opened (indicating that Excel is closed), the script uses the `system` function to execute the DOS command 'Start Excel'. It includes a waiting loop to verify the launch. NOTE: This code is specific to Windows environments and relies on obsolete DDE technology; it is not functional in a standard SAS© Viya 4 environment under Linux.
Data Analysis

Type : INTERNAL_CREATION


No external data read. The script only handles system interactions and file references (fileref).

1 Code Block
DATA STEP
Explanation :
Checks the accessibility of the Excel DDE server. If inactive, launches Excel via system command and waits up to 5 seconds for the service to become available.
Copied!
1OPTIONS NOXSYNC NOXWAIT;
2filename cmdexcel DDE 'EXCEL|SYSTEM'; /* Fileref for Excel System */
3 
4DATA _null_;
5 fid = fopen('cmdexcel','S'); /* Check if Excel is open */
6 IF fid le 0 THEN
7 DO; /* Excel is not open, open Excel via Windows registry */
8 rc=system("Start Excel"); /* DOS command to open Excel*/
9 start = datetime(); /* Note start time */
10 stop = start + 5; /* Max time to try opening */
11 DO while (fid le 0); /* Loop while Excel opens */
12 fid = fopen('cmdexcel','S'); /* Check if Excel is open */
13 time = datetime(); /* Reset current time */
14 IF time ge stop THEN
15 fid = time; /* Set FID to terminate loop*/
16 END; /* do while (fid le 0); */
17 END; /* Excel is not open, open Excel via Windows registry */
18 rc = fclose(fid); /* Close fileopen on EXCEL */
19RUN;
2 Code Block
COMMAND X
Explanation :
Alternative and direct method to launch Excel via the X command (shell escape).
Copied!
1options noxwait noxsync;
2 x start excel;
This material is provided "as is" by We Are Cas. There are no warranties, expressed or implied, as to merchantability or fitness for a particular purpose regarding the materials or code contained herein. We Are Cas is not responsible for errors in this material as it now exists or will exist, nor does We Are Cas provide technical support for it.