Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Inserting text into a bookmarked table cell in word using DDE from SAS

Status
Not open for further replies.

eguva

Programmer
Jun 23, 2007
27
US
Hi,

I am trying to insert a text into the table of a word document using SAS and DDE.say, one of the cell in the table has text "version:". I have a bookmark right after the : and truing to insert some text here. But, it is not working. It is working if I am trying to insert text at bookmarks outside the table.
Does any one know the easiest method to insert text into cells of a table.Here is the code that I am using.


options noxwait noxsync;
x 'c:\msoffice\winword\winword.exe';

filename ws dde 'winword|system';
filename name dde 'winword|C:\Documents and Settings\......\t.doc!name';
filename location dde 'winword|C:\Documents and Settings\......\t.doc!address';
filename prod dde 'winword|C:\Documents and Settings\......\t.doc!tab';

data _null_;
x=sleep(10);
file ws;
put '[FileOpen .Name = "C:\Documents and Settings\.....\t.doc"]';
stop;
run;

data _null_;
/*file name notab;
put 'Alice';
file location notab;
put 'Wonderland';*/
file prod notab;
put "ente";
stop;
run;

data _null_;
file ws;
put '[FilePrint]';
put '[FileSave]';
put '[FileExit 2]';
stop;
run;

Thanks,
Eguva
 
You need to allow the MS Word time to load before you start writing execute codes to it. The first time MS Word is launched the program will need anywhere from 3-10 seconds to fully load into your computer's memory. The way you can 'stall' SAS and 'wait' for the word app to load is by using the 'SLEEP()' function. I see that you use it, but in the very same data step you use the file handle and write commands to it. You could try to increase the sleep time. This may work, but I would increase the sleep time by 5-10 seconds and use another data step. So you would have two data _null_ steps the first, using the sleep() and the second executing your word commands.

Let me know how it turns out.
Klaz
 
Hi Klaz,

I have split that into 2 datasteps and increased the sleep time to 10 secs.
I am having the same problem as before.
When I open the .sas file from its location and run it for first time the word document is opening by itself.AFter first time, it is not able to open the word document and giving the same error.
I run in batch mode in ultra edit, i am not sure if that is making the difference.

Thanks,
Kiran


 
Can you put the following statement at the top of your code?
Code:
options macrogen symbolgen mprint source source2;

Then run your program and post the log results here.
Klaz
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top